Fix for stupid Solaris (maybe other Sysv systems too).
[wmaker-crm.git] / src / kwm.c
blob4d7df00de5243708a681e11160dd95af265e6750
1 /* kwm.c-- stuff for support for kwm hints
3 * Window Maker window manager
4 *
5 * Copyright (c) 1998, 1999 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
25 * Supported stuff:
26 * ================
28 * kfm icon selection from krootbgwm
30 * kwm.h function/method Notes
31 *----------------------------------------------------------------------------
32 * setUnsavedDataHint() currently, only gives visual clue that
33 * there is unsaved data (broken X close button)
34 * setSticky()
35 * setIcon() std X thing...
36 * setDecoration()
37 * logout()
38 * refreshScreen()
39 * setWmCommand() std X thing
40 * currentDesktop()
41 * setKWMModule()
43 * isKWMInitialized() not trustworthy
44 * activeWindow() dunno it's use, but since it's easy to
45 * implement it won't hurt to support
46 * switchToDesktop()
47 * (set/get)WindowRegion()
48 * (set)numberOfDesktops() KDE limits to 32, but wmaker is virtually
49 * unlimited. May raise some incompatibility
50 * in badly written KDE modules?
51 * (set/get)DesktopName()
52 * sendKWMCommand() also does the message relay thing
53 * desktop()
54 * geometryRestore()
55 * isIconified()
56 * isMaximized()
57 * isSticky()
58 * moveToDesktop() WARNING: evil mechanism
59 * setGeometryRestore() WARNING: evil mechanism
60 * setMaximize() woo hoo! wanna race?
61 * setIconify() BAH!: why reinvent the f'ing wheel!?
62 * its even broken!!!
63 * move() std X thing
64 * setGeometry() std X thing
65 * close() std X thing
66 * activate()
67 * activateInternal()
68 * raise() std X thing
69 * lower() std X thing
70 * prepareForSwallowing() std X thing
71 * doNotManage() klugy thing...
72 * getBlablablaString()
73 * setKWMDockModule() maybe we can make the Dock behave as the KDE
74 * dock, but must figure where to show the windows
75 * setDockWindow()
77 * Unsupported stuff (superfluous/not-essential/nonsense):
78 * =======================================================
80 * darkenScreen()
81 * setMiniIcon()
82 * configureWm()
83 * raiseSoundEvent()
84 * registerSoundEvent()
85 * unregisterSoundEvent()
86 * title()
87 * titleWithState()
88 * geometry() kde lib code makes it unnecessary
91 * Extensions to KDE:
92 * ==================
94 * These are clientmessage-type messages specific to Window Maker:
95 * wmaker:info - show info panel
96 * wmaker:legal - show legal panel
97 * wmaker:arrangeIcons - arrange icons
98 * wmaker:showAll - show all windows
99 * wmaker:hideOthers - hide others
100 * wmaker:restart - restart wmaker
101 * wmaker:exit - exit wmaker
105 * TODO
106 * different WORKAREA for each workspace
110 #include "wconfig.h"
112 #ifdef KWM_HINTS
114 #include <X11/Xlib.h>
115 #include <X11/Xutil.h>
116 #include <X11/Xatom.h>
118 #include <stdlib.h>
119 #include <stdio.h>
120 #include <string.h>
121 #include <unistd.h>
123 #include <sys/types.h>
124 #include <sys/socket.h>
125 #include <sys/un.h>
126 #include <signal.h>
129 #include "WindowMaker.h"
131 #include "screen.h"
132 #include "wcore.h"
133 #include "framewin.h"
134 #include "window.h"
135 #include "properties.h"
136 #include "icon.h"
137 #include "client.h"
138 #include "funcs.h"
139 #include "actions.h"
140 #include "workspace.h"
141 #include "dialog.h"
142 #include "stacking.h"
144 #include "kwm.h"
146 /*#define DEBUG1
148 /******* Global ******/
150 extern Time LastFocusChange;
151 extern Time LastTimestamp;
154 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
155 extern Atom _XA_WM_DELETE_WINDOW;
157 /** Local **/
159 static Atom _XA_KWM_COMMAND = 0;
160 static Atom _XA_KWM_ACTIVATE_WINDOW = 0;
161 static Atom _XA_KWM_ACTIVE_WINDOW = 0;
162 static Atom _XA_KWM_DO_NOT_MANAGE = 0;
163 static Atom _XA_KWM_DOCKWINDOW = 0;
164 static Atom _XA_KWM_RUNNING = 0;
166 static Atom _XA_KWM_MODULE = 0;
168 static Atom _XA_KWM_MODULE_INIT = 0;
169 static Atom _XA_KWM_MODULE_INITIALIZED = 0;
170 static Atom _XA_KWM_MODULE_DESKTOP_CHANGE = 0;
171 static Atom _XA_KWM_MODULE_DESKTOP_NAME_CHANGE = 0;
172 static Atom _XA_KWM_MODULE_DESKTOP_NUMBER_CHANGE = 0;
173 static Atom _XA_KWM_MODULE_WIN_ADD = 0;
174 static Atom _XA_KWM_MODULE_WIN_REMOVE = 0;
175 static Atom _XA_KWM_MODULE_WIN_CHANGE = 0;
176 static Atom _XA_KWM_MODULE_WIN_RAISE = 0;
177 static Atom _XA_KWM_MODULE_WIN_LOWER = 0;
178 static Atom _XA_KWM_MODULE_WIN_ACTIVATE = 0;
179 static Atom _XA_KWM_MODULE_WIN_ICON_CHANGE = 0;
180 static Atom _XA_KWM_MODULE_DOCKWIN_ADD = 0;
181 static Atom _XA_KWM_MODULE_DOCKWIN_REMOVE = 0;
183 static Atom _XA_KWM_WIN_UNSAVED_DATA = 0;
184 static Atom _XA_KWM_WIN_DECORATION = 0;
185 static Atom _XA_KWM_WIN_DESKTOP = 0;
186 static Atom _XA_KWM_WIN_GEOMETRY_RESTORE = 0;
187 static Atom _XA_KWM_WIN_ICONIFIED = 0;
188 static Atom _XA_KWM_WIN_MAXIMIZED = 0;
189 static Atom _XA_KWM_WIN_STICKY = 0;
191 static Atom _XA_KWM_WIN_ICON_GEOMETRY = 0;
193 static Atom _XA_KWM_CURRENT_DESKTOP = 0;
194 static Atom _XA_KWM_NUMBER_OF_DESKTOPS = 0;
195 static Atom _XA_KWM_DESKTOP_NAME_[MAX_WORKSPACES];
196 static Atom _XA_KWM_WINDOW_REGION_[MAX_WORKSPACES];
200 /* list of window titles that must not be managed */
201 typedef struct KWMDoNotManageList {
202 char title[20];
203 struct KWMDoNotManageList *next;
204 } KWMDoNotManageList;
206 static KWMDoNotManageList *KWMDoNotManageCrap = NULL;
209 /* list of KWM modules */
210 typedef struct KWMModuleList {
211 Window window;
212 struct KWMModuleList *next;
213 #ifdef DEBUG1
214 char *title;
215 #endif
216 } KWMModuleList;
218 static KWMModuleList *KWMModules = NULL;
220 static KWMModuleList *KWMDockWindows = NULL;
222 /* window decoration types */
223 enum {
224 KWMnoDecoration = 0,
225 KWMnormalDecoration = 1,
226 KWMtinyDecoration = 2,
227 KWMnoFocus = 256,
228 KWMstandaloneMenuBar = 512,
229 KWMdesktopIcon = 1024,
230 KWMstaysOnTop = 2048
235 static Bool
236 getSimpleHint(Window win, Atom atom, long *retval)
238 long *data = 0;
240 assert(atom!=0);
242 data = (long*)PropGetCheckProperty(win, atom, atom, 32, 1, NULL);
244 if (!data)
245 return False;
247 *retval = *data;
249 XFree(data);
251 return True;
256 static void
257 setSimpleHint(Window win, Atom atom, long value)
259 assert(atom!=0);
260 XChangeProperty(dpy, win, atom, atom,
261 32, PropModeReplace, (unsigned char*)&value, 1);
265 static void
266 sendClientMessage(WScreen *scr, Window window, Atom atom, long value)
268 XEvent event;
269 long mask = 0;
271 assert(atom!=0);
273 memset(&event, 0, sizeof(XEvent));
274 event.xclient.type = ClientMessage;
275 event.xclient.message_type = atom;
276 event.xclient.window = window;
277 event.xclient.format = 32;
278 event.xclient.data.l[0] = value;
279 event.xclient.data.l[1] = LastTimestamp;
281 if (scr && scr->root_win == window)
282 mask = SubstructureRedirectMask;
284 XSendEvent(dpy, window, False, mask, &event);
288 static void
289 sendTextMessage(WScreen *scr, Window window, Atom atom, char *text)
291 XEvent event;
292 long mask = 0;
293 int i;
295 assert(atom!=0);
297 memset(&event, 0, sizeof(XEvent));
298 event.xclient.type = ClientMessage;
299 event.xclient.message_type = atom;
300 event.xclient.window = window;
301 event.xclient.format = 8;
303 for (i=0; i<20 && text[i]; i++)
304 event.xclient.data.b[i] = text[i];
306 if (scr && scr->root_win == window)
307 mask = SubstructureRedirectMask;
309 XSendEvent(dpy, window, False, mask, &event);
313 static Bool
314 getAreaHint(Window win, Atom atom, WArea *area)
316 long *data = 0;
318 data = (long*)PropGetCheckProperty(win, atom, atom, 32, 4, NULL);
320 if (!data)
321 return False;
323 area->x1 = data[0];
324 area->y1 = data[1];
325 area->x2 = data[2] + area->x1;
326 area->y2 = data[3] + area->y1;
328 XFree(data);
330 return True;
334 static void
335 setAreaHint(Window win, Atom atom, WArea area)
337 long value[4];
339 assert(atom!=0);
340 value[0] = area.x1;
341 value[1] = area.y1;
342 value[2] = area.x2 - area.x1;
343 value[3] = area.y2 - area.y1;
344 XChangeProperty(dpy, win, atom, atom, 32, PropModeReplace,
345 (unsigned char*)&value, 4);
349 static void
350 addModule(WScreen *scr, Window window)
352 KWMModuleList *node;
353 long val;
354 WWindow *ptr;
356 node = malloc(sizeof(KWMModuleList));
357 if (!node) {
358 wwarning("out of memory while registering KDE module");
359 return;
362 node->next = KWMModules;
363 node->window = window;
364 KWMModules = node;
366 sendClientMessage(scr, window, _XA_KWM_MODULE_INIT, 0);
368 if (getSimpleHint(window, _XA_KWM_MODULE, &val) && val==2) {
369 if (scr->kwm_dock != None) {
370 setSimpleHint(window, _XA_KWM_MODULE, 1);
371 } else {
372 KWMModuleList *ptr;
374 scr->kwm_dock = window;
376 for (ptr = KWMDockWindows; ptr!=NULL; ptr = ptr->next) {
377 sendClientMessage(scr, scr->kwm_dock, _XA_KWM_MODULE_DOCKWIN_ADD,
378 ptr->window);
383 /* send list of windows */
384 for (ptr = scr->focused_window; ptr!=NULL; ptr = ptr->prev) {
385 if (!ptr->flags.kwm_hidden_for_modules
386 && !WFLAGP(ptr, skip_window_list)) {
387 sendClientMessage(scr, window, _XA_KWM_MODULE_WIN_ADD,
388 ptr->client_win);
392 /* send window stacking order */
393 wKWMSendStacking(scr, window);
395 /* send focused window */
396 if (scr->focused_window && scr->focused_window->flags.focused) {
397 sendClientMessage(scr, window, _XA_KWM_MODULE_WIN_ACTIVATE,
398 scr->focused_window->client_win);
401 /* tell who we are */
402 sendTextMessage(scr, window, _XA_KWM_COMMAND, "wm:wmaker");
405 sendClientMessage(scr, window, _XA_KWM_MODULE_INITIALIZED, 0);
406 #ifdef DEBUG1
407 KWMModules->title = NULL;
408 XFetchName(dpy, window, &KWMModules->title);
409 printf("NEW MODULE %s\n", KWMModules->title);
410 #endif
414 static void
415 removeModule(WScreen *scr, Window window)
417 KWMModuleList *next;
419 if (!KWMModules) {
420 return;
423 if (KWMModules->window == window) {
424 next = KWMModules->next;
425 #ifdef DEBUG1
426 printf("REMOVING MODULE %s\n", KWMModules->title);
427 if (KWMModules->title)
428 XFree(KWMModules->title);
429 #endif
430 free(KWMModules);
431 KWMModules = next;
432 } else {
433 KWMModuleList *ptr;
435 ptr = KWMModules;
436 while (ptr->next) {
437 if (ptr->next->window == window) {
438 next = ptr->next->next;
439 #ifdef DEBUG1
440 printf("REMOVING MODULE %s\n", ptr->next->title);
441 if (ptr->next->title)
442 XFree(ptr->next->title);
443 #endif
444 free(ptr->next);
445 ptr->next->next = next;
446 break;
448 ptr->next = ptr->next->next;
452 if (scr->kwm_dock == window)
453 scr->kwm_dock = None;
458 static void
459 addDockWindow(WScreen *scr, Window window)
461 KWMModuleList *ptr;
463 for (ptr = KWMDockWindows; ptr != NULL; ptr = ptr->next) {
464 if (ptr->window == window)
465 break;
467 if (!ptr) {
468 KWMModuleList *node;
470 node = malloc(sizeof(KWMModuleList));
471 if (!node) {
472 wwarning("out of memory while processing KDE dock window");
473 return;
475 node->next = KWMDockWindows;
476 KWMDockWindows = node;
477 node->window = window;
478 XSelectInput(dpy, window, StructureNotifyMask);
480 sendClientMessage(scr, scr->kwm_dock, _XA_KWM_MODULE_DOCKWIN_ADD,
481 window);
486 static void
487 removeDockWindow(WScreen *scr, Window window)
489 if (!KWMDockWindows)
490 return;
492 if (KWMDockWindows->window == window) {
493 KWMModuleList *next;
495 sendClientMessage(scr, scr->kwm_dock, _XA_KWM_MODULE_DOCKWIN_REMOVE,
496 window);
498 next = KWMDockWindows->next;
499 free(KWMDockWindows);
500 KWMDockWindows = next;
502 } else {
503 KWMModuleList *ptr, *next;
505 ptr = KWMDockWindows;
506 while (ptr->next) {
507 if (ptr->next->window == window) {
508 sendClientMessage(scr, scr->kwm_dock,
509 _XA_KWM_MODULE_DOCKWIN_REMOVE, window);
510 next = ptr->next->next;
511 free(ptr->next);
512 ptr->next = next;
513 return;
515 ptr = ptr->next;
521 static void
522 sendToModules(WScreen *scr, Atom atom, WWindow *wwin, long data)
524 KWMModuleList *ptr;
525 XEvent event;
526 long mask;
528 if (wwin) {
529 if (wwin->flags.kwm_hidden_for_modules
530 || WFLAGP(wwin, skip_window_list))
531 return;
532 data = wwin->client_win;
534 #ifdef DEBUG1
535 printf("notifying %s\n",XGetAtomName(dpy, atom));
536 #endif
537 memset(&event, 0, sizeof(XEvent));
538 event.xclient.type = ClientMessage;
539 event.xclient.message_type = atom;
540 event.xclient.format = 32;
541 event.xclient.data.l[1] = LastTimestamp;
543 mask = 0;
544 if (scr && scr->root_win == data)
545 mask = SubstructureRedirectMask;
547 for (ptr = KWMModules; ptr!=NULL; ptr = ptr->next) {
548 event.xclient.window = ptr->window;
549 event.xclient.data.l[0] = data;
550 XSendEvent(dpy, ptr->window, False, mask, &event);
555 void
556 wKWMInitStuff(WScreen *scr)
558 if (!_XA_KWM_WIN_STICKY) {
559 _XA_KWM_WIN_UNSAVED_DATA = XInternAtom(dpy, "KWM_WIN_UNSAVED_DATA",
560 False);
562 _XA_KWM_WIN_DECORATION = XInternAtom(dpy, "KWM_WIN_DECORATION", False);
564 _XA_KWM_WIN_DESKTOP = XInternAtom(dpy, "KWM_WIN_DESKTOP", False);
566 _XA_KWM_WIN_GEOMETRY_RESTORE = XInternAtom(dpy,
567 "KWM_WIN_GEOMETRY_RESTORE",
568 False);
570 _XA_KWM_WIN_STICKY = XInternAtom(dpy, "KWM_WIN_STICKY", False);
572 _XA_KWM_WIN_ICONIFIED = XInternAtom(dpy, "KWM_WIN_ICONIFIED", False);
574 _XA_KWM_WIN_MAXIMIZED = XInternAtom(dpy, "KWM_WIN_MAXIMIZED", False);
576 _XA_KWM_WIN_ICON_GEOMETRY = XInternAtom(dpy, "KWM_WIN_ICON_GEOMETRY",
577 False);
579 _XA_KWM_COMMAND = XInternAtom(dpy, "KWM_COMMAND", False);
581 _XA_KWM_ACTIVE_WINDOW = XInternAtom(dpy, "KWM_ACTIVE_WINDOW", False);
583 _XA_KWM_ACTIVATE_WINDOW = XInternAtom(dpy, "KWM_ACTIVATE_WINDOW",
584 False);
586 _XA_KWM_DO_NOT_MANAGE = XInternAtom(dpy, "KWM_DO_NOT_MANAGE", False);
588 _XA_KWM_CURRENT_DESKTOP = XInternAtom(dpy, "KWM_CURRENT_DESKTOP",
589 False);
591 _XA_KWM_NUMBER_OF_DESKTOPS = XInternAtom(dpy, "KWM_NUMBER_OF_DESKTOPS",
592 False);
594 _XA_KWM_DOCKWINDOW = XInternAtom(dpy, "KWM_DOCKWINDOW", False);
596 _XA_KWM_RUNNING = XInternAtom(dpy, "KWM_RUNNING", False);
598 _XA_KWM_MODULE = XInternAtom(dpy, "KWM_MODULE", False);
600 _XA_KWM_MODULE_INIT = XInternAtom(dpy, "KWM_MODULE_INIT", False);
601 _XA_KWM_MODULE_INITIALIZED = XInternAtom(dpy, "KWM_MODULE_INITIALIZED", False);
603 /* dunno what these do, but Matthias' patch contains it... */
604 _XA_KWM_MODULE_DESKTOP_CHANGE = XInternAtom(dpy, "KWM_MODULE_DESKTOP_CHANGE", False);
605 _XA_KWM_MODULE_DESKTOP_NAME_CHANGE = XInternAtom(dpy, "KWM_MODULE_DESKTOP_NAME_CHANGE", False);
606 _XA_KWM_MODULE_DESKTOP_NUMBER_CHANGE = XInternAtom(dpy, "KWM_MODULE_DESKTOP_NUMBER_CHANGE", False);
608 _XA_KWM_MODULE_WIN_ADD = XInternAtom(dpy, "KWM_MODULE_WIN_ADD", False);
609 _XA_KWM_MODULE_WIN_REMOVE = XInternAtom(dpy, "KWM_MODULE_WIN_REMOVE", False);
610 _XA_KWM_MODULE_WIN_CHANGE = XInternAtom(dpy, "KWM_MODULE_WIN_CHANGE", False);
611 _XA_KWM_MODULE_WIN_RAISE = XInternAtom(dpy, "KWM_MODULE_WIN_RAISE", False);
612 _XA_KWM_MODULE_WIN_LOWER = XInternAtom(dpy, "KWM_MODULE_WIN_LOWER", False);
613 _XA_KWM_MODULE_WIN_ACTIVATE = XInternAtom(dpy, "KWM_MODULE_WIN_ACTIVATE", False);
614 _XA_KWM_MODULE_WIN_ICON_CHANGE = XInternAtom(dpy, "KWM_MODULE_WIN_ICON_CHANGE", False);
615 _XA_KWM_MODULE_DOCKWIN_ADD = XInternAtom(dpy, "KWM_MODULE_DOCKWIN_ADD", False);
616 _XA_KWM_MODULE_DOCKWIN_REMOVE = XInternAtom(dpy, "KWM_MODULE_DOCKWIN_REMOVE", False);
618 memset(_XA_KWM_WINDOW_REGION_, 0, sizeof(_XA_KWM_WINDOW_REGION_));
620 memset(_XA_KWM_DESKTOP_NAME_, 0, sizeof(_XA_KWM_DESKTOP_NAME_));
623 #define SETSTR(hint, str) {\
624 static Atom a = 0; if (!a) a = XInternAtom(dpy, #hint, False);\
625 XChangeProperty(dpy, scr->root_win, a, XA_STRING, 8, PropModeReplace,\
626 (unsigned char*)str, strlen(str));}
628 SETSTR(KWM_STRING_MAXIMIZE, _("Maximize"));
629 SETSTR(KWM_STRING_UNMAXIMIZE, _("Unmaximize"));
630 SETSTR(KWM_STRING_ICONIFY, _("Miniaturize"));
631 SETSTR(KWM_STRING_UNICONIFY, _("Deminiaturize"));
632 SETSTR(KWM_STRING_STICKY, _("Omnipresent"));
633 SETSTR(KWM_STRING_UNSTICKY, _("Not Omnipresent"));
634 SETSTR(KWM_STRING_STRING_MOVE, _("Move"));
635 SETSTR(KWM_STRING_STRING_RESIZE, _("Resize"));
636 SETSTR(KWM_STRING_CLOSE, _("Close"));
637 SETSTR(KWM_STRING_TODESKTOP, _("Move To"));
638 SETSTR(KWM_STRING_ONTOCURRENTDESKTOP, _("Bring Here"));
639 #undef SETSTR
643 void
644 wKWMSendStacking(WScreen *scr, Window module)
646 int i;
647 WCoreWindow *core;
649 for (i = 0; i < MAX_WINDOW_LEVELS; i++) {
650 for (core = scr->stacking_list[i]; core != NULL;
651 core = core->stacking->under) {
652 WWindow *wwin;
654 wwin = wWindowFor(core->window);
655 if (wwin)
656 sendClientMessage(scr, module, _XA_KWM_MODULE_WIN_RAISE,
657 wwin->client_win);
663 void
664 wKWMBroadcastStacking(WScreen *scr)
666 KWMModuleList *ptr = KWMModules;
668 while (ptr) {
669 wKWMSendStacking(scr, ptr->window);
671 ptr = ptr->next;
676 char*
677 wKWMGetWorkspaceName(WScreen *scr, int workspace)
679 Atom type_ret;
680 int fmt_ret;
681 unsigned long nitems_ret;
682 unsigned long bytes_after_ret;
683 char *data = NULL, *tmp;
684 char buffer[64];
686 assert(workspace >= 0 && workspace < MAX_WORKSPACES);
688 if (_XA_KWM_DESKTOP_NAME_[workspace]==0) {
689 sprintf(buffer, "KWM_DESKTOP_NAME_%d", workspace + 1);
691 _XA_KWM_DESKTOP_NAME_[workspace] = XInternAtom(dpy, buffer, False);
694 /* What do these people have against correctly using property types? */
695 if (XGetWindowProperty(dpy, scr->root_win,
696 _XA_KWM_DESKTOP_NAME_[workspace], 0, 128, False,
697 XA_STRING,
698 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
699 (unsigned char**)&data)!=Success || !data)
700 return NULL;
702 tmp = wstrdup(data);
703 XFree(data);
705 return tmp;
709 void
710 wKWMSetInitializedHint(WScreen *scr)
712 setSimpleHint(scr->root_win, _XA_KWM_RUNNING, 1);
716 void
717 wKWMShutdown(WScreen *scr, Bool closeModules)
719 KWMModuleList *ptr;
721 XDeleteProperty(dpy, scr->root_win, _XA_KWM_RUNNING);
723 if (closeModules) {
724 for (ptr = KWMModules; ptr != NULL; ptr = ptr->next) {
725 XKillClient(dpy, ptr->window);
731 void
732 wKWMCheckClientHints(WWindow *wwin, int *layer, int *workspace)
734 long val;
736 if (getSimpleHint(wwin->client_win, _XA_KWM_WIN_UNSAVED_DATA, &val)
737 && val) {
739 wwin->client_flags.broken_close = 1;
741 if (getSimpleHint(wwin->client_win, _XA_KWM_WIN_DECORATION, &val)) {
742 if (val & KWMnoFocus) {
743 wwin->client_flags.no_focusable = 1;
745 switch (val & ~KWMnoFocus) {
746 case KWMnoDecoration:
747 wwin->client_flags.no_titlebar = 1;
748 wwin->client_flags.no_resizebar = 1;
749 break;
750 case KWMtinyDecoration:
751 wwin->client_flags.no_resizebar = 1;
752 break;
753 case KWMstandaloneMenuBar:
754 wwin->client_flags.no_titlebar = 1;
755 wwin->client_flags.no_resizebar = 1;
756 wwin->client_flags.no_resizable = 1;
757 wwin->client_flags.skip_window_list = 1;
758 wwin->client_flags.no_hide_others = 1;
759 wwin->flags.kwm_menubar = 1;
760 *layer = WMMainMenuLevel;
761 break;
762 case KWMdesktopIcon:
763 *layer = WMDesktopLevel;
764 break;
765 case KWMstaysOnTop:
766 *layer = WMFloatingLevel;
767 break;
768 case KWMnormalDecoration:
769 default:
770 break;
773 if (getSimpleHint(wwin->client_win, _XA_KWM_WIN_DESKTOP, &val)) {
774 *workspace = val - 1;
779 void
780 wKWMCheckClientInitialState(WWindow *wwin)
782 long val;
783 WArea area;
785 if (getSimpleHint(wwin->client_win, _XA_KWM_WIN_STICKY, &val) && val) {
787 wwin->client_flags.omnipresent = 1;
789 if (getSimpleHint(wwin->client_win, _XA_KWM_WIN_ICONIFIED, &val) && val) {
791 wwin->flags.miniaturized = 1;
793 if (getSimpleHint(wwin->client_win, _XA_KWM_WIN_MAXIMIZED, &val) && val) {
795 wwin->flags.maximized = MAX_VERTICAL|MAX_HORIZONTAL;
797 if (getAreaHint(wwin->client_win, _XA_KWM_WIN_GEOMETRY_RESTORE, &area)
798 && (wwin->old_geometry.x != area.x1
799 || wwin->old_geometry.y != area.y1
800 || wwin->old_geometry.width != area.x2 - area.x1
801 || wwin->old_geometry.height != area.y2 - area.y1)) {
803 wwin->old_geometry.x = area.x1;
804 wwin->old_geometry.y = area.y1;
805 wwin->old_geometry.width = area.x2 - area.x1;
806 wwin->old_geometry.height = area.y2 - area.y1;
811 Bool
812 wKWMCheckClientHintChange(WWindow *wwin, XPropertyEvent *event)
814 Bool processed = True;
815 Bool flag;
816 long value;
819 if (!wwin->frame) {
820 return False;
823 if (event->atom == _XA_KWM_WIN_UNSAVED_DATA) {
824 #ifdef DEBUG1
825 printf("got KDE unsaved data change\n");
826 #endif
828 flag = getSimpleHint(wwin->client_win, _XA_KWM_WIN_UNSAVED_DATA,
829 &value) && value;
831 if (flag != wwin->client_flags.broken_close) {
832 wwin->client_flags.broken_close = flag;
833 if (wwin->frame)
834 wWindowUpdateButtonImages(wwin);
836 } else if (event->atom == _XA_KWM_WIN_STICKY) {
838 #ifdef DEBUG1
839 printf("got KDE sticky change\n");
840 #endif
841 flag = !getSimpleHint(wwin->client_win, _XA_KWM_WIN_STICKY,
842 &value) || value;
844 if (flag != wwin->client_flags.omnipresent) {
846 wwin->client_flags.omnipresent = flag;
848 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_WORKSPACE);
851 } else if (event->atom == _XA_KWM_WIN_MAXIMIZED) {
853 #ifdef DEBUG1
854 printf("got KDE maximize change\n");
855 #endif
856 flag = !getSimpleHint(wwin->client_win, _XA_KWM_WIN_MAXIMIZED,
857 &value) || value;
859 if (flag != (wwin->flags.maximized!=0)) {
861 if (flag)
862 wMaximizeWindow(wwin, flag*(MAX_VERTICAL|MAX_HORIZONTAL));
863 else
864 wUnmaximizeWindow(wwin);
866 } else if (event->atom == _XA_KWM_WIN_ICONIFIED) {
868 #ifdef DEBUG1
869 printf("got KDE iconify change\n");
870 #endif
871 flag = !getSimpleHint(wwin->client_win, _XA_KWM_WIN_ICONIFIED,
872 &value) || value;
874 if (flag != wwin->flags.miniaturized) {
876 if (flag)
877 wIconifyWindow(wwin);
878 else
879 wDeiconifyWindow(wwin);
882 } else if (event->atom == _XA_KWM_WIN_DECORATION) {
883 Bool refresh = False;
884 int oldnofocus;
886 #ifdef DEBUG1
887 printf("got KDE decoration change\n");
888 #endif
890 oldnofocus = wwin->client_flags.no_focusable;
892 if (getSimpleHint(wwin->client_win, _XA_KWM_WIN_DECORATION, &value)) {
893 wwin->client_flags.no_focusable = (value & KWMnoFocus)!=0;
895 switch (value & ~KWMnoFocus) {
896 case KWMnoDecoration:
897 if (!WFLAGP(wwin, no_titlebar) || !WFLAGP(wwin, no_resizebar))
898 refresh = True;
900 wwin->client_flags.no_titlebar = 1;
901 wwin->client_flags.no_resizebar = 1;
902 break;
904 case KWMtinyDecoration:
905 if (WFLAGP(wwin, no_titlebar) || !WFLAGP(wwin, no_resizebar))
906 refresh = True;
908 wwin->client_flags.no_titlebar = 0;
909 wwin->client_flags.no_resizebar = 1;
910 break;
912 case KWMnormalDecoration:
913 default:
914 if (WFLAGP(wwin, no_titlebar) || WFLAGP(wwin, no_resizebar))
915 refresh = True;
917 wwin->client_flags.no_titlebar = 0;
918 wwin->client_flags.no_resizebar = 0;
919 break;
921 } else {
922 if (WFLAGP(wwin, no_titlebar) || WFLAGP(wwin, no_resizebar))
923 refresh = True;
924 wwin->client_flags.no_focusable = (value & KWMnoFocus)!=0;
925 wwin->client_flags.no_titlebar = 0;
926 wwin->client_flags.no_resizebar = 0;
929 if (refresh)
930 wWindowConfigureBorders(wwin);
932 if (wwin->client_flags.no_focusable && !oldnofocus) {
934 sendToModules(wwin->screen_ptr, _XA_KWM_MODULE_WIN_REMOVE,
935 wwin, 0);
936 wwin->flags.kwm_hidden_for_modules = 1;
938 } else if (!wwin->client_flags.no_focusable && oldnofocus) {
940 if (wwin->flags.kwm_hidden_for_modules) {
941 sendToModules(wwin->screen_ptr, _XA_KWM_MODULE_WIN_ADD,
942 wwin, 0);
943 wwin->flags.kwm_hidden_for_modules = 0;
946 } else if (event->atom == _XA_KWM_WIN_DESKTOP && wwin->frame) {
947 #ifdef DEBUG1
948 printf("got KDE workspace change for %s\n", wwin->frame->title);
949 #endif
950 if (getSimpleHint(wwin->client_win, _XA_KWM_WIN_DESKTOP, &value)
951 && value-1 != wwin->frame->workspace) {
952 wWindowChangeWorkspace(wwin, value-1);
955 } else if (event->atom == _XA_KWM_WIN_GEOMETRY_RESTORE) {
956 WArea area;
958 #ifdef DEBUG1
959 printf("got KDE geometry restore change\n");
960 #endif
961 if (getAreaHint(wwin->client_win, _XA_KWM_WIN_GEOMETRY_RESTORE, &area)
962 && (wwin->old_geometry.x != area.x1
963 || wwin->old_geometry.y != area.y1
964 || wwin->old_geometry.width != area.x2 - area.x1
965 || wwin->old_geometry.height != area.y2 - area.y1)) {
967 wwin->old_geometry.x = area.x1;
968 wwin->old_geometry.y = area.y1;
969 wwin->old_geometry.width = area.x2 - area.x1;
970 wwin->old_geometry.height = area.y2 - area.y1;
972 } else {
973 processed = False;
976 return processed;
980 static Bool
981 performWindowCommand(WScreen *scr, char *command)
983 WWindow *wwin = NULL;
986 wwin = scr->focused_window;
987 if (!wwin || !wwin->flags.focused || !wwin->flags.mapped) {
988 wwin = NULL;
991 CloseWindowMenu(scr);
994 if (strcmp(command, "winMove")==0 || strcmp(command, "winResize")==0) {
996 if (wwin)
997 wKeyboardMoveResizeWindow(wwin);
999 } else if (strcmp(command, "winMaximize")==0) {
1001 if (wwin)
1002 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1004 } else if (strcmp(command, "winRestore")==0) {
1006 if (wwin && wwin->flags.maximized)
1007 wUnmaximizeWindow(wwin);
1009 } else if (strcmp(command, "winIconify")==0) {
1012 if (wwin && !WFLAGP(wwin, no_miniaturizable)) {
1013 if (wwin->protocols.MINIATURIZE_WINDOW)
1014 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1015 LastTimestamp);
1016 else {
1017 wIconifyWindow(wwin);
1021 } else if (strcmp(command, "winClose")==0) {
1023 if (wwin && !WFLAGP(wwin, no_closable)) {
1024 if (wwin->protocols.DELETE_WINDOW)
1025 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
1028 } else if (strcmp(command, "winSticky")==0) {
1030 if (wwin) {
1031 wwin->client_flags.omnipresent ^= 1;
1032 UpdateSwitchMenu(scr, wwin, ACTION_CHANGE_WORKSPACE);
1035 } else if (strcmp(command, "winShade")==0) {
1037 if (wwin && !WFLAGP(wwin, no_shadeable)) {
1038 if (wwin->flags.shaded)
1039 wUnshadeWindow(wwin);
1040 else
1041 wShadeWindow(wwin);
1044 } else if (strcmp(command, "winOperation")==0) {
1046 if (wwin)
1047 OpenWindowMenu(wwin, wwin->frame_x,
1048 wwin->frame_y+wwin->frame->top_width, True);
1050 } else {
1051 return False;
1054 return True;
1058 static void
1059 performCommand(WScreen *scr, char *command, XClientMessageEvent *event)
1061 assert(scr != NULL);
1063 if (strcmp(command, "commandLine")==0
1064 || strcmp(command, "execute")==0) {
1065 char *cmd;
1067 cmd = ExpandOptions(scr, _("%a(Run Command,Type the command to run:)"));
1068 if (cmd) {
1069 ExecuteShellCommand(scr, cmd);
1070 free(cmd);
1072 } else if (strcmp(command, "logout")==0) {
1074 Shutdown(WSLogoutMode);
1076 } else if (strcmp(command, "refreshScreen")==0) {
1078 wRefreshDesktop(scr);
1080 } else if (strncmp(command, "go:", 3)==0) {
1082 Shutdown(WSRestartPreparationMode);
1083 Restart(&command[3], False);
1084 Restart(NULL, True);
1086 } else if (strcmp(command, "desktop+1")==0) {
1088 wWorkspaceRelativeChange(scr, 1);
1090 } else if (strcmp(command, "desktop-1")==0) {
1092 wWorkspaceRelativeChange(scr, -1);
1094 } else if (strcmp(command, "desktop+2")==0) {
1096 wWorkspaceRelativeChange(scr, 2);
1098 } else if (strcmp(command, "desktop-2")==0) {
1100 wWorkspaceRelativeChange(scr, -2);
1102 } else if (strcmp(command, "desktop%%2")==0) {
1104 if (scr->current_workspace % 2 == 1)
1105 wWorkspaceRelativeChange(scr, 1);
1106 else
1107 wWorkspaceRelativeChange(scr, -1);
1108 } else if (strncmp(command, "desktop", 7)==0) {
1109 int ws;
1111 ws = atoi(&command[7]);
1112 wWorkspaceChange(scr, ws);
1114 /* wmaker specific stuff */
1115 } else if (strcmp(command, "wmaker:info")==0) {
1117 wShowInfoPanel(scr);
1119 } else if (strcmp(command, "wmaker:legal")==0) {
1121 wShowLegalPanel(scr);
1123 } else if (strcmp(command, "wmaker:arrangeIcons")==0) {
1125 wArrangeIcons(scr, True);
1127 } else if (strcmp(command, "wmaker:showAll")==0) {
1129 wShowAllWindows(scr);
1131 } else if (strcmp(command, "wmaker:hideOthers")==0) {
1133 wHideOtherApplications(scr->focused_window);
1135 } else if (strcmp(command, "wmaker:restart")==0) {
1137 Shutdown(WSRestartPreparationMode);
1138 Restart(NULL, True);
1140 } else if (strcmp(command, "wmaker:exit")==0) {
1142 Shutdown(WSExitMode);
1144 #ifdef UNSUPPORTED_STUFF
1145 } else if (strcmp(command, "moduleRaised")==0) { /* useless */
1146 } else if (strcmp(command, "deskUnclutter")==0) {
1147 } else if (strcmp(command, "deskCascade")==0) {
1148 } else if (strcmp(command, "configure")==0) {
1149 } else if (strcmp(command, "taskManager")==0) {
1150 } else if (strcmp(command, "darkenScreen")==0) { /* breaks consistency */
1151 #endif
1152 } else if (!performWindowCommand(scr, command)) {
1153 KWMModuleList *module;
1154 long mask = 0;
1155 XEvent ev;
1156 /* do message relay thing */
1158 ev.xclient = *event;
1159 for (module = KWMModules; module != NULL; module = module->next) {
1161 ev.xclient.window = module->window;
1162 if (module->window == scr->root_win)
1163 mask = SubstructureRedirectMask;
1164 else
1165 mask = 0;
1167 XSendEvent(dpy, module->window, False, mask, &ev);
1173 Bool
1174 wKWMProcessClientMessage(XClientMessageEvent *event)
1176 Bool processed = True;
1177 WScreen *scr;
1178 #ifdef DEBUG1
1179 printf("CLIENT MESS %s\n", XGetAtomName(dpy, event->message_type));
1180 #endif
1181 if (event->message_type == _XA_KWM_COMMAND && event->format==8) {
1182 char buffer[24];
1183 int i;
1185 scr = wScreenForRootWindow(event->window);
1187 for (i=0; i<20; i++) {
1188 buffer[i] = event->data.b[i];
1190 buffer[i] = 0;
1192 #ifdef DEBUG1
1193 printf("got KDE command %s\n", buffer);
1194 #endif
1195 performCommand(scr, buffer, event);
1197 } else if (event->message_type == _XA_KWM_ACTIVATE_WINDOW) {
1198 WWindow *wwin;
1200 #ifdef DEBUG1
1201 printf("got KDE activate internal\n");
1202 #endif
1203 wwin = wWindowFor(event->data.l[0]);
1205 if (wwin)
1206 wSetFocusTo(wwin->screen_ptr, wwin);
1208 } else if (event->message_type == _XA_KWM_DO_NOT_MANAGE
1209 && event->format == 8) {
1210 KWMDoNotManageList *node;
1211 int i;
1213 #ifdef DEBUG1
1214 printf("got KDE dont manage\n");
1215 #endif
1217 node = malloc(sizeof(KWMDoNotManageList));
1218 if (!node) {
1219 wwarning("out of memory processing KWM_DO_NOT_MANAGE message");
1221 for (i=0; i<20 && event->data.b[i]; i++)
1222 node->title[i] = event->data.b[i];
1223 node->title[i] = 0;
1225 node->next = KWMDoNotManageCrap;
1226 KWMDoNotManageCrap = node;
1228 } else if (event->message_type == _XA_KWM_MODULE) {
1229 long val;
1230 Window modwin = event->data.l[0];
1232 scr = wScreenForRootWindow(event->window);
1234 if (getSimpleHint(modwin, _XA_KWM_MODULE, &val) && val) {
1235 #ifdef DEBUG1
1236 puts("got KDE module startup");
1237 #endif
1238 addModule(scr, modwin);
1239 } else {
1240 #ifdef DEBUG1
1241 puts("got KDE module finish");
1242 #endif
1243 removeModule(scr, modwin);
1245 } else {
1246 processed = False;
1249 return processed;
1253 void
1254 wKWMCheckModule(WScreen *scr, Window window)
1256 long val;
1258 if (getSimpleHint(window, _XA_KWM_MODULE, &val) && val) {
1259 #ifdef DEBUG1
1260 puts("got KDE module startup");
1261 #endif
1262 addModule(scr, window);
1267 Bool
1268 wKWMCheckRootHintChange(WScreen *scr, XPropertyEvent *event)
1270 Bool processed = True;
1271 long value;
1273 if (event->atom == _XA_KWM_CURRENT_DESKTOP) {
1274 if (getSimpleHint(scr->root_win, _XA_KWM_CURRENT_DESKTOP, &value)) {
1275 #ifdef DEBUG1
1276 printf("got KDE workspace switch to %li\n", value);
1277 #endif
1278 if (value-1 != scr->current_workspace) {
1279 wWorkspaceChange(scr, value-1);
1282 } else if (event->atom == _XA_KWM_NUMBER_OF_DESKTOPS) {
1283 #ifdef DEBUG1
1284 printf("got KDE workspace number change\n");
1285 #endif
1287 if (getSimpleHint(scr->root_win, _XA_KWM_NUMBER_OF_DESKTOPS, &value)) {
1289 /* increasing is easy... */
1290 if (value > scr->workspace_count) {
1291 scr->flags.kwm_syncing_count = 1;
1293 wWorkspaceMake(scr, value - scr->workspace_count);
1295 scr->flags.kwm_syncing_count = 0;
1297 } else if (value < scr->workspace_count) {
1298 int i;
1299 Bool rebuild = False;
1301 scr->flags.kwm_syncing_count = 1;
1303 /* decrease all we can do */
1304 for (i = scr->workspace_count; i >= value; i--) {
1305 if (!wWorkspaceDelete(scr, i)) {
1306 rebuild = True;
1307 break;
1311 scr->flags.kwm_syncing_count = 0;
1313 /* someone destroyed a workspace that can't be destroyed.
1314 * Reset the hints to reflect our internal state.
1316 if (rebuild) {
1317 wKWMUpdateWorkspaceCountHint(scr);
1321 } else {
1322 int i;
1324 processed = False;
1326 for (i = 0; i < MAX_WORKSPACES && i < scr->workspace_count; i++) {
1327 if (event->atom == _XA_KWM_DESKTOP_NAME_[i]) {
1328 char *name;
1330 name = wKWMGetWorkspaceName(scr, i);
1332 #ifdef DEBUG1
1333 printf("got KDE workspace name change to %s\n", name);
1334 #endif
1336 if (name && strncmp(name, scr->workspaces[i]->name,
1337 MAX_WORKSPACENAME_WIDTH)!=0) {
1338 scr->flags.kwm_syncing_name = 1;
1339 wWorkspaceRename(scr, i, name);
1340 scr->flags.kwm_syncing_name = 0;
1342 if (name)
1343 XFree(name);
1344 processed = True;
1345 break;
1346 } else if (event->atom == _XA_KWM_WINDOW_REGION_[i]) {
1347 WArea area;
1349 if (getAreaHint(scr->root_win, event->atom, &area)) {
1351 if (scr->totalUsableArea.x1 != area.x1
1352 || scr->totalUsableArea.y1 != area.y1
1353 || scr->totalUsableArea.x2 != area.x2
1354 || scr->totalUsableArea.y2 != area.y2) {
1355 wScreenUpdateUsableArea(scr);
1359 processed = True;
1360 break;
1365 return processed;
1369 Bool
1370 wKWMManageableClient(WScreen *scr, Window win, char *title)
1372 KWMDoNotManageList *ptr, *next;
1373 long val;
1375 if (getSimpleHint(win, _XA_KWM_DOCKWINDOW, &val) && val) {
1376 addDockWindow(scr, win);
1377 return False;
1380 ptr = KWMDoNotManageCrap;
1382 * TODO: support for glob patterns or regexes
1384 if (ptr && strncmp(ptr->title, title, strlen(ptr->title))==0) {
1385 next = ptr->next;
1386 free(ptr);
1387 KWMDoNotManageCrap = next;
1388 #ifdef DEBUG1
1389 printf("window %s not managed per KDE request\n", title);
1390 #endif
1392 sendToModules(scr, _XA_KWM_MODULE_WIN_ADD, NULL, win);
1393 sendToModules(scr, _XA_KWM_MODULE_WIN_REMOVE, NULL, win);
1395 return False;
1396 } else if (ptr) {
1397 while (ptr->next) {
1398 if (strncmp(ptr->next->title, title, strlen(ptr->next->title))==0) {
1399 #ifdef DEBUG1
1400 printf("window %s not managed per KDE request\n", title);
1401 #endif
1402 next = ptr->next->next;
1403 free(ptr->next);
1404 ptr->next = next;
1406 sendToModules(scr, _XA_KWM_MODULE_WIN_ADD, NULL, win);
1407 sendToModules(scr, _XA_KWM_MODULE_WIN_REMOVE, NULL, win);
1409 return False;
1412 ptr = ptr->next;
1416 return True;
1420 void
1421 wKWMUpdateCurrentWorkspaceHint(WScreen *scr)
1423 setSimpleHint(scr->root_win, _XA_KWM_CURRENT_DESKTOP,
1424 scr->current_workspace+1);
1426 sendToModules(scr, _XA_KWM_MODULE_DESKTOP_CHANGE, NULL,
1427 scr->current_workspace+1);
1431 void
1432 wKWMUpdateActiveWindowHint(WScreen *scr)
1434 long val;
1435 WWindow *wwin, *tmp;
1437 if (!scr->focused_window || !scr->focused_window->flags.focused)
1438 val = None;
1439 else {
1440 val = (long)(scr->focused_window->client_win);
1442 /* raise the menubar thing */
1443 wwin = scr->focused_window;
1444 tmp = wwin->prev;
1445 while (tmp) {
1446 if (tmp->flags.kwm_menubar
1447 && tmp->transient_for == wwin->client_win) {
1448 wRaiseFrame(tmp->frame->core);
1449 break;
1451 tmp = tmp->prev;
1455 XChangeProperty(dpy, scr->root_win, _XA_KWM_ACTIVE_WINDOW,
1456 _XA_KWM_ACTIVE_WINDOW, 32, PropModeReplace,
1457 (unsigned char*)&val, 1);
1458 XFlush(dpy);
1462 void
1463 wKWMUpdateWorkspaceCountHint(WScreen *scr)
1465 if (scr->flags.kwm_syncing_count)
1466 return;
1468 setSimpleHint(scr->root_win, _XA_KWM_NUMBER_OF_DESKTOPS,
1469 scr->workspace_count);
1471 sendToModules(scr, _XA_KWM_MODULE_DESKTOP_NUMBER_CHANGE, NULL,
1472 scr->workspace_count);
1476 void
1477 wKWMCheckDestroy(XDestroyWindowEvent *event)
1479 WScreen *scr;
1481 if (event->event == event->window) {
1482 return;
1485 scr = wScreenSearchForRootWindow(event->event);
1486 if (!scr) {
1487 return;
1490 removeModule(scr, event->window);
1491 removeDockWindow(scr, event->window);
1495 void
1496 wKWMUpdateWorkspaceNameHint(WScreen *scr, int workspace)
1498 char buffer[64];
1500 assert(workspace >= 0 && workspace < MAX_WORKSPACES);
1502 if (_XA_KWM_DESKTOP_NAME_[workspace]==0) {
1503 sprintf(buffer, "KWM_DESKTOP_NAME_%d", workspace + 1);
1505 _XA_KWM_DESKTOP_NAME_[workspace] = XInternAtom(dpy, buffer, False);
1508 XChangeProperty(dpy, scr->root_win, _XA_KWM_DESKTOP_NAME_[workspace],
1509 XA_STRING, 8, PropModeReplace,
1510 (unsigned char*)scr->workspaces[workspace]->name,
1511 strlen(scr->workspaces[workspace]->name)+1);
1513 sendToModules(scr, _XA_KWM_MODULE_DESKTOP_NAME_CHANGE, NULL, workspace+1);
1518 void
1519 wKWMUpdateClientWorkspace(WWindow *wwin)
1521 #ifdef DEBUG1
1522 printf("updating workspace of %s to %i\n",
1523 wwin->frame->title, wwin->frame->workspace+1);
1524 #endif
1525 setSimpleHint(wwin->client_win, _XA_KWM_WIN_DESKTOP,
1526 wwin->frame->workspace+1);
1530 void
1531 wKWMUpdateClientGeometryRestore(WWindow *wwin)
1533 WArea rect;
1535 rect.x1 = wwin->old_geometry.x;
1536 rect.y1 = wwin->old_geometry.y;
1537 rect.x2 = wwin->old_geometry.x + wwin->old_geometry.width;
1538 rect.y2 = wwin->old_geometry.y + wwin->old_geometry.height;
1540 setAreaHint(wwin->client_win, _XA_KWM_WIN_GEOMETRY_RESTORE, rect);
1544 void
1545 wKWMUpdateClientStateHint(WWindow *wwin, WKWMStateFlag flags)
1547 if (flags & KWMIconifiedFlag) {
1548 setSimpleHint(wwin->client_win, _XA_KWM_WIN_ICONIFIED,
1549 wwin->flags.miniaturized /*|| wwin->flags.shaded
1550 || wwin->flags.hidden*/);
1552 if (flags & KWMStickyFlag) {
1553 setSimpleHint(wwin->client_win, _XA_KWM_WIN_STICKY,
1554 IS_OMNIPRESENT(wwin));
1556 if (flags & KWMMaximizedFlag) {
1557 setSimpleHint(wwin->client_win, _XA_KWM_WIN_MAXIMIZED,
1558 wwin->flags.maximized!=0);
1563 Bool
1564 wKWMGetUsableArea(WScreen *scr, WArea *area)
1566 char buffer[64];
1568 if (_XA_KWM_WINDOW_REGION_[0]==0) {
1569 sprintf(buffer, "KWM_WINDOW_REGION_%d", 1);
1571 _XA_KWM_WINDOW_REGION_[0] = XInternAtom(dpy, buffer, False);
1574 return getAreaHint(scr->root_win, _XA_KWM_WINDOW_REGION_[0], area);
1579 Bool
1580 wKWMGetIconGeometry(WWindow *wwin, WArea *area)
1582 return getAreaHint(wwin->client_win, _XA_KWM_WIN_ICON_GEOMETRY, area);
1587 #ifdef not_used
1588 void
1589 wKWMSetUsableAreaHint(WScreen *scr, int workspace)
1591 /* if we set this after making changes of our own to the area,
1592 * the next time the area changes, we won't know what should
1593 * be the new final area. This protocol isn't worth a shit :/
1596 * According to Matthias Ettrich:
1597 * Indeed, there's no protocol to deal with the area yet in case several
1598 * clients want to influence it. It is sufficent, though, if it is clear
1599 * that one process is responsable for the area. For KDE this is kpanel, but
1600 * I see that there might be a conflict with the docking area of windowmaker
1601 * itself.
1605 #ifdef notdef
1606 char buffer[64];
1608 assert(workspace >= 0 && workspace < MAX_WORKSPACES);
1610 if (_XA_KWM_WINDOW_REGION_[workspace]==0) {
1611 sprintf(buffer, "KWM_WINDOW_REGION_%d", workspace+1);
1613 _XA_KWM_WINDOW_REGION_[workspace] = XInternAtom(dpy, buffer, False);
1616 setAreaHint(scr->root_win, _XA_KWM_WINDOW_REGION_[workspace],
1617 scr->totalUsableArea);
1618 #endif
1620 #endif /* not_used */
1622 void
1623 wKWMSendEventMessage(WWindow *wwin, WKWMEventMessage message)
1625 Atom msg;
1627 if (wwin && (wwin->flags.internal_window
1628 || wwin->flags.kwm_hidden_for_modules
1629 || !wwin->flags.kwm_managed
1630 || WFLAGP(wwin, skip_window_list)))
1631 return;
1633 switch (message) {
1634 case WKWMAddWindow:
1635 msg = _XA_KWM_MODULE_WIN_ADD;
1636 break;
1637 case WKWMRemoveWindow:
1638 msg = _XA_KWM_MODULE_WIN_REMOVE;
1639 break;
1640 case WKWMFocusWindow:
1641 msg = _XA_KWM_MODULE_WIN_ACTIVATE;
1642 break;
1643 case WKWMRaiseWindow:
1644 msg = _XA_KWM_MODULE_WIN_RAISE;
1645 break;
1646 case WKWMLowerWindow:
1647 msg = _XA_KWM_MODULE_WIN_LOWER;
1648 break;
1649 case WKWMChangedClient:
1650 msg = _XA_KWM_MODULE_WIN_CHANGE;
1651 break;
1652 case WKWMIconChange:
1653 msg = _XA_KWM_MODULE_WIN_ICON_CHANGE;
1654 break;
1655 default:
1656 return;
1659 sendToModules(wwin ? wwin->screen_ptr : NULL, msg, wwin, 0);
1663 static void
1664 writeSocket(int sock, char *data)
1666 char buffer[128];
1668 sprintf(buffer, "%i ", strlen(data));
1669 write(sock, buffer, strlen(buffer));
1670 write(sock, data, strlen(data));
1674 static int
1675 connectKFM(WScreen *scr)
1677 char *path;
1678 char buffer[128];
1679 char *ptr;
1680 FILE *f;
1681 int pid;
1682 int sock = 0;
1683 struct sockaddr_un addr;
1685 path = wstrappend(wgethomedir(), "/.kde/share/apps/kfm/pid");
1686 strcpy(buffer, getenv("DISPLAY"));
1688 ptr = strchr(buffer, ':');
1689 if (ptr)
1690 *ptr = '_';
1692 ptr = strrchr(buffer, '.');
1693 if (ptr)
1694 *ptr = 0;
1696 char b[32];
1698 sprintf(b, ".%i", scr->screen);
1699 strcat(buffer, b);
1701 ptr = path;
1702 path = wstrappend(ptr, buffer);
1703 free(ptr);
1705 /* pid file */
1706 f = fopen(path, "r");
1707 free(path);
1708 if (!f)
1709 return -1;
1711 buffer[0] = 0;
1712 fgets(buffer, 123, f);
1713 pid = atoi(buffer);
1714 if (pid <= 0)
1715 return -1;
1717 if (kill(pid, 0) != 0)
1718 return -1;
1720 buffer[0] = 0;
1721 fscanf(f, "%s", buffer);
1722 fclose(f);
1724 sock = socket(AF_UNIX, SOCK_STREAM, 0);
1725 if (sock < 0)
1726 return -1;
1727 addr.sun_family = AF_UNIX;
1728 strcpy(addr.sun_path, buffer);
1730 if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
1731 close(sock);
1732 return -1;
1735 path = wstrappend(wgethomedir(), "/.kde/share/apps/kfm/magic");
1736 f = fopen(path, "r");
1737 if (!f) {
1738 return -1;
1740 ptr = fgets(buffer, 123, f);
1741 fclose(f);
1742 if (!ptr) {
1743 return -1;
1745 puts(buffer);
1747 ptr = wstrappend("auth", buffer);
1749 writeSocket(sock, ptr);
1750 free(ptr);
1752 return sock;
1756 void
1757 wKWMSelectRootRegion(WScreen *scr, int x, int y, int w, int h, Bool control)
1759 #if 0
1760 char buffer[128];
1761 int sock;
1763 puts("CONNECTING");
1764 sock = connectKFM(scr);
1765 if (sock < 0)
1766 return;
1767 puts("SENDING DATA");
1769 sprintf(buffer, "selectRootIcons %i %i %i %i %c", x, y, w, h, control);
1770 writeSocket(sock, buffer);
1772 close(sock);
1773 #endif
1777 #endif /* KWM_HINTS */