2
// Copyright (c) 2002 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
4
// Permission is hereby granted, free of charge, to any person obtaining a
5
// copy of this software and associated documentation files (the "Software"),
6
// to deal in the Software without restriction, including without limitation
7
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
// and/or sell copies of the Software, and to permit persons to whom the
9
// Software is furnished to do so, subject to the following conditions:
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
// DEALINGS IN THE SOFTWARE.
22
// $Id: Ewmh.cc 4074 2005-07-04 18:19:53Z fluxgen $
28
#include "WinClient.hh"
29
#include "Workspace.hh"
32
#include "FbTk/FbWindow.hh"
33
#include "FbTk/I18n.hh"
41
// mipspro has no new(nothrow)
42
#if defined sgi && ! defined GCC
43
#define FB_new_nothrow new
45
#define FB_new_nothrow new(std::nothrow)
54
while (!m_windows.empty()) {
55
XDestroyWindow(FbTk::App::instance()->display(), m_windows.back());
60
void Ewmh::initForScreen(BScreen &screen) {
61
Display *disp = FbTk::App::instance()->display();
63
/* From Extended Window Manager Hints, draft 1.3:
65
* _NET_SUPPORTING_WM_CHECK
67
* The Window Manager MUST set this property on the root window
68
* to be the ID of a child window created by himself, to indicate
69
* that a compliant window manager is active. The child window
70
* MUST also have the _NET_SUPPORTING_WM_CHECK property set to
71
* the ID of the child window. The child window MUST also have
72
* the _NET_WM_NAME property set to the name of the Window Manager.
74
* Rationale: The child window is used to distinguish an active
75
* Window Manager from a stale _NET_SUPPORTING_WM_CHECK property
76
* that happens to point to another window. If the
77
* _NET_SUPPORTING_WM_CHECK window on the client window is missing
78
* or not properly set, clients SHOULD assume that no conforming
79
* Window Manager is present.
82
Window wincheck = XCreateSimpleWindow(disp,
83
screen.rootWindow().window(),
84
-10, -10, 5, 5, 0, 0, 0);
86
if (wincheck != None) {
87
// store the window so we can delete it later
88
m_windows.push_back(wincheck);
90
screen.rootWindow().changeProperty(m_net_supporting_wm_check, XA_WINDOW, 32,
91
PropModeReplace, (unsigned char *) &wincheck, 1);
92
XChangeProperty(disp, wincheck, m_net_supporting_wm_check, XA_WINDOW, 32,
93
PropModeReplace, (unsigned char *) &wincheck, 1);
95
XChangeProperty(disp, wincheck, m_net_wm_name, utf8_string, 8,
96
PropModeReplace, (unsigned char *) "Fluxbox", strlen("Fluxbox"));
100
Atom atomsupported[] = {
104
// states that we support:
105
m_net_wm_state_sticky,
106
m_net_wm_state_shaded,
107
m_net_wm_state_maximized_horz,
108
m_net_wm_state_maximized_vert,
109
m_net_wm_state_fullscreen,
110
m_net_wm_state_hidden,
111
m_net_wm_state_skip_taskbar,
114
m_net_wm_window_type,
115
m_net_wm_window_type_dock,
116
m_net_wm_window_type_desktop,
120
m_net_client_list_stacking,
121
m_net_number_of_desktops,
122
m_net_current_desktop,
125
m_net_moveresize_window,
128
// desktop properties
131
m_net_desktop_viewport,
132
m_net_desktop_geometry,
134
m_net_supporting_wm_check
136
/* From Extended Window Manager Hints, draft 1.3:
138
* _NET_SUPPORTED, ATOM[]/32
140
* This property MUST be set by the Window Manager
141
* to indicate which hints it supports. For
142
* example: considering _NET_WM_STATE both this
143
* atom and all supported states
144
* e.g. _NET_WM_STATE_MODAL, _NET_WM_STATE_STICKY,
145
* would be listed. This assumes that backwards
146
* incompatible changes will not be made to the
147
* hints (without being renamed).
149
screen.rootWindow().changeProperty(m_net_supported, XA_ATOM, 32,
151
(unsigned char *) &atomsupported,
152
(sizeof atomsupported)/sizeof atomsupported[0]);
156
updateWorkspaceCount(screen);
157
updateCurrentWorkspace(screen);
158
updateWorkspaceNames(screen);
159
updateClientList(screen);
160
updateViewPort(screen);
161
updateGeometry(screen);
162
updateWorkarea(screen);
166
void Ewmh::setupClient(WinClient &winclient) {
167
updateStrut(winclient);
170
void Ewmh::setupFrame(FluxboxWindow &win) {
173
unsigned long nitems, bytes_after;
174
unsigned char *data = 0;
176
/* From Extended Window Manager Hints, draft 1.3:
178
* _NET_WM_WINDOW_TYPE, ATOM[]/32
180
* This SHOULD be set by the Client before mapping to a list of atoms
181
* indicating the functional type of the window. This property SHOULD
182
* be used by the window manager in determining the decoration,
183
* stacking position and other behavior of the window. The Client
184
* SHOULD specify window types in order of preference (the first being
185
* most preferable) but MUST include at least one of the basic window
186
* type atoms from the list below. This is to allow for extension of
187
* the list of types whilst providing default behavior for Window
188
* Managers that do not recognize the extensions.
192
win.winClient().property(m_net_wm_window_type, 0, 0x7fffffff, False, XA_ATOM,
193
&ret_type, &fmt, &nitems, &bytes_after,
196
Atom *atoms = (unsigned long *)data;
197
for (unsigned long l=0; l<nitems; ++l) {
198
/* From Extended Window Manager Hints, draft 1.3:
200
* _NET_WM_WINDOW_TYPE_DOCK indicates a dock or panel feature.
201
* Typically a Window Manager would keep such windows on top
202
* of all other windows.
205
if (atoms[l] == m_net_wm_window_type_dock) {
206
// we also assume it shouldn't be visible in any toolbar
207
win.setFocusHidden(true);
208
win.setIconHidden(true);
210
} else if (atoms[l] == m_net_wm_window_type_desktop) {
212
* _NET_WM_WINDOW_TYPE_DESKTOP indicates a "false desktop" window
213
* We let it be the size it wants, but it gets no decoration,
214
* is hidden in the toolbar and window cycling list, plus
215
* windows don't tab with it and is right on the bottom.
218
win.setFocusHidden(true);
219
win.setIconHidden(true);
220
win.moveToLayer(Fluxbox::instance()->getDesktopLayer());
221
win.setDecorationMask(0);
222
win.setTabable(false);
223
win.setMovable(false);
224
win.setResizable(false);
234
if (win.winClient().property(m_net_wm_desktop, 0, 1, False, XA_CARDINAL,
235
&ret_type, &fmt, &nitems, &bytes_after,
236
(unsigned char **) &data) && data) {
237
unsigned int desktop = static_cast<unsigned int>(*data);
238
if (desktop == 0xFFFFFFFF && !win.isStuck())
241
win.setWorkspace(desktop);
245
updateWorkspace(win);
249
void Ewmh::updateFrameClose(FluxboxWindow &win) {
253
void Ewmh::updateFocusedWindow(BScreen &screen, Window win) {
254
/* From Extended Window Manager Hints, draft 1.3:
256
* _NET_ACTIVE_WINDOW, WINDOW/32
258
* The window ID of the currently active window or None
259
* if no window has the focus. This is a read-only
260
* property set by the Window Manager.
263
screen.rootWindow().changeProperty(m_net_active_window,
266
(unsigned char *)&win, 1);
269
void Ewmh::updateClientClose(WinClient &winclient){
270
updateClientList(winclient.screen());
273
void Ewmh::updateClientList(BScreen &screen) {
276
BScreen::Workspaces::const_iterator workspace_it =
277
screen.getWorkspacesList().begin();
278
const BScreen::Workspaces::const_iterator workspace_it_end =
279
screen.getWorkspacesList().end();
280
for (; workspace_it != workspace_it_end; ++workspace_it) {
281
Workspace::Windows::iterator win_it =
282
(*workspace_it)->windowList().begin();
283
Workspace::Windows::iterator win_it_end =
284
(*workspace_it)->windowList().end();
285
for (; win_it != win_it_end; ++win_it) {
286
num += (*win_it)->numClients();
291
BScreen::Icons::const_iterator icon_it = screen.iconList().begin();
292
BScreen::Icons::const_iterator icon_it_end = screen.iconList().end();
293
for (; icon_it != icon_it_end; ++icon_it) {
294
num += (*icon_it)->numClients();
297
Window *wl = FB_new_nothrow Window[num];
300
cerr<<_FBTEXT(Ewmh, OutOfMemoryClientList, "Fatal: Out of memory, can't allocate for EWMH client list", "")<<endl;
304
//start the iterator from begining
305
workspace_it = screen.getWorkspacesList().begin();
307
for (; workspace_it != workspace_it_end; ++workspace_it) {
309
// Fill in array of window ID's
310
Workspace::Windows::const_iterator it =
311
(*workspace_it)->windowList().begin();
312
Workspace::Windows::const_iterator it_end =
313
(*workspace_it)->windowList().end();
314
for (; it != it_end; ++it) {
315
if ((*it)->numClients() == 1) {
316
wl[win++] = (*it)->clientWindow();
318
// add every client in fluxboxwindow to list window list
319
std::list<WinClient *>::iterator client_it =
320
(*it)->clientList().begin();
321
std::list<WinClient *>::iterator client_it_end =
322
(*it)->clientList().end();
323
for (; client_it != client_it_end; ++client_it)
324
wl[win++] = (*client_it)->window();
329
// plus iconified windows
330
icon_it = screen.iconList().begin();
331
for (; icon_it != icon_it_end; ++icon_it) {
332
FluxboxWindow::ClientList::iterator client_it = (*icon_it)->clientList().begin();
333
FluxboxWindow::ClientList::iterator client_it_end = (*icon_it)->clientList().end();
334
for (; client_it != client_it_end; ++client_it)
335
wl[win++] = (*client_it)->window();
337
//number of windows to show in client list
340
/* From Extended Window Manager Hints, draft 1.3:
342
* _NET_CLIENT_LIST, WINDOW[]/32
343
* _NET_CLIENT_LIST_STACKING, WINDOW[]/32
345
* These arrays contain all X Windows managed by
346
* the Window Manager. _NET_CLIENT_LIST has
347
* initial mapping order, starting with the oldest
348
* window. _NET_CLIENT_LIST_STACKING has
349
* bottom-to-top stacking order. These properties
350
* SHOULD be set and updated by the Window
353
screen.rootWindow().changeProperty(m_net_client_list,
355
PropModeReplace, (unsigned char *)wl, num);
356
screen.rootWindow().changeProperty(m_net_client_list_stacking,
358
PropModeReplace, (unsigned char *)wl, num);
363
void Ewmh::updateWorkspaceNames(BScreen &screen) {
364
/* From Extended Window Manager Hints, draft 1.3:
366
* _NET_DESKTOP_NAMES, UTF8_STRING[]
368
* The names of all virtual desktops.
369
* This is a list of NULL-terminated strings in UTF-8
370
* encoding [UTF8]. This property MAY be changed by a
371
* Pager or the Window Manager at any time.
373
* Note: The number of names could be different from
374
* _NET_NUMBER_OF_DESKTOPS. If it is less than
375
* _NET_NUMBER_OF_DESKTOPS, then the desktops with high
376
* numbers are unnamed. If it is larger than
377
* _NET_NUMBER_OF_DESKTOPS, then the excess names outside
378
* of the _NET_NUMBER_OF_DESKTOPS are considered to be
379
* reserved in case the number of desktops is increased.
381
* Rationale: The name is not a necessary attribute of a
382
* virtual desktop. Thus the availability or unavailability
383
* of names has no impact on virtual desktop functionality.
384
* Since names are set by users and users are likely to
385
* preset names for a fixed number of desktops, it
386
* doesn't make sense to shrink or grow this list when the
387
* number of available desktops changes.
391
const BScreen::WorkspaceNames &workspacenames = screen.getWorkspaceNames();
392
const size_t number_of_desks = workspacenames.size();
394
char *names[number_of_desks];
396
for (size_t i = 0; i < number_of_desks; i++) {
397
names[i] = new char[workspacenames[i].size() + 1]; // +1 for \0
398
memset(names[i], 0, workspacenames[i].size());
399
strcpy(names[i], workspacenames[i].c_str());
402
if (XStringListToTextProperty(names, number_of_desks, &text)) {
403
XSetTextProperty(FbTk::App::instance()->display(), screen.rootWindow().window(),
404
&text, m_net_desktop_names);
408
for (size_t i = 0; i < number_of_desks; i++)
413
void Ewmh::updateCurrentWorkspace(BScreen &screen) {
414
/* From Extended Window Manager Hints, draft 1.3:
416
* _NET_CURRENT_DESKTOP desktop, CARDINAL/32
418
* The index of the current desktop. This is always
419
* an integer between 0 and _NET_NUMBER_OF_DESKTOPS - 1.
420
* This MUST be set and updated by the Window Manager.
423
unsigned long workspace = screen.currentWorkspaceID();
424
screen.rootWindow().changeProperty(m_net_current_desktop,
427
(unsigned char *)&workspace, 1);
431
void Ewmh::updateWorkspaceCount(BScreen &screen) {
432
/* From Extended Window Manager Hints, draft 1.3:
434
* _NET_NUMBER_OF_DESKTOPS, CARDINAL/32
436
* This property SHOULD be set and updated by the
437
* Window Manager to indicate the number of virtual
440
unsigned long numworkspaces = screen.numberOfWorkspaces();
441
screen.rootWindow().changeProperty(m_net_number_of_desktops,
444
(unsigned char *)&numworkspaces, 1);
447
void Ewmh::updateViewPort(BScreen &screen) {
448
/* From Extended Window Manager Hints, draft 1.3:
450
* _NET_DESKTOP_VIEWPORT x, y, CARDINAL[][2]/32
452
* Array of pairs of cardinals that define the
453
* top left corner of each desktop's viewport.
454
* For Window Managers that don't support large
455
* desktops, this MUST always be set to (0,0).
458
long value[2] = {0, 0}; // we dont support large desktops
459
screen.rootWindow().changeProperty(m_net_desktop_viewport,
462
(unsigned char *)value, 2);
465
void Ewmh::updateGeometry(BScreen &screen) {
466
/* From Extended Window Manager Hints, draft 1.3:
468
* _NET_DESKTOP_GEOMETRY width, height, CARDINAL[2]/32
470
* Array of two cardinals that defines the common size
471
* of all desktops (this is equal to the screen size
472
* if the Window Manager doesn't support large
473
* desktops, otherwise it's equal to the virtual size
474
* of the desktop). This property SHOULD be set by the
478
long value[2] = {screen.width(), screen.height()};
479
screen.rootWindow().changeProperty(m_net_desktop_geometry,
482
(unsigned char *)value, 2);
486
void Ewmh::updateWorkarea(BScreen &screen) {
487
/* From Extended Window Manager Hints, draft 1.3:
489
* _NET_WORKAREA, x, y, width, height CARDINAL[][4]/32
491
* This property MUST be set by the Window Manager upon
492
* calculating the work area for each desktop. Contains a
493
* geometry for each desktop. These geometries are
494
* specified relative to the viewport on each desktop and
495
* specify an area that is completely contained within the
496
* viewport. Work area SHOULD be used by desktop applications
497
* to place desktop icons appropriately.
502
* Not sure how to handle xinerama stuff here.
503
* So i'm just doing this on the first head.
505
unsigned long *coords = new unsigned long[4*screen.numberOfWorkspaces()];
506
for (unsigned int i=0; i < screen.numberOfWorkspaces()*4; i+=4) {
508
coords[i] = screen.maxLeft(0);
509
coords[i + 1] = screen.maxTop(0);
511
coords[i + 2] = screen.maxRight(0) - screen.maxLeft(0);
512
coords[i + 3] = screen.maxBottom(0) - screen.maxTop(0);
515
screen.rootWindow().changeProperty(m_net_workarea,
518
(unsigned char *)coords,
519
4 * screen.numberOfWorkspaces());
524
void Ewmh::updateState(FluxboxWindow &win) {
526
// TODO: should we update the _NET_WM_ALLOWED_ACTIONS
529
typedef std::vector<unsigned int> StateVec;
534
state.push_back(m_net_wm_state_sticky);
536
state.push_back(m_net_wm_state_shaded);
537
if (win.layerNum() == Fluxbox::instance()->getBottomLayer())
538
state.push_back(m_net_wm_state_below);
539
if (win.layerNum() == Fluxbox::instance()->getAboveDockLayer())
540
state.push_back(m_net_wm_state_above);
542
state.push_back(m_net_wm_state_hidden);
543
if (win.isIconHidden())
544
state.push_back(m_net_wm_state_skip_taskbar);
545
if (win.isFullscreen()) {
546
state.push_back(m_net_wm_state_fullscreen);
549
FluxboxWindow::ClientList::iterator it = win.clientList().begin();
550
FluxboxWindow::ClientList::iterator it_end = win.clientList().end();
552
it = win.clientList().begin();
553
for (; it != it_end; ++it) {
555
// search the old states for _NET_WM_STATE_SKIP_PAGER and append it
556
// to the current state, so it wont get deleted by us.
557
StateVec client_state(state);
560
unsigned long nitems, bytes_after;
561
unsigned char *data = 0;
563
(*it)->property(m_net_wm_state, 0, 0x7fffffff, False, XA_ATOM,
564
&ret_type, &fmt, &nitems, &bytes_after,
567
Atom *old_states = (Atom *)data;
568
for (unsigned long i=0; i < nitems; ++i)
569
if (old_states[i] == m_net_wm_state_skip_pager) {
570
client_state.push_back(m_net_wm_state_skip_pager);
575
if (!client_state.empty())
576
(*it)->changeProperty(m_net_wm_state, XA_ATOM, 32, PropModeReplace,
577
reinterpret_cast<unsigned char*>(&client_state.front()),
578
client_state.size());
580
(*it)->deleteProperty(m_net_wm_state);
584
void Ewmh::updateLayer(FluxboxWindow &win) {
585
//!! TODO _NET_WM_WINDOW_TYPE
587
if (win.getLayer() == Fluxbox::instance()->getAboveDockLayer()) {
588
// _NET_WM_STATE_BELOW
590
} else if (win.getLayer() == Fluxbox::instance()->getBottomLayer()) {
591
// _NET_WM_STATE_ABOVE
596
void Ewmh::updateHints(FluxboxWindow &win) {
599
void Ewmh::updateWorkspace(FluxboxWindow &win) {
600
long workspace = win.isInitialized() ? win.workspaceNumber() : win.screen().currentWorkspaceID();
603
workspace = 0xFFFFFFFF; // appear on all desktops/workspaces
605
FluxboxWindow::ClientList::iterator it = win.clientList().begin();
606
FluxboxWindow::ClientList::iterator it_end = win.clientList().end();
607
for (; it != it_end; ++it) {
608
(*it)->changeProperty(m_net_wm_desktop, XA_CARDINAL, 32, PropModeReplace,
609
(unsigned char *)&workspace, 1);
615
// return true if we did handle the atom here
616
bool Ewmh::checkClientMessage(const XClientMessageEvent &ce,
617
BScreen * screen, WinClient * const winclient) {
619
if (ce.message_type == m_net_wm_desktop) {
620
// ce.data.l[0] = workspace number
623
if (winclient == 0 || winclient->fbwindow() == 0)
626
FluxboxWindow *fbwin = winclient->fbwindow();
628
// if it's stick, make sure it is stuck.
629
// otherwise, make sure it isn't stuck
630
if (ce.data.l[0] == 0xFFFFFFFF) {
631
if (!fbwin->isStuck())
634
} else if (fbwin->isStuck())
637
// the screen is the root window of the message,
638
// which doesn't apply here (so borrow the variable :) )
639
screen = &fbwin->screen();
640
// valid workspace number?
641
if (static_cast<unsigned int>(ce.data.l[0]) < screen->numberOfWorkspaces())
642
screen->sendToWorkspace(ce.data.l[0], fbwin, false);
645
} else if (ce.message_type == m_net_wm_state) {
646
if (winclient == 0 || winclient->fbwindow() == 0)
649
FluxboxWindow &win = *winclient->fbwindow();
650
// ce.data.l[0] = the action (remove, add or toggle)
651
// ce.data.l[1] = the first property to alter
652
// ce.data.l[2] = second property to alter (can be zero)
653
if (ce.data.l[0] == STATE_REMOVE) {
654
setState(win, ce.data.l[1], false);
655
setState(win, ce.data.l[2], false);
656
} else if (ce.data.l[0] == STATE_ADD) {
657
setState(win, ce.data.l[1], true);
658
setState(win, ce.data.l[2], true);
659
} else if (ce.data.l[0] == STATE_TOGGLE) {
660
toggleState(win, ce.data.l[1]);
661
toggleState(win, ce.data.l[2]);
664
} else if (ce.message_type == m_net_number_of_desktops) {
667
// ce.data.l[0] = number of workspaces
669
// no need to alter number of desktops if they are the same
670
// or if requested number of workspace is less than zero
671
if (screen->numberOfWorkspaces() == static_cast<unsigned int>(ce.data.l[0]) ||
675
if (screen->numberOfWorkspaces() > static_cast<unsigned int>(ce.data.l[0])) {
676
// remove last workspace until we have
677
// the same number of workspaces
678
while (screen->numberOfWorkspaces() != static_cast<unsigned int>(ce.data.l[0])) {
679
screen->removeLastWorkspace();
680
if (screen->numberOfWorkspaces() == 1) // must have at least one workspace
683
} else { // add workspaces to screen until workspace count match the requested size
684
while (screen->numberOfWorkspaces() != static_cast<unsigned int>(ce.data.l[0])) {
685
screen->addWorkspace();
690
} else if (ce.message_type == m_net_current_desktop) {
693
// ce.data.l[0] = workspace number
695
// prevent out of range value
696
if (static_cast<unsigned int>(ce.data.l[0]) >= screen->numberOfWorkspaces())
698
screen->changeWorkspaceID(ce.data.l[0]);
700
} else if (ce.message_type == m_net_active_window) {
702
// make sure we have a valid window
705
// ce.window = window to focus
708
if (winclient->fbwindow()) {
710
FluxboxWindow* fbwin = winclient->fbwindow();
713
// if the raised window is on a different workspace
714
// we do what the user wish:
715
// either ignore|go to that workspace|get the window
716
if (fbwin->screen().currentWorkspaceID() != fbwin->workspaceNumber()) {
717
if (fbwin->screen().getFollowModel() == BScreen::FOLLOW_ACTIVE_WINDOW) {
718
fbwin->screen().changeWorkspaceID(fbwin->workspaceNumber());
719
} else if (fbwin->screen().getFollowModel() == BScreen::FETCH_ACTIVE_WINDOW) {
720
fbwin->screen().sendToWorkspace(fbwin->screen().currentWorkspaceID(), fbwin);
721
} // else we ignore it. my favourite mode :)
725
} else if (ce.message_type == m_net_close_window) {
728
// ce.window = window to close (which in this case is the win argument)
729
winclient->sendClose();
731
} else if (ce.message_type == m_net_moveresize_window) {
732
if (winclient == 0 || winclient->fbwindow() == 0)
734
// ce.data.l[0] = gravity and flags
737
// ce.data.l[3] = width
738
// ce.data.l[4] = height
740
int win_gravity=ce.data.l[0] & 0xFF;
741
winclient->fbwindow()->moveResizeForClient(ce.data.l[1], ce.data.l[2],
742
ce.data.l[3], ce.data.l[4], win_gravity);
746
// we didn't handle the ce.message_type here
751
bool Ewmh::propertyNotify(WinClient &winclient, Atom the_property) {
752
if (the_property == m_net_wm_strut) {
754
cerr<<"_NET_WM_STRUT"<<endl;
756
updateStrut(winclient);
763
void Ewmh::createAtoms() {
765
Display *disp = FbTk::App::instance()->display();
767
m_net_supported = XInternAtom(disp, "_NET_SUPPORTED", False);
768
m_net_client_list = XInternAtom(disp, "_NET_CLIENT_LIST", False);
769
m_net_client_list_stacking = XInternAtom(disp, "_NET_CLIENT_LIST_STACKING", False);
770
m_net_number_of_desktops = XInternAtom(disp, "_NET_NUMBER_OF_DESKTOPS", False);
771
m_net_desktop_geometry = XInternAtom(disp, "_NET_DESKTOP_GEOMETRY", False);
772
m_net_desktop_viewport = XInternAtom(disp, "_NET_DESKTOP_VIEWPORT", False);
773
m_net_current_desktop = XInternAtom(disp, "_NET_CURRENT_DESKTOP", False);
774
m_net_desktop_names = XInternAtom(disp, "_NET_DESKTOP_NAMES", False);
775
m_net_active_window = XInternAtom(disp, "_NET_ACTIVE_WINDOW", False);
776
m_net_workarea = XInternAtom(disp, "_NET_WORKAREA", False);
777
m_net_supporting_wm_check = XInternAtom(disp, "_NET_SUPPORTING_WM_CHECK", False);
778
m_net_virtual_roots = XInternAtom(disp, "_NET_VIRTUAL_ROOTS", False);
780
m_net_close_window = XInternAtom(disp, "_NET_CLOSE_WINDOW", False);
781
m_net_moveresize_window = XInternAtom(disp, "_NET_MOVERESIZE_WINDOW", False);
783
// TODO: implement this one
784
m_net_wm_moveresize = XInternAtom(disp, "_NET_WM_MOVERESIZE", False);
786
m_net_properties = XInternAtom(disp, "_NET_PROPERTIES", False);
787
m_net_wm_name = XInternAtom(disp, "_NET_WM_NAME", False);
788
m_net_wm_desktop = XInternAtom(disp, "_NET_WM_DESKTOP", False);
791
m_net_wm_window_type = XInternAtom(disp, "_NET_WM_WINDOW_TYPE", False);
792
m_net_wm_window_type_dock = XInternAtom(disp, "_NET_WM_WINDOW_TYPE_DOCK", False);
793
m_net_wm_window_type_desktop = XInternAtom(disp, "_NET_WM_WINDOW_TYPE_DESKTOP", False);
795
// state atom and the supported state atoms
796
m_net_wm_state = XInternAtom(disp, "_NET_WM_STATE", False);
797
m_net_wm_state_sticky = XInternAtom(disp, "_NET_WM_STATE_STICKY", False);
798
m_net_wm_state_shaded = XInternAtom(disp, "_NET_WM_STATE_SHADED", False);
799
m_net_wm_state_maximized_horz = XInternAtom(disp, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
800
m_net_wm_state_maximized_vert = XInternAtom(disp, "_NET_WM_STATE_MAXIMIZED_VERT", False);
801
m_net_wm_state_fullscreen = XInternAtom(disp, "_NET_WM_STATE_FULLSCREEN", False);
802
m_net_wm_state_hidden = XInternAtom(disp, "_NET_WM_STATE_HIDDEN", False);
803
m_net_wm_state_skip_taskbar = XInternAtom(disp, "_NET_WM_STATE_SKIP_TASKBAR", False);
804
m_net_wm_state_skip_pager = XInternAtom(disp, "_NET_WM_STATE_SKIP_PAGER", False);
805
m_net_wm_state_above = XInternAtom(disp, "_NET_WM_STATE_ABOVE", False);
806
m_net_wm_state_below = XInternAtom(disp, "_NET_WM_STATE_BELOW", False);
809
m_net_wm_allowed_actions = XInternAtom(disp, "_NET_WM_ALLOWED_ACTIONS", False);
810
m_net_wm_action_move = XInternAtom(disp, "_NET_WM_ACTIONS_MOVE", False);
811
m_net_wm_action_resize = XInternAtom(disp, "_NET_WM_ACTIONS_RESIZE", False);
812
m_net_wm_action_minimize = XInternAtom(disp, "_NET_WM_ACTIONS_MINIMIZE", False);
813
m_net_wm_action_shade = XInternAtom(disp, "_NET_WM_ACTIONS_SHADE", False);
814
m_net_wm_action_stick = XInternAtom(disp, "_NET_WM_ACTIONS_STICK", False);
815
m_net_wm_action_maximize_horz = XInternAtom(disp, "_NET_WM_ACTIONS_MAXIMIZE_HORZ", False);
816
m_net_wm_action_maximize_vert = XInternAtom(disp, "_NET_WM_ACTIONS_MAXIMIZE_VERT", False);
817
m_net_wm_action_fullscreen = XInternAtom(disp, "_NET_WM_ACTIONS_FULLSCREEN", False);
818
m_net_wm_action_change_desktop = XInternAtom(disp, "_NET_WM_ACTIONS_CHANGE_DESKTOP", False);
819
m_net_wm_action_close = XInternAtom(disp, "_NET_WM_ACTIONS_CLOSE", False);
821
m_net_wm_strut = XInternAtom(disp, "_NET_WM_STRUT", False);
822
m_net_wm_icon_geometry = XInternAtom(disp, "_NET_WM_ICON_GEOMETRY", False);
823
m_net_wm_icon = XInternAtom(disp, "_NET_WM_ICON", False);
824
m_net_wm_pid = XInternAtom(disp, "_NET_WM_PID", False);
825
m_net_wm_handled_icons = XInternAtom(disp, "_NET_WM_HANDLED_ICONS", False);
827
m_net_wm_ping = XInternAtom(disp, "_NET_WM_PING", False);
828
utf8_string = XInternAtom(disp, "UTF8_STRING", False);
832
void Ewmh::setFullscreen(FluxboxWindow &win, bool value) {
833
// fullscreen implies maximised, above dock layer,
834
// and no decorations (or decorations offscreen)
836
// TODO: do we need the WindowState etc here anymore?
837
// FluxboxWindow::setFullscreen() remembering old values
838
// already and set them...
839
// only reason i can see is that the user manually
840
// moved the (fullscreened) window
841
WindowState *saved_state = getState(win);
844
if (!saved_state) { // not already fullscreen
845
saved_state = new WindowState(win.x(), win.y(), win.width(),
846
win.height(), win.layerNum(), win.decorationMask());
847
saveState(win, saved_state);
848
win.setFullscreen(true);
850
} else { // turn off fullscreen
851
if (saved_state) { // no saved state, can't restore it
852
win.setFullscreen(false);
854
win.setDecorationMask(saved_state->decor);
855
win.moveResize(saved_state->x, saved_state->y,
856
saved_state->width, saved_state->height);
857
win.moveToLayer(saved_state->layer);
866
void Ewmh::setState(FluxboxWindow &win, Atom state, bool value) {
868
if (state == m_net_wm_state_sticky) { // STICKY
869
if (value && !win.isStuck() ||
870
(!value && win.isStuck()))
872
} else if (state == m_net_wm_state_shaded) { // SHADED
873
if ((value && !win.isShaded()) ||
874
(!value && win.isShaded()))
876
} else if (state == m_net_wm_state_maximized_horz ) { // maximized Horizontal
877
if ((value && !win.isMaximized()) ||
878
(!value && win.isMaximized()))
879
win.maximizeHorizontal();
880
} else if (state == m_net_wm_state_maximized_vert) { // maximized Vertical
881
if ((value && !win.isMaximized()) ||
882
(!value && win.isMaximized()))
883
win.maximizeVertical();
884
} else if (state == m_net_wm_state_fullscreen) { // fullscreen
885
if ((value && !win.isFullscreen()) ||
886
(!value && win.isFullscreen()))
887
setFullscreen(win, value);
888
} else if (state == m_net_wm_state_skip_taskbar) {
889
win.setIconHidden(value);
890
} else if (state == m_net_wm_state_below) { // bottom layer
892
win.moveToLayer(Fluxbox::instance()->getBottomLayer());
894
win.moveToLayer(Fluxbox::instance()->getNormalLayer());
896
} else if (state == m_net_wm_state_above) { // above layer
898
win.moveToLayer(Fluxbox::instance()->getAboveDockLayer());
900
win.moveToLayer(Fluxbox::instance()->getNormalLayer());
904
// toggle window state
905
void Ewmh::toggleState(FluxboxWindow &win, Atom state) {
906
if (state == m_net_wm_state_sticky) {
908
} else if (state == m_net_wm_state_shaded){
910
} else if (state == m_net_wm_state_maximized_horz ) { // maximized Horizontal
911
win.maximizeHorizontal();
912
} else if (state == m_net_wm_state_maximized_vert) { // maximized Vertical
913
win.maximizeVertical();
914
} else if (state == m_net_wm_state_fullscreen) { // fullscreen
915
setFullscreen(win, getState(win) == 0); // toggle current state
916
} else if (state == m_net_wm_state_skip_taskbar) {
917
win.setIconHidden(!win.isIconHidden());
918
} else if (state == m_net_wm_state_below) { // bottom layer
919
if (win.layerNum() == Fluxbox::instance()->getBottomLayer())
920
win.moveToLayer(Fluxbox::instance()->getNormalLayer());
922
win.moveToLayer(Fluxbox::instance()->getBottomLayer());
924
} else if (state == m_net_wm_state_above) { // top layer
925
if (win.layerNum() == Fluxbox::instance()->getAboveDockLayer())
926
win.moveToLayer(Fluxbox::instance()->getNormalLayer());
928
win.moveToLayer(Fluxbox::instance()->getAboveDockLayer());
934
void Ewmh::updateStrut(WinClient &winclient) {
937
unsigned long nitems = 0, bytes_after = 0;
939
if (winclient.property(m_net_wm_strut, 0, 4, False, XA_CARDINAL,
940
&ret_type, &fmt, &nitems, &bytes_after,
941
(unsigned char **) &data) && data) {
943
int head = winclient.screen().getHead(winclient);
944
winclient.setStrut(winclient.screen().requestStrut(head,
947
winclient.screen().updateAvailableWorkspaceArea();
951
void Ewmh::setupState(FluxboxWindow &win) {
952
/* From Extended Window Manager Hints, draft 1.3:
954
* _NET_WM_STATE, ATOM[]
956
* A list of hints describing the window state. Atoms present in
957
* the list MUST be considered set, atoms not present in the list
958
* MUST be considered not set. The Window Manager SHOULD honor
959
* _NET_WM_STATE whenever a withdrawn window requests to be mapped.
960
* A Client wishing to change the state of a window MUST send a
961
* _NET_WM_STATE client message to the root window (see below).
962
* The Window Manager MUST keep this property updated to reflect
963
* the current state of the window.
965
* The Window Manager should remove the property whenever a window
966
* is withdrawn, but it should leave the property in place when it
967
* is shutting down, e.g. in response to losing ownership of the
968
* WM_Sn manager selection.
972
unsigned long nitems, bytes_after;
973
unsigned char *data = 0;
975
win.winClient().property(m_net_wm_state, 0, 0x7fffffff, False, XA_ATOM,
976
&ret_type, &fmt, &nitems, &bytes_after,
979
Atom *states = (Atom *)data;
980
for (unsigned long i=0; i < nitems; ++i)
981
setState(win, states[i], true);
987
Ewmh::WindowState::WindowState(int t_x, int t_y,
988
unsigned int t_width,
989
unsigned int t_height,
990
int t_layer, unsigned int t_decor) :
998
Ewmh::WindowState *Ewmh::getState(FluxboxWindow &win) {
999
SavedState::iterator it = m_savedstate.find(&win);
1000
if (it == m_savedstate.end())
1006
void Ewmh::clearState(FluxboxWindow &win) {
1007
WindowState *state = 0;
1008
SavedState::iterator it = m_savedstate.find(&win);
1009
if (it == m_savedstate.end())
1014
m_savedstate.erase(it);
1018
void Ewmh::saveState(FluxboxWindow &win, WindowState *state) {
1019
m_savedstate[&win] = state;