- Changed fallback font to 'sans serif:pixelsize=12'
[wmaker-crm.git] / src / window.c
blob63a68c4ed1643765e9b85eb682c68ac4dc92fbea
1 /* window.c - client window managing stuffs
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
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.
23 #include "wconfig.h"
25 #include <X11/Xlib.h>
26 #include <X11/Xutil.h>
27 #ifdef SHAPE
28 #include <X11/extensions/shape.h>
29 #endif
30 #ifdef KEEP_XKB_LOCK_STATUS
31 #include <X11/XKBlib.h>
32 #endif /* KEEP_XKB_LOCK_STATUS */
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
37 /* For getting mouse wheel mappings from WINGs */
38 #include <WINGs/WINGsP.h>
40 #include "WindowMaker.h"
41 #include "GNUstep.h"
42 #include "wcore.h"
43 #include "framewin.h"
44 #include "texture.h"
45 #include "window.h"
46 #include "winspector.h"
47 #include "icon.h"
48 #include "properties.h"
49 #include "actions.h"
50 #include "client.h"
51 #include "funcs.h"
52 #include "keybind.h"
53 #include "stacking.h"
54 #include "defaults.h"
55 #include "workspace.h"
56 #include "xinerama.h"
59 #ifdef MWM_HINTS
60 # include "motif.h"
61 #endif
62 #ifdef NETWM_HINTS
63 # include "wmspec.h"
64 #endif
66 /****** Global Variables ******/
68 extern WShortKey wKeyBindings[WKBD_LAST];
70 #ifdef SHAPE
71 extern Bool wShapeSupported;
72 #endif
74 /* contexts */
75 extern XContext wWinContext;
77 /* cursors */
78 extern Cursor wCursor[WCUR_LAST];
80 /* protocol atoms */
81 extern Atom _XA_WM_DELETE_WINDOW;
82 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
84 extern Atom _XA_WINDOWMAKER_STATE;
86 extern WPreferences wPreferences;
88 #define MOD_MASK wPreferences.modifier_mask
90 extern Time LastTimestamp;
92 /* superfluous... */
93 extern void DoWindowBirth(WWindow*);
97 /***** Local Stuff *****/
100 static WWindowState *windowState=NULL;
104 /* local functions */
105 static FocusMode getFocusMode(WWindow *wwin);
107 static int getSavedState(Window window, WSavedState **state);
109 static void setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints);
111 /* event handlers */
114 /* frame window (during window grabs) */
115 static void frameMouseDown(WObjDescriptor *desc, XEvent *event);
117 /* close button */
118 static void windowCloseClick(WCoreWindow *sender, void *data, XEvent *event);
119 static void windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event);
121 /* iconify button */
122 static void windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event);
124 #ifdef XKB_BUTTON_HINT
125 static void windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event);
126 #endif
128 static void titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
129 static void titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event);
131 static void resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
134 /****** Notification Observers ******/
136 static void
137 appearanceObserver(void *self, WMNotification *notif)
139 WWindow *wwin = (WWindow*)self;
140 int flags = (int)WMGetNotificationClientData(notif);
142 if (!wwin->frame || (!wwin->frame->titlebar && !wwin->frame->resizebar))
143 return;
145 if (flags & WFontSettings) {
146 wWindowConfigureBorders(wwin);
147 if(wwin->flags.shaded) {
148 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
149 wwin->frame->top_width - 1);
151 wwin->client.y = wwin->frame_y - wwin->client.height
152 + wwin->frame->top_width;
153 wWindowSynthConfigureNotify(wwin);
156 if (flags & WTextureSettings) {
157 wwin->frame->flags.need_texture_remake = 1;
159 if (flags & (WTextureSettings | WColorSettings)) {
160 if (wwin->frame->titlebar)
161 XClearWindow(dpy, wwin->frame->titlebar->window);
163 wFrameWindowPaint(wwin->frame);
167 /************************************/
169 WWindow*
170 wWindowFor(Window window)
172 WObjDescriptor *desc;
174 if (window==None)
175 return NULL;
177 if (XFindContext(dpy, window, wWinContext, (XPointer*)&desc)==XCNOENT)
178 return NULL;
180 if (desc->parent_type==WCLASS_WINDOW)
181 return desc->parent;
182 else if (desc->parent_type==WCLASS_FRAME) {
183 WFrameWindow *frame = (WFrameWindow*)desc->parent;
184 if (frame->flags.is_client_window_frame)
185 return frame->child;
188 return NULL;
192 WWindow*
193 wWindowCreate()
195 WWindow *wwin;
197 wwin = wmalloc(sizeof(WWindow));
198 wretain(wwin);
200 memset(wwin, 0, sizeof(WWindow));
202 wwin->client_descriptor.handle_mousedown = frameMouseDown;
203 wwin->client_descriptor.parent = wwin;
204 wwin->client_descriptor.self = wwin;
205 wwin->client_descriptor.parent_type = WCLASS_WINDOW;
207 return wwin;
211 void
212 wWindowDestroy(WWindow *wwin)
214 int i;
216 if (wwin->screen_ptr->cmap_window == wwin) {
217 wwin->screen_ptr->cmap_window = NULL;
220 WMRemoveNotificationObserver(wwin);
222 wwin->flags.destroyed = 1;
224 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
225 if (!wwin->screen_ptr->shortcutWindows[i])
226 continue;
228 WMRemoveFromArray(wwin->screen_ptr->shortcutWindows[i], wwin);
230 if (!WMGetArrayItemCount(wwin->screen_ptr->shortcutWindows[i])) {
231 WMFreeArray(wwin->screen_ptr->shortcutWindows[i]);
232 wwin->screen_ptr->shortcutWindows[i] = NULL;
236 if (wwin->fake_group && wwin->fake_group->retainCount>0) {
237 wwin->fake_group->retainCount--;
238 if (wwin->fake_group->retainCount==0 && wwin->fake_group->leader!=None) {
239 XDestroyWindow(dpy, wwin->fake_group->leader);
240 wwin->fake_group->leader = None;
241 wwin->fake_group->origLeader = None;
242 XFlush(dpy);
246 if (wwin->normal_hints)
247 XFree(wwin->normal_hints);
249 if (wwin->wm_hints)
250 XFree(wwin->wm_hints);
252 if (wwin->wm_instance)
253 XFree(wwin->wm_instance);
255 if (wwin->wm_class)
256 XFree(wwin->wm_class);
258 if (wwin->wm_gnustep_attr)
259 wfree(wwin->wm_gnustep_attr);
261 if (wwin->cmap_windows)
262 XFree(wwin->cmap_windows);
264 XDeleteContext(dpy, wwin->client_win, wWinContext);
266 if (wwin->frame)
267 wFrameWindowDestroy(wwin->frame);
269 if (wwin->icon) {
270 RemoveFromStackList(wwin->icon->core);
271 wIconDestroy(wwin->icon);
272 if (wPreferences.auto_arrange_icons)
273 wArrangeIcons(wwin->screen_ptr, True);
276 #ifdef NETWM_HINTS
277 if (wwin->net_icon_image)
278 RReleaseImage(wwin->net_icon_image);
279 #endif
281 wrelease(wwin);
285 static void
286 setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints)
288 if (gs_hints->flags & GSWindowStyleAttr) {
289 if (gs_hints->window_style == WMBorderlessWindowMask) {
290 wwin->client_flags.no_border = 1;
291 wwin->client_flags.no_titlebar = 1;
292 wwin->client_flags.no_closable = 1;
293 wwin->client_flags.no_miniaturizable = 1;
294 wwin->client_flags.no_resizable = 1;
295 wwin->client_flags.no_close_button = 1;
296 wwin->client_flags.no_miniaturize_button = 1;
297 wwin->client_flags.no_resizebar = 1;
298 } else {
299 wwin->client_flags.no_close_button =
300 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
302 wwin->client_flags.no_closable =
303 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
305 wwin->client_flags.no_miniaturize_button =
306 ((gs_hints->window_style & WMMiniaturizableWindowMask)?0:1);
308 wwin->client_flags.no_miniaturizable =
309 wwin->client_flags.no_miniaturize_button;
311 wwin->client_flags.no_resizebar =
312 ((gs_hints->window_style & WMResizableWindowMask)?0:1);
314 wwin->client_flags.no_resizable = wwin->client_flags.no_resizebar;
316 /* these attributes supposedly imply in the existence
317 * of a titlebar */
318 if (gs_hints->window_style & (WMResizableWindowMask|
319 WMClosableWindowMask|
320 WMMiniaturizableWindowMask)) {
321 wwin->client_flags.no_titlebar = 0;
322 } else {
323 wwin->client_flags.no_titlebar =
324 ((gs_hints->window_style & WMTitledWindowMask)?0:1);
328 } else {
329 /* setup the defaults */
330 wwin->client_flags.no_border = 0;
331 wwin->client_flags.no_titlebar = 0;
332 wwin->client_flags.no_closable = 0;
333 wwin->client_flags.no_miniaturizable = 0;
334 wwin->client_flags.no_resizable = 0;
335 wwin->client_flags.no_close_button = 0;
336 wwin->client_flags.no_miniaturize_button = 0;
337 wwin->client_flags.no_resizebar = 0;
339 if (gs_hints->extra_flags & GSNoApplicationIconFlag) {
340 wwin->client_flags.no_appicon = 1;
343 /* temporary solution to avoid GS menus in our window list.
344 * it's temporary because it's not the proper way: windows at the
345 * floating level are also skipped from the window list with this.
346 * Fix it -Dan */
347 if (gs_hints->flags & GSWindowLevelAttr) {
348 if (gs_hints->window_level == WMMainMenuWindowLevel ||
349 gs_hints->window_level == WMSubmenuWindowLevel) {
350 wwin->client_flags.skip_window_list = 1;
357 void
358 wWindowCheckAttributeSanity(WWindow *wwin, WWindowAttributes *wflags,
359 WWindowAttributes *mask)
361 if (wflags->no_appicon && mask->no_appicon)
362 wflags->emulate_appicon = 0;
364 if (wwin->main_window!=None) {
365 WApplication *wapp = wApplicationOf(wwin->main_window);
366 if (wapp && !wapp->flags.emulated)
367 wflags->emulate_appicon = 0;
370 if (wwin->transient_for!=None
371 && wwin->transient_for!=wwin->screen_ptr->root_win)
372 wflags->emulate_appicon = 0;
374 if (wflags->sunken && mask->sunken && wflags->floating && mask->floating)
375 wflags->sunken = 0;
380 void
381 wWindowSetupInitialAttributes(WWindow *wwin, int *level, int *workspace)
383 WScreen *scr = wwin->screen_ptr;
385 /* sets global default stuff */
386 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
387 &wwin->client_flags, NULL, True);
389 * Decoration setting is done in this precedence (lower to higher)
390 * - use global default in the resource database
391 * - guess some settings
392 * - use GNUstep/external window attributes
393 * - set hints specified for the app in the resource DB
396 WSETUFLAG(wwin, broken_close, 0);
398 if (wwin->protocols.DELETE_WINDOW)
399 WSETUFLAG(wwin, kill_close, 0);
400 else
401 WSETUFLAG(wwin, kill_close, 1);
403 /* transients can't be iconified or maximized */
404 if (wwin->transient_for!=None && wwin->transient_for!=scr->root_win) {
405 WSETUFLAG(wwin, no_miniaturizable, 1);
406 WSETUFLAG(wwin, no_miniaturize_button, 1);
409 /* if the window can't be resized, remove the resizebar */
410 if (wwin->normal_hints->flags & (PMinSize|PMaxSize)
411 && (wwin->normal_hints->min_width==wwin->normal_hints->max_width)
412 && (wwin->normal_hints->min_height==wwin->normal_hints->max_height)) {
413 WSETUFLAG(wwin, no_resizable, 1);
414 WSETUFLAG(wwin, no_resizebar, 1);
417 /* set GNUstep window attributes */
418 if (wwin->wm_gnustep_attr) {
419 setupGNUstepHints(wwin, wwin->wm_gnustep_attr);
421 if (wwin->wm_gnustep_attr->flags & GSWindowLevelAttr) {
423 *level = wwin->wm_gnustep_attr->window_level;
425 * INT_MIN is the only illegal window level.
427 if (*level == INT_MIN)
428 *level = INT_MIN + 1;
429 } else {
430 /* setup defaults */
431 *level = WMNormalLevel;
433 } else {
434 int tmp_workspace = -1;
435 int tmp_level = INT_MIN; /* INT_MIN is never used by the window levels */
436 Bool check;
438 check = False;
440 #ifdef MWM_HINTS
441 wMWMCheckClientHints(wwin);
442 #endif /* MWM_HINTS */
444 #ifdef NETWM_HINTS
445 if (!check)
446 check = wNETWMCheckClientHints(wwin, &tmp_level, &tmp_workspace);
447 #endif
449 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
450 * have INT_MIN that means that no window level was requested. -Dan
452 if (tmp_level == INT_MIN) {
453 if (WFLAGP(wwin, floating))
454 *level = WMFloatingLevel;
455 else if (WFLAGP(wwin, sunken))
456 *level = WMSunkenLevel;
457 else
458 *level = WMNormalLevel;
459 } else {
460 *level = tmp_level;
463 if (wwin->transient_for!=None && wwin->transient_for != scr->root_win) {
464 WWindow * transientOwner = wWindowFor(wwin->transient_for);
465 if (transientOwner) {
466 int ownerLevel = transientOwner->frame->core->stacking->window_level;
467 if (ownerLevel > *level) *level = ownerLevel;
471 if (tmp_workspace >= 0) {
472 *workspace = tmp_workspace % scr->workspace_count;
477 * Set attributes specified only for that window/class.
478 * This might do duplicate work with the 1st wDefaultFillAttributes().
480 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
481 &wwin->user_flags, &wwin->defined_user_flags,
482 False);
484 * Sanity checks for attributes that depend on other attributes
486 if (wwin->user_flags.no_appicon && wwin->defined_user_flags.no_appicon)
487 wwin->user_flags.emulate_appicon = 0;
489 if (wwin->main_window!=None) {
490 WApplication *wapp = wApplicationOf(wwin->main_window);
491 if (wapp && !wapp->flags.emulated)
492 wwin->user_flags.emulate_appicon = 0;
495 if (wwin->transient_for!=None
496 && wwin->transient_for!=wwin->screen_ptr->root_win)
497 wwin->user_flags.emulate_appicon = 0;
499 if (wwin->user_flags.sunken && wwin->defined_user_flags.sunken
500 && wwin->user_flags.floating && wwin->defined_user_flags.floating)
501 wwin->user_flags.sunken = 0;
503 WSETUFLAG(wwin, no_shadeable, WFLAGP(wwin, no_titlebar));
506 /* windows that have takefocus=False shouldn't take focus at all */
507 if (wwin->focus_mode == WFM_NO_INPUT) {
508 wwin->client_flags.no_focusable = 1;
515 Bool
516 wWindowCanReceiveFocus(WWindow *wwin)
518 if (!wwin->flags.mapped && (!wwin->flags.shaded || wwin->flags.hidden))
519 return False;
520 if (WFLAGP(wwin, no_focusable) || wwin->flags.miniaturized)
521 return False;
522 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
523 return False;
525 return True;
529 Bool
530 wWindowObscuresWindow(WWindow *wwin, WWindow *obscured)
532 int w1, h1, w2, h2;
534 w1 = wwin->frame->core->width;
535 h1 = wwin->frame->core->height;
536 w2 = obscured->frame->core->width;
537 h2 = obscured->frame->core->height;
539 if (!IS_OMNIPRESENT(wwin) && !IS_OMNIPRESENT(obscured)
540 && wwin->frame->workspace != obscured->frame->workspace)
541 return False;
543 if (wwin->frame_x + w1 < obscured->frame_x
544 || wwin->frame_y + h1 < obscured->frame_y
545 || wwin->frame_x > obscured->frame_x + w2
546 || wwin->frame_y > obscured->frame_y + h2) {
547 return False;
550 return True;
554 static void
555 fixLeaderProperties(WWindow *wwin)
557 XClassHint *classHint;
558 XWMHints *hints, *clientHints;
559 Window leaders[2], window;
560 char **argv, *command;
561 int argc, i, pid;
562 Bool haveCommand;
564 classHint = XAllocClassHint();
565 clientHints = XGetWMHints(dpy, wwin->client_win);
566 pid = wNETWMGetPidForWindow(wwin->client_win);
567 if (pid > 0) {
568 haveCommand = GetCommandForPid(pid, &argv, &argc);
569 } else {
570 haveCommand = False;
573 leaders[0] = wwin->client_leader;
574 leaders[1] = wwin->group_id;
576 if (haveCommand) {
577 command = GetCommandForWindow(wwin->client_win);
578 if (command) {
579 /* command already set. nothing to do. */
580 wfree(command);
581 } else {
582 XSetCommand(dpy, wwin->client_win, argv, argc);
586 for (i=0; i<2; i++) {
587 window = leaders[i];
588 if (window) {
589 if (XGetClassHint(dpy, window, classHint) == 0) {
590 classHint->res_name = wwin->wm_instance;
591 classHint->res_class = wwin->wm_class;
592 XSetClassHint(dpy, window, classHint);
594 hints = XGetWMHints(dpy, window);
595 if (hints) {
596 XFree(hints);
597 } else if (clientHints) {
598 /* set window group leader to self */
599 clientHints->window_group = window;
600 clientHints->flags |= WindowGroupHint;
601 XSetWMHints(dpy, window, clientHints);
604 if (haveCommand) {
605 command = GetCommandForWindow(window);
606 if (command) {
607 /* command already set. nothing to do. */
608 wfree(command);
609 } else {
610 XSetCommand(dpy, window, argv, argc);
616 XFree(classHint);
617 if (clientHints) {
618 XFree(clientHints);
620 if (haveCommand) {
621 wfree(argv);
626 static Window
627 createFakeWindowGroupLeader(WScreen *scr, Window win, char *instance, char *class)
629 XClassHint *classHint;
630 XWMHints *hints;
631 Window leader;
632 int argc;
633 char **argv;
635 leader = XCreateSimpleWindow(dpy, scr->root_win, 10, 10, 10, 10, 0, 0, 0);
636 /* set class hint */
637 classHint = XAllocClassHint();
638 classHint->res_name = instance;
639 classHint->res_class = class;
640 XSetClassHint(dpy, leader, classHint);
641 XFree(classHint);
643 /* inherit these from the original leader if available */
644 hints = XGetWMHints(dpy, win);
645 if (!hints) {
646 hints = XAllocWMHints();
647 hints->flags = 0;
649 /* set window group leader to self */
650 hints->window_group = leader;
651 hints->flags |= WindowGroupHint;
652 XSetWMHints(dpy, leader, hints);
653 XFree(hints);
655 if (XGetCommand(dpy, win, &argv, &argc)!=0 && argc > 0) {
656 XSetCommand(dpy, leader, argv, argc);
657 XFreeStringList(argv);
660 return leader;
664 static int
665 matchIdentifier(void *item, void *cdata)
667 return (strcmp(((WFakeGroupLeader*)item)->identifier, (char*)cdata)==0);
672 *----------------------------------------------------------------
673 * wManageWindow--
674 * reparents the window and allocates a descriptor for it.
675 * Window manager hints and other hints are fetched to configure
676 * the window decoration attributes and others. User preferences
677 * for the window are used if available, to configure window
678 * decorations and some behaviour.
679 * If in startup, windows that are override redirect,
680 * unmapped and never were managed and are Withdrawn are not
681 * managed.
683 * Returns:
684 * the new window descriptor
686 * Side effects:
687 * The window is reparented and appropriate notification
688 * is done to the client. Input mask for the window is setup.
689 * The window descriptor is also associated with various window
690 * contexts and inserted in the head of the window list.
691 * Event handler contexts are associated for some objects
692 * (buttons, titlebar and resizebar)
694 *----------------------------------------------------------------
696 WWindow*
697 wManageWindow(WScreen *scr, Window window)
699 WWindow *wwin;
700 int x, y;
701 unsigned width, height;
702 XWindowAttributes wattribs;
703 XSetWindowAttributes attribs;
704 WWindowState *win_state;
705 WWindow *transientOwner = NULL;
706 int window_level;
707 int wm_state;
708 int foo;
709 int workspace = -1;
710 char *title;
711 Bool withdraw = False;
712 Bool raise = False;
714 /* mutex. */
715 /* XGrabServer(dpy); */
716 XSync(dpy, False);
717 /* make sure the window is still there */
718 if (!XGetWindowAttributes(dpy, window, &wattribs)) {
719 XUngrabServer(dpy);
720 return NULL;
723 /* if it's an override-redirect, ignore it */
724 if (wattribs.override_redirect) {
725 XUngrabServer(dpy);
726 return NULL;
729 wm_state = PropGetWindowState(window);
731 /* if it's startup and the window is unmapped, don't manage it */
732 if (scr->flags.startup && wm_state < 0 && wattribs.map_state==IsUnmapped) {
733 XUngrabServer(dpy);
734 return NULL;
737 wwin = wWindowCreate();
739 title= wNETWMGetWindowName(window);
740 if (title)
741 wwin->flags.net_has_title= 1;
742 if (!title && !wFetchName(dpy, window, &title))
743 title = NULL;
745 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
747 #ifdef DEBUG
748 printf("managing window %x\n", (unsigned)window);
749 #endif
751 #ifdef SHAPE
752 if (wShapeSupported) {
753 int junk;
754 unsigned int ujunk;
755 int b_shaped;
757 XShapeSelectInput(dpy, window, ShapeNotifyMask);
758 XShapeQueryExtents(dpy, window, &b_shaped, &junk, &junk, &ujunk,
759 &ujunk, &junk, &junk, &junk, &ujunk, &ujunk);
760 wwin->flags.shaped = b_shaped;
762 #endif
765 *--------------------------------------------------
767 * Get hints and other information in properties
769 *--------------------------------------------------
771 PropGetWMClass(window, &wwin->wm_class, &wwin->wm_instance);
773 /* setup descriptor */
774 wwin->client_win = window;
775 wwin->screen_ptr = scr;
777 wwin->old_border_width = wattribs.border_width;
779 wwin->event_mask = CLIENT_EVENTS;
780 attribs.event_mask = CLIENT_EVENTS;
781 attribs.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask;
782 attribs.save_under = False;
783 XChangeWindowAttributes(dpy, window, CWEventMask|CWDontPropagate
784 |CWSaveUnder, &attribs);
785 XSetWindowBorderWidth(dpy, window, 0);
787 /* get hints from GNUstep app */
788 if (wwin->wm_class != 0 && strcmp(wwin->wm_class, "GNUstep") == 0) {
789 wwin->flags.is_gnustep = 1;
791 if (!PropGetGNUstepWMAttr(window, &wwin->wm_gnustep_attr)) {
792 wwin->wm_gnustep_attr = NULL;
795 wwin->client_leader = PropGetClientLeader(window);
796 if (wwin->client_leader!=None)
797 wwin->main_window = wwin->client_leader;
799 wwin->wm_hints = XGetWMHints(dpy, window);
801 if (wwin->wm_hints) {
802 if (wwin->wm_hints->flags & StateHint) {
804 if (wwin->wm_hints->initial_state == IconicState) {
806 wwin->flags.miniaturized = 1;
808 } else if (wwin->wm_hints->initial_state == WithdrawnState) {
810 withdraw = True;
814 if (wwin->wm_hints->flags & WindowGroupHint) {
815 wwin->group_id = wwin->wm_hints->window_group;
816 /* window_group has priority over CLIENT_LEADER */
817 wwin->main_window = wwin->group_id;
818 } else {
819 wwin->group_id = None;
822 if (wwin->wm_hints->flags & UrgencyHint)
823 wwin->flags.urgent = 1;
824 } else {
825 wwin->group_id = None;
828 PropGetProtocols(window, &wwin->protocols);
830 if (!XGetTransientForHint(dpy, window, &wwin->transient_for)) {
831 wwin->transient_for = None;
832 } else {
833 if (wwin->transient_for==None || wwin->transient_for==window) {
834 wwin->transient_for = scr->root_win;
835 } else {
836 transientOwner = wWindowFor(wwin->transient_for);
837 if (transientOwner && transientOwner->main_window!=None) {
838 wwin->main_window = transientOwner->main_window;
839 } /*else {
840 wwin->main_window = None;
845 /* guess the focus mode */
846 wwin->focus_mode = getFocusMode(wwin);
848 /* get geometry stuff */
849 wClientGetNormalHints(wwin, &wattribs, True, &x, &y, &width, &height);
851 /* printf("wManageWindow: %d %d %d %d\n", x, y, width, height);*/
853 /* get colormap windows */
854 GetColormapWindows(wwin);
857 *--------------------------------------------------
859 * Setup the decoration/window attributes and
860 * geometry
862 *--------------------------------------------------
865 wWindowSetupInitialAttributes(wwin, &window_level, &workspace);
867 /* Make broken apps behave as a nice app. */
868 if (WFLAGP(wwin, emulate_appicon)) {
869 wwin->main_window = wwin->client_win;
872 fixLeaderProperties(wwin);
874 wwin->orig_main_window = wwin->main_window;
876 if (wwin->flags.is_gnustep) {
877 WSETUFLAG(wwin, shared_appicon, 0);
880 if (wwin->main_window) {
881 extern Atom _XA_WINDOWMAKER_MENU;
882 XTextProperty text_prop;
884 if (XGetTextProperty(dpy, wwin->main_window, &text_prop,
885 _XA_WINDOWMAKER_MENU)) {
886 WSETUFLAG(wwin, shared_appicon, 0);
890 if (!withdraw && wwin->main_window && WFLAGP(wwin, shared_appicon)) {
891 char *buffer, *instance, *class;
892 WFakeGroupLeader *fPtr;
893 int index;
895 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
897 // only enter here if PropGetWMClass() succeds
898 PropGetWMClass(wwin->main_window, &class, &instance);
899 buffer = StrConcatDot(instance, class);
901 index = WMFindInArray(scr->fakeGroupLeaders, matchIdentifier, (void*)buffer);
902 if (index != WANotFound) {
903 fPtr = WMGetFromArray(scr->fakeGroupLeaders, index);
904 if (fPtr->retainCount == 0) {
905 fPtr->leader = createFakeWindowGroupLeader(scr, wwin->main_window,
906 instance, class);
908 fPtr->retainCount++;
909 #undef method2
910 if (fPtr->origLeader==None) {
911 #ifdef method2
912 if (ADEQUATE(wwin->group_id)) {
913 fPtr->retainCount++;
914 fPtr->origLeader = wwin->group_id;
915 } else if (ADEQUATE(wwin->client_leader)) {
916 fPtr->retainCount++;
917 fPtr->origLeader = wwin->client_leader;
918 } else if (ADEQUATE(wwin->main_window)) {
919 fPtr->retainCount++;
920 fPtr->origLeader = wwin->main_window;
922 #else
923 if (ADEQUATE(wwin->main_window)) {
924 fPtr->retainCount++;
925 fPtr->origLeader = wwin->main_window;
927 #endif
929 wwin->fake_group = fPtr;
930 /*wwin->group_id = fPtr->leader;*/
931 wwin->main_window = fPtr->leader;
932 wfree(buffer);
933 } else {
934 fPtr = (WFakeGroupLeader*)wmalloc(sizeof(WFakeGroupLeader));
936 fPtr->identifier = buffer;
937 fPtr->leader = createFakeWindowGroupLeader(scr, wwin->main_window,
938 instance, class);
939 fPtr->origLeader = None;
940 fPtr->retainCount = 1;
942 WMAddToArray(scr->fakeGroupLeaders, fPtr);
944 #ifdef method2
945 if (ADEQUATE(wwin->group_id)) {
946 fPtr->retainCount++;
947 fPtr->origLeader = wwin->group_id;
948 } else if (ADEQUATE(wwin->client_leader)) {
949 fPtr->retainCount++;
950 fPtr->origLeader = wwin->client_leader;
951 } else if (ADEQUATE(wwin->main_window)) {
952 fPtr->retainCount++;
953 fPtr->origLeader = wwin->main_window;
955 #else
956 if (ADEQUATE(wwin->main_window)) {
957 fPtr->retainCount++;
958 fPtr->origLeader = wwin->main_window;
960 #endif
961 wwin->fake_group = fPtr;
962 /*wwin->group_id = fPtr->leader;*/
963 wwin->main_window = fPtr->leader;
965 if (instance)
966 XFree(instance);
967 if (class)
968 XFree(class);
970 #undef method2
971 #undef ADEQUATE
975 *------------------------------------------------------------
977 * Setup the initial state of the window
979 *------------------------------------------------------------
982 if (WFLAGP(wwin, start_miniaturized) && !WFLAGP(wwin, no_miniaturizable)) {
983 wwin->flags.miniaturized = 1;
986 if (WFLAGP(wwin, start_maximized) && IS_RESIZABLE(wwin)) {
987 wwin->flags.maximized = MAX_VERTICAL|MAX_HORIZONTAL;
990 #ifdef NETWM_HINTS
991 wNETWMCheckInitialClientState(wwin);
992 #endif
994 /* apply previous state if it exists and we're in startup */
995 if (scr->flags.startup && wm_state >= 0) {
997 if (wm_state == IconicState) {
999 wwin->flags.miniaturized = 1;
1001 } else if (wm_state == WithdrawnState) {
1003 withdraw = True;
1007 /* if there is a saved state (from file), restore it */
1008 win_state = NULL;
1009 if (wwin->main_window!=None/* && wwin->main_window!=window*/) {
1010 win_state = (WWindowState*)wWindowGetSavedState(wwin->main_window);
1011 } else {
1012 win_state = (WWindowState*)wWindowGetSavedState(window);
1014 if (win_state && !withdraw) {
1016 if (win_state->state->hidden>0)
1017 wwin->flags.hidden = win_state->state->hidden;
1019 if (win_state->state->shaded>0 && !WFLAGP(wwin, no_shadeable))
1020 wwin->flags.shaded = win_state->state->shaded;
1022 if (win_state->state->miniaturized>0 &&
1023 !WFLAGP(wwin, no_miniaturizable)) {
1024 wwin->flags.miniaturized = win_state->state->miniaturized;
1027 if (!IS_OMNIPRESENT(wwin)) {
1028 int w = wDefaultGetStartWorkspace(scr, wwin->wm_instance,
1029 wwin->wm_class);
1030 if (w < 0 || w >= scr->workspace_count) {
1031 workspace = win_state->state->workspace;
1032 if (workspace >= scr->workspace_count)
1033 workspace = scr->current_workspace;
1034 } else {
1035 workspace = w;
1037 } else {
1038 workspace = scr->current_workspace;
1042 /* if we're restarting, restore saved state (from hints).
1043 * This will overwrite previous */
1045 WSavedState *wstate;
1047 if (getSavedState(window, &wstate)) {
1048 wwin->flags.shaded = wstate->shaded;
1049 wwin->flags.hidden = wstate->hidden;
1050 wwin->flags.miniaturized = wstate->miniaturized;
1051 wwin->flags.maximized = wstate->maximized;
1052 if (wwin->flags.maximized) {
1053 wwin->old_geometry.x = wstate->x;
1054 wwin->old_geometry.y = wstate->y;
1055 wwin->old_geometry.width = wstate->w;
1056 wwin->old_geometry.height = wstate->h;
1059 workspace = wstate->workspace;
1060 } else {
1061 wstate = NULL;
1064 /* restore window shortcut */
1065 if (wstate != NULL || win_state != NULL) {
1066 unsigned mask = 0;
1068 if (win_state != NULL)
1069 mask = win_state->state->window_shortcuts;
1071 if (wstate != NULL && mask == 0)
1072 mask = wstate->window_shortcuts;
1074 if (mask > 0) {
1075 int i;
1077 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
1078 if (mask & (1<<i)) {
1079 if (!scr->shortcutWindows[i])
1080 scr->shortcutWindows[i] = WMCreateArray(4);
1082 WMAddToArray(scr->shortcutWindows[i], wwin);
1087 if (wstate != NULL) {
1088 wfree(wstate);
1092 /* don't let transients start miniaturized if their owners are not */
1093 if (transientOwner && !transientOwner->flags.miniaturized
1094 && wwin->flags.miniaturized && !withdraw) {
1095 wwin->flags.miniaturized = 0;
1096 if (wwin->wm_hints)
1097 wwin->wm_hints->initial_state = NormalState;
1100 /* set workspace on which the window starts */
1101 if (workspace >= 0) {
1102 if (workspace > scr->workspace_count-1) {
1103 workspace = workspace % scr->workspace_count;
1105 } else {
1106 int w;
1108 w = wDefaultGetStartWorkspace(scr, wwin->wm_instance, wwin->wm_class);
1110 if (w >= 0 && w < scr->workspace_count && !(IS_OMNIPRESENT(wwin))) {
1112 workspace = w;
1114 } else {
1115 if (wPreferences.open_transients_with_parent && transientOwner) {
1117 workspace = transientOwner->frame->workspace;
1119 } else {
1121 workspace = scr->current_workspace;
1126 /* setup window geometry */
1127 if (win_state && win_state->state->w > 0) {
1128 width = win_state->state->w;
1129 height = win_state->state->h;
1131 wWindowConstrainSize(wwin, &width, &height);
1133 /* do not ask for window placement if the window is
1134 * transient, during startup, if the initial workspace is another one
1135 * or if the window wants to start iconic.
1136 * If geometry was saved, restore it. */
1138 Bool dontBring = False;
1140 if (win_state && win_state->state->w > 0) {
1141 x = win_state->state->x;
1142 y = win_state->state->y;
1143 } else if ((wwin->transient_for==None
1144 || wPreferences.window_placement!=WPM_MANUAL)
1145 && !scr->flags.startup
1146 && workspace == scr->current_workspace
1147 && !wwin->flags.miniaturized
1148 && !wwin->flags.maximized
1149 && !(wwin->normal_hints->flags & (USPosition|PPosition))) {
1151 if (transientOwner && transientOwner->flags.mapped) {
1152 int offs = WMAX(20, 2*transientOwner->frame->top_width);
1153 WMRect rect;
1154 int head;
1156 x = transientOwner->frame_x +
1157 abs((transientOwner->frame->core->width - width)/2) + offs;
1158 y = transientOwner->frame_y +
1159 abs((transientOwner->frame->core->height - height)/3) + offs;
1162 * limit transient windows to be inside their parent's head
1164 rect.pos.x = transientOwner->frame_x;
1165 rect.pos.y = transientOwner->frame_y;
1166 rect.size.width = transientOwner->frame->core->width;
1167 rect.size.height = transientOwner->frame->core->height;
1169 head = wGetHeadForRect(scr, rect);
1170 rect = wGetRectForHead(scr, head);
1172 if (x < rect.pos.x)
1173 x = rect.pos.x;
1174 else if (x + width > rect.pos.x + rect.size.width)
1175 x = rect.pos.x + rect.size.width - width;
1177 if (y < rect.pos.y)
1178 y = rect.pos.y;
1179 else if (y + height > rect.pos.y + rect.size.height)
1180 y = rect.pos.y + rect.size.height - height;
1182 } else {
1183 PlaceWindow(wwin, &x, &y, width, height);
1185 if (wPreferences.window_placement == WPM_MANUAL) {
1186 dontBring = True;
1188 } else if (scr->xine_info.count &&
1189 (wwin->normal_hints->flags & PPosition)) {
1190 int head, flags;
1191 WMRect rect;
1192 int reposition = 0;
1195 * Make spash screens come out in the center of a head
1196 * trouble is that most splashies never get here
1197 * they are managed trough atoms but god knows where.
1198 * Dan, do you know ? -peter
1200 * Most of them are not managed, they have set
1201 * OverrideRedirect, which means we can't do anything about
1202 * them. -alfredo
1204 #if 0
1205 printf("xinerama PPosition: x: %d %d\n", x, (scr->scr_width - width)/2);
1206 printf("xinerama PPosition: y: %d %d\n", y, (scr->scr_height - height)/2);
1208 if ((unsigned)(x + (width - scr->scr_width)/2 + 10) < 20 &&
1209 (unsigned)(y + (height - scr->scr_height)/2 + 10) < 20) {
1211 reposition = 1;
1213 } else
1214 #endif
1217 * xinerama checks for: across head and dead space
1219 rect.pos.x = x;
1220 rect.pos.y = y;
1221 rect.size.width = width;
1222 rect.size.height = height;
1224 head = wGetRectPlacementInfo(scr, rect, &flags);
1226 if (flags & XFLAG_DEAD)
1227 reposition = 1;
1229 if (flags & XFLAG_MULTIPLE)
1230 reposition = 2;
1233 switch (reposition) {
1234 case 1:
1235 head = wGetHeadForPointerLocation(scr);
1236 rect = wGetRectForHead(scr, head);
1238 x = rect.pos.x + (x * rect.size.width)/scr->scr_width;
1239 y = rect.pos.y + (y * rect.size.height)/scr->scr_height;
1240 break;
1242 case 2:
1243 rect = wGetRectForHead(scr, head);
1245 if (x < rect.pos.x)
1246 x = rect.pos.x;
1247 else if (x + width > rect.pos.x + rect.size.width)
1248 x = rect.pos.x + rect.size.width - width;
1250 if (y < rect.pos.y)
1251 y = rect.pos.y;
1252 else if (y + height > rect.pos.y + rect.size.height)
1253 y = rect.pos.y + rect.size.height - height;
1255 break;
1257 default:
1258 break;
1262 if (WFLAGP(wwin, dont_move_off) && dontBring)
1263 wScreenBringInside(scr, &x, &y, width, height);
1266 #ifdef NETWM_HINTS
1267 wNETWMPositionSplash(wwin, &x, &y, width, height);
1268 #endif
1270 if (wwin->flags.urgent) {
1271 if (!IS_OMNIPRESENT(wwin))
1272 wwin->flags.omnipresent ^= 1;
1276 *--------------------------------------------------
1278 * Create frame, borders and do reparenting
1280 *--------------------------------------------------
1282 foo = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
1283 #ifdef XKB_BUTTON_HINT
1284 if (wPreferences.modelock)
1285 foo |= WFF_LANGUAGE_BUTTON;
1286 #endif
1287 if (HAS_TITLEBAR(wwin))
1288 foo |= WFF_TITLEBAR;
1289 if (HAS_RESIZEBAR(wwin))
1290 foo |= WFF_RESIZEBAR;
1291 if (HAS_BORDER(wwin))
1292 foo |= WFF_BORDER;
1294 wwin->frame = wFrameWindowCreate(scr, window_level,
1295 x, y, width, height,
1296 &wPreferences.window_title_clearance, foo,
1297 scr->window_title_texture,
1298 scr->resizebar_texture,
1299 scr->window_title_color,
1300 &scr->title_font);
1302 wwin->frame->flags.is_client_window_frame = 1;
1303 wwin->frame->flags.justification = wPreferences.title_justification;
1305 /* setup button images */
1306 wWindowUpdateButtonImages(wwin);
1308 /* hide unused buttons */
1309 foo = 0;
1310 if (WFLAGP(wwin, no_close_button))
1311 foo |= WFF_RIGHT_BUTTON;
1312 if (WFLAGP(wwin, no_miniaturize_button))
1313 foo |= WFF_LEFT_BUTTON;
1314 #ifdef XKB_BUTTON_HINT
1315 if (WFLAGP(wwin, no_language_button) || WFLAGP(wwin, no_focusable))
1316 foo |= WFF_LANGUAGE_BUTTON;
1317 #endif
1318 if (foo!=0)
1319 wFrameWindowHideButton(wwin->frame, foo);
1321 wwin->frame->child = wwin;
1323 wwin->frame->workspace = workspace;
1325 wwin->frame->on_click_left = windowIconifyClick;
1326 #ifdef XKB_BUTTON_HINT
1327 if (wPreferences.modelock)
1328 wwin->frame->on_click_language = windowLanguageClick;
1329 #endif
1331 wwin->frame->on_click_right = windowCloseClick;
1332 wwin->frame->on_dblclick_right = windowCloseDblClick;
1334 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1335 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1337 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1340 XSelectInput(dpy, wwin->client_win,
1341 wwin->event_mask & ~StructureNotifyMask);
1343 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1344 0, wwin->frame->top_width);
1346 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1350 int gx, gy;
1352 wClientGetGravityOffsets(wwin, &gx, &gy);
1354 /* if gravity is to the south, account for the border sizes */
1355 if (gy > 0)
1356 y -= wwin->frame->top_width + wwin->frame->bottom_width;
1360 * wWindowConfigure() will init the client window's size
1361 * (wwin->client.{width,height}) and all other geometry
1362 * related variables (frame_x,frame_y)
1364 wWindowConfigure(wwin, x, y, width, height);
1366 /* to make sure the window receives it's new position after reparenting */
1367 wWindowSynthConfigureNotify(wwin);
1370 *--------------------------------------------------
1372 * Setup descriptors and save window to internal
1373 * lists
1375 *--------------------------------------------------
1378 if (wwin->main_window!=None) {
1379 WApplication *app;
1380 WWindow *leader;
1382 /* Leader windows do not necessary set themselves as leaders.
1383 * If this is the case, point the leader of this window to
1384 * itself */
1385 leader = wWindowFor(wwin->main_window);
1386 if (leader && leader->main_window==None) {
1387 leader->main_window = leader->client_win;
1389 app = wApplicationCreate(wwin);
1390 if (app) {
1391 app->last_workspace = workspace;
1394 * Do application specific stuff, like setting application
1395 * wide attributes.
1398 if (wwin->flags.hidden) {
1399 /* if the window was set to hidden because it was hidden
1400 * in a previous incarnation and that state was restored */
1401 app->flags.hidden = 1;
1402 } else if (app->flags.hidden) {
1403 if (WFLAGP(app->main_window_desc, start_hidden)) {
1404 wwin->flags.hidden = 1;
1405 } else {
1406 wUnhideApplication(app, False, False);
1407 raise = True;
1413 /* setup the frame descriptor */
1414 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1415 wwin->frame->core->descriptor.parent = wwin;
1416 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1418 /* don't let windows go away if we die */
1419 XAddToSaveSet(dpy, window);
1421 XLowerWindow(dpy, window);
1423 /* if window is in this workspace and should be mapped, then map it */
1424 if (!wwin->flags.miniaturized
1425 && (workspace == scr->current_workspace || IS_OMNIPRESENT(wwin))
1426 && !wwin->flags.hidden && !withdraw) {
1428 /* The following "if" is to avoid crashing of clients that expect
1429 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1430 * after the return from this function.
1432 if (wwin->wm_hints && (wwin->wm_hints->flags & StateHint)) {
1433 wClientSetState(wwin, wwin->wm_hints->initial_state, None);
1434 } else {
1435 wClientSetState(wwin, NormalState, None);
1438 #if 0
1439 /* if not auto focus, then map the window under the currently
1440 * focused window */
1441 #define _WIDTH(w) (w)->frame->core->width
1442 #define _HEIGHT(w) (w)->frame->core->height
1443 if (!wPreferences.auto_focus && scr->focused_window
1444 && !scr->flags.startup && !transientOwner
1445 && ((wWindowObscuresWindow(wwin, scr->focused_window)
1446 && (_WIDTH(wwin) > (_WIDTH(scr->focused_window)*5)/3
1447 || _HEIGHT(wwin) > (_HEIGHT(scr->focused_window)*5)/3)
1448 && WINDOW_LEVEL(scr->focused_window) == WINDOW_LEVEL(wwin))
1449 || wwin->flags.maximized)) {
1450 MoveInStackListUnder(scr->focused_window->frame->core,
1451 wwin->frame->core);
1453 #undef _WIDTH
1454 #undef _HEIGHT
1456 #endif
1458 if (wPreferences.superfluous && !wPreferences.no_animations
1459 && !scr->flags.startup &&
1460 (wwin->transient_for==None || wwin->transient_for==scr->root_win)
1462 * The brain damaged idiotic non-click to focus modes will
1463 * have trouble with this because:
1465 * 1. window is created and mapped by the client
1466 * 2. window is mapped by wmaker in small size
1467 * 3. window is animated to grow to normal size
1468 * 4. this function returns to normal event loop
1469 * 5. eventually, the EnterNotify event that would trigger
1470 * the window focusing (if the mouse is over that window)
1471 * will be processed by wmaker.
1472 * But since this event will be rather delayed
1473 * (step 3 has a large delay) the time when the event ocurred
1474 * and when it is processed, the client that owns that window
1475 * will reject the XSetInputFocus() for it.
1477 && (wPreferences.focus_mode==WKF_CLICK
1478 || wPreferences.auto_focus)) {
1479 DoWindowBirth(wwin);
1482 wWindowMap(wwin);
1485 /* setup stacking descriptor */
1486 if (transientOwner) {
1487 wwin->frame->core->stacking->child_of = transientOwner->frame->core;
1488 } else {
1489 wwin->frame->core->stacking->child_of = NULL;
1493 if (!scr->focused_window) {
1494 /* first window on the list */
1495 wwin->next = NULL;
1496 wwin->prev = NULL;
1497 scr->focused_window = wwin;
1498 } else {
1499 WWindow *tmp;
1501 /* add window at beginning of focus window list */
1502 tmp = scr->focused_window;
1503 while (tmp->prev)
1504 tmp = tmp->prev;
1505 tmp->prev = wwin;
1506 wwin->next = tmp;
1507 wwin->prev = NULL;
1510 /* raise is set to true if we un-hid the app when this window was born.
1511 * we raise, else old windows of this app will be above this new one. */
1512 if (raise) {
1513 wRaiseFrame(wwin->frame->core);
1516 /* Update name must come after WApplication stuff is done */
1517 wWindowUpdateName(wwin, title);
1518 if (title)
1519 XFree(title);
1521 XUngrabServer(dpy);
1524 *--------------------------------------------------
1526 * Final preparations before window is ready to go
1528 *--------------------------------------------------
1531 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1534 if (!wwin->flags.miniaturized && workspace == scr->current_workspace
1535 && !wwin->flags.hidden) {
1536 if (((transientOwner && transientOwner->flags.focused)
1537 || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable))
1538 wSetFocusTo(scr, wwin);
1540 wWindowResetMouseGrabs(wwin);
1542 if (!WFLAGP(wwin, no_bind_keys)) {
1543 wWindowSetKeyGrabs(wwin);
1547 WMPostNotificationName(WMNManaged, wwin, NULL);
1550 wColormapInstallForWindow(scr, scr->cmap_window);
1554 *------------------------------------------------------------
1555 * Setup Notification Observers
1556 *------------------------------------------------------------
1558 WMAddNotificationObserver(appearanceObserver, wwin,
1559 WNWindowAppearanceSettingsChanged, wwin);
1563 *--------------------------------------------------
1565 * Cleanup temporary stuff
1567 *--------------------------------------------------
1570 if (win_state)
1571 wWindowDeleteSavedState(win_state);
1573 /* If the window must be withdrawed, then do it now.
1574 * Must do some optimization, 'though */
1575 if (withdraw) {
1576 wwin->flags.mapped = 0;
1577 wClientSetState(wwin, WithdrawnState, None);
1578 wUnmanageWindow(wwin, True, False);
1579 wwin = NULL;
1582 return wwin;
1589 WWindow*
1590 wManageInternalWindow(WScreen *scr, Window window, Window owner,
1591 char *title, int x, int y, int width, int height)
1593 WWindow *wwin;
1594 int foo;
1596 wwin = wWindowCreate();
1598 WMAddNotificationObserver(appearanceObserver, wwin,
1599 WNWindowAppearanceSettingsChanged, wwin);
1601 wwin->flags.internal_window = 1;
1603 WSETUFLAG(wwin, omnipresent, 1);
1604 WSETUFLAG(wwin, no_shadeable, 1);
1605 WSETUFLAG(wwin, no_resizable, 1);
1606 WSETUFLAG(wwin, no_miniaturizable, 1);
1608 wwin->focus_mode = WFM_PASSIVE;
1610 wwin->client_win = window;
1611 wwin->screen_ptr = scr;
1613 wwin->transient_for = owner;
1615 wwin->client.x = x;
1616 wwin->client.y = y;
1617 wwin->client.width = width;
1618 wwin->client.height = height;
1620 wwin->frame_x = wwin->client.x;
1621 wwin->frame_y = wwin->client.y;
1624 foo = WFF_RIGHT_BUTTON|WFF_BORDER;
1625 foo |= WFF_TITLEBAR;
1626 #ifdef XKB_BUTTON_HINT
1627 foo |= WFF_LANGUAGE_BUTTON;
1628 #endif
1630 wwin->frame = wFrameWindowCreate(scr, WMFloatingLevel,
1631 wwin->frame_x, wwin->frame_y,
1632 width, height,
1633 &wPreferences.window_title_clearance, foo,
1634 scr->window_title_texture,
1635 scr->resizebar_texture,
1636 scr->window_title_color,
1637 &scr->title_font);
1639 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
1641 wwin->frame->flags.is_client_window_frame = 1;
1642 wwin->frame->flags.justification = wPreferences.title_justification;
1644 wFrameWindowChangeTitle(wwin->frame, title);
1646 /* setup button images */
1647 wWindowUpdateButtonImages(wwin);
1649 /* hide buttons */
1650 wFrameWindowHideButton(wwin->frame, WFF_RIGHT_BUTTON);
1652 wwin->frame->child = wwin;
1654 wwin->frame->workspace = wwin->screen_ptr->current_workspace;
1656 #ifdef XKB_BUTTON_HINT
1657 if (wPreferences.modelock)
1658 wwin->frame->on_click_language = windowLanguageClick;
1659 #endif
1661 wwin->frame->on_click_right = windowCloseClick;
1663 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1664 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1666 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1668 wwin->client.y += wwin->frame->top_width;
1669 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1670 0, wwin->frame->top_width);
1672 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y,
1673 wwin->client.width, wwin->client.height);
1675 /* setup the frame descriptor */
1676 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1677 wwin->frame->core->descriptor.parent = wwin;
1678 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1681 XLowerWindow(dpy, window);
1682 XMapSubwindows(dpy, wwin->frame->core->window);
1684 /* setup stacking descriptor */
1685 if (wwin->transient_for!=None && wwin->transient_for!=scr->root_win) {
1686 WWindow *tmp;
1687 tmp = wWindowFor(wwin->transient_for);
1688 if (tmp)
1689 wwin->frame->core->stacking->child_of = tmp->frame->core;
1690 } else {
1691 wwin->frame->core->stacking->child_of = NULL;
1695 if (!scr->focused_window) {
1696 /* first window on the list */
1697 wwin->next = NULL;
1698 wwin->prev = NULL;
1699 scr->focused_window = wwin;
1700 } else {
1701 WWindow *tmp;
1703 /* add window at beginning of focus window list */
1704 tmp = scr->focused_window;
1705 while (tmp->prev)
1706 tmp = tmp->prev;
1707 tmp->prev = wwin;
1708 wwin->next = tmp;
1709 wwin->prev = NULL;
1712 if (wwin->flags.is_gnustep == 0)
1713 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1715 /* if (wPreferences.auto_focus)*/
1716 wSetFocusTo(scr, wwin);
1718 wWindowResetMouseGrabs(wwin);
1720 wWindowSetKeyGrabs(wwin);
1722 return wwin;
1727 *----------------------------------------------------------------------
1728 * wUnmanageWindow--
1729 * Removes the frame window from a window and destroys all data
1730 * related to it. The window will be reparented back to the root window
1731 * if restore is True.
1733 * Side effects:
1734 * Everything related to the window is destroyed and the window
1735 * is removed from the window lists. Focus is set to the previous on the
1736 * window list.
1737 *----------------------------------------------------------------------
1739 void
1740 wUnmanageWindow(WWindow *wwin, Bool restore, Bool destroyed)
1742 WCoreWindow *frame = wwin->frame->core;
1743 WWindow *owner = NULL;
1744 WWindow *newFocusedWindow = NULL;
1745 int wasFocused;
1746 WScreen *scr = wwin->screen_ptr;
1749 /* First close attribute editor window if open */
1750 if (wwin->flags.inspector_open) {
1751 wCloseInspectorForWindow(wwin);
1754 /* Close window menu if it's open for this window */
1755 if (wwin->flags.menu_open_for_me) {
1756 CloseWindowMenu(scr);
1759 if (!destroyed) {
1760 if (!wwin->flags.internal_window)
1761 XRemoveFromSaveSet(dpy, wwin->client_win);
1763 XSelectInput(dpy, wwin->client_win, NoEventMask);
1765 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
1766 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->client_win);
1769 XUnmapWindow(dpy, frame->window);
1771 XUnmapWindow(dpy, wwin->client_win);
1773 /* deselect window */
1774 wSelectWindow(wwin, False);
1776 /* remove all pending events on window */
1777 /* I think this only matters for autoraise */
1778 if (wPreferences.raise_delay)
1779 WMDeleteTimerWithClientData(wwin->frame->core);
1781 XFlush(dpy);
1783 /* reparent the window back to the root */
1784 if (restore)
1785 wClientRestore(wwin);
1787 if (wwin->transient_for!=scr->root_win) {
1788 owner = wWindowFor(wwin->transient_for);
1789 if (owner) {
1790 if (!owner->flags.semi_focused) {
1791 owner = NULL;
1792 } else {
1793 owner->flags.semi_focused = 0;
1798 wasFocused = wwin->flags.focused;
1800 /* remove from window focus list */
1801 if (!wwin->prev && !wwin->next) {
1802 /* was the only window */
1803 scr->focused_window = NULL;
1804 newFocusedWindow = NULL;
1805 } else {
1806 WWindow *tmp;
1808 if (wwin->prev)
1809 wwin->prev->next = wwin->next;
1810 if (wwin->next)
1811 wwin->next->prev = wwin->prev;
1812 else {
1813 scr->focused_window = wwin->prev;
1814 scr->focused_window->next = NULL;
1817 if (wPreferences.focus_mode==WKF_CLICK) {
1819 /* if in click to focus mode and the window
1820 * was a transient, focus the owner window
1822 tmp = NULL;
1823 if (wPreferences.focus_mode==WKF_CLICK) {
1824 tmp = wWindowFor(wwin->transient_for);
1825 if (tmp && (!tmp->flags.mapped || WFLAGP(tmp, no_focusable))) {
1826 tmp = NULL;
1829 /* otherwise, focus the next one in the focus list */
1830 if (!tmp) {
1831 tmp = scr->focused_window;
1832 while (tmp) { /* look for one in the window list first */
1833 if (!WFLAGP(tmp, no_focusable) && !WFLAGP(tmp, skip_window_list)
1834 && (tmp->flags.mapped || tmp->flags.shaded))
1835 break;
1836 tmp = tmp->prev;
1838 if (!tmp) { /* if unsuccessful, choose any focusable window */
1839 tmp = scr->focused_window;
1840 while (tmp) {
1841 if (!WFLAGP(tmp, no_focusable)
1842 && (tmp->flags.mapped || tmp->flags.shaded))
1843 break;
1844 tmp = tmp->prev;
1849 newFocusedWindow = tmp;
1851 } else if (wPreferences.focus_mode==WKF_SLOPPY) {
1852 unsigned int mask;
1853 int foo;
1854 Window bar, win;
1856 /* This is to let the root window get the keyboard input
1857 * if Sloppy focus mode and no other window get focus.
1858 * This way keybindings will not freeze.
1860 tmp = NULL;
1861 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
1862 &foo, &foo, &foo, &foo, &mask))
1863 tmp = wWindowFor(win);
1864 if (tmp == wwin)
1865 tmp = NULL;
1866 newFocusedWindow = tmp;
1867 } else {
1868 newFocusedWindow = NULL;
1872 if (!wwin->flags.internal_window) {
1873 WMPostNotificationName(WMNUnmanaged, wwin, NULL);
1876 #ifdef DEBUG
1877 printf("destroying window %x frame %x\n", (unsigned)wwin->client_win,
1878 (unsigned)frame->window);
1879 #endif
1881 if (wasFocused) {
1882 if (newFocusedWindow != owner && owner) {
1883 if (wwin->flags.is_gnustep == 0)
1884 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1886 wSetFocusTo(scr, newFocusedWindow);
1888 wWindowDestroy(wwin);
1889 XFlush(dpy);
1893 void
1894 wWindowMap(WWindow *wwin)
1896 XMapWindow(dpy, wwin->frame->core->window);
1897 if (!wwin->flags.shaded) {
1898 /* window will be remapped when getting MapNotify */
1899 XSelectInput(dpy, wwin->client_win,
1900 wwin->event_mask & ~StructureNotifyMask);
1901 XMapWindow(dpy, wwin->client_win);
1902 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1904 wwin->flags.mapped = 1;
1909 void
1910 wWindowUnmap(WWindow *wwin)
1912 wwin->flags.mapped = 0;
1914 /* prevent window withdrawal when getting UnmapNotify */
1915 XSelectInput(dpy, wwin->client_win,
1916 wwin->event_mask & ~StructureNotifyMask);
1917 XUnmapWindow(dpy, wwin->client_win);
1918 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1920 XUnmapWindow(dpy, wwin->frame->core->window);
1925 void
1926 wWindowFocus(WWindow *wwin, WWindow *owin)
1928 WWindow *nowner;
1929 WWindow *oowner;
1931 #ifdef KEEP_XKB_LOCK_STATUS
1932 if (wPreferences.modelock) {
1933 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1935 #endif /* KEEP_XKB_LOCK_STATUS */
1937 wwin->flags.semi_focused = 0;
1939 if (wwin->flags.is_gnustep == 0)
1940 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1942 wwin->flags.focused = 1;
1944 wWindowResetMouseGrabs(wwin);
1946 WMPostNotificationName(WMNChangedFocus, wwin, (void*)True);
1948 if (owin == wwin || !owin)
1949 return;
1951 nowner = wWindowFor(wwin->transient_for);
1953 /* new window is a transient for the old window */
1954 if (nowner == owin) {
1955 owin->flags.semi_focused = 1;
1956 wWindowUnfocus(nowner);
1957 return;
1960 oowner = wWindowFor(owin->transient_for);
1962 /* new window is owner of old window */
1963 if (wwin == oowner) {
1964 wWindowUnfocus(owin);
1965 return;
1968 if (!nowner) {
1969 wWindowUnfocus(owin);
1970 return;
1973 /* new window has same owner of old window */
1974 if (oowner == nowner) {
1975 /* prevent unfocusing of owner */
1976 oowner->flags.semi_focused = 0;
1977 wWindowUnfocus(owin);
1978 oowner->flags.semi_focused = 1;
1980 return;
1983 /* nowner != NULL && oowner != nowner */
1984 nowner->flags.semi_focused = 1;
1985 wWindowUnfocus(nowner);
1986 wWindowUnfocus(owin);
1990 void
1991 wWindowUnfocus(WWindow *wwin)
1993 CloseWindowMenu(wwin->screen_ptr);
1995 if (wwin->flags.is_gnustep == 0)
1996 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused
1997 ? WS_PFOCUSED : WS_UNFOCUSED);
1999 if (wwin->transient_for!=None
2000 && wwin->transient_for!=wwin->screen_ptr->root_win) {
2001 WWindow *owner;
2002 owner = wWindowFor(wwin->transient_for);
2003 if (owner && owner->flags.semi_focused) {
2004 owner->flags.semi_focused = 0;
2005 if (owner->flags.mapped || owner->flags.shaded) {
2006 wWindowUnfocus(owner);
2007 wFrameWindowPaint(owner->frame);
2011 wwin->flags.focused = 0;
2013 wWindowResetMouseGrabs(wwin);
2015 WMPostNotificationName(WMNChangedFocus, wwin, (void*)False);
2019 void
2020 wWindowUpdateName(WWindow *wwin, char *newTitle)
2022 char *title;
2024 if (!wwin->frame)
2025 return;
2027 wwin->flags.wm_name_changed = 1;
2029 if (!newTitle) {
2030 /* the hint was removed */
2031 title = DEF_WINDOW_TITLE;
2032 } else {
2033 title = newTitle;
2036 if (wFrameWindowChangeTitle(wwin->frame, title)) {
2037 WMPostNotificationName(WMNChangedName, wwin, NULL);
2044 *----------------------------------------------------------------------
2046 * wWindowConstrainSize--
2047 * Constrains size for the client window, taking the maximal size,
2048 * window resize increments and other size hints into account.
2050 * Returns:
2051 * The closest size to what was given that the client window can
2052 * have.
2054 *----------------------------------------------------------------------
2056 void
2057 wWindowConstrainSize(WWindow *wwin, int *nwidth, int *nheight)
2059 int width = *nwidth;
2060 int height = *nheight;
2061 int winc = 1;
2062 int hinc = 1;
2063 int minW = 1, minH = 1;
2064 int maxW = wwin->screen_ptr->scr_width*2;
2065 int maxH = wwin->screen_ptr->scr_height*2;
2066 int minAX = -1, minAY = -1;
2067 int maxAX = -1, maxAY = -1;
2068 int baseW = 0;
2069 int baseH = 0;
2071 if (wwin->normal_hints) {
2072 winc = wwin->normal_hints->width_inc;
2073 hinc = wwin->normal_hints->height_inc;
2074 minW = wwin->normal_hints->min_width;
2075 minH = wwin->normal_hints->min_height;
2076 maxW = wwin->normal_hints->max_width;
2077 maxH = wwin->normal_hints->max_height;
2078 if (wwin->normal_hints->flags & PAspect) {
2079 minAX = wwin->normal_hints->min_aspect.x;
2080 minAY = wwin->normal_hints->min_aspect.y;
2081 maxAX = wwin->normal_hints->max_aspect.x;
2082 maxAY = wwin->normal_hints->max_aspect.y;
2085 baseW = wwin->normal_hints->base_width;
2086 baseH = wwin->normal_hints->base_height;
2089 if (width < minW)
2090 width = minW;
2091 if (height < minH)
2092 height = minH;
2094 if (width > maxW)
2095 width = maxW;
2096 if (height > maxH)
2097 height = maxH;
2099 /* aspect ratio code borrowed from olwm */
2100 if (minAX > 0) {
2101 /* adjust max aspect ratio */
2102 if (!(maxAX == 1 && maxAY == 1) && width * maxAY > height * maxAX) {
2103 if (maxAX > maxAY) {
2104 height = (width * maxAY) / maxAX;
2105 if (height > maxH) {
2106 height = maxH;
2107 width = (height * maxAX) / maxAY;
2109 } else {
2110 width = (height * maxAX) / maxAY;
2111 if (width > maxW) {
2112 width = maxW;
2113 height = (width * maxAY) / maxAX;
2118 /* adjust min aspect ratio */
2119 if (!(minAX == 1 && minAY == 1) && width * minAY < height * minAX) {
2120 if (minAX > minAY) {
2121 height = (width * minAY) / minAX;
2122 if (height < minH) {
2123 height = minH;
2124 width = (height * minAX) / minAY;
2126 } else {
2127 width = (height * minAX) / minAY;
2128 if (width < minW) {
2129 width = minW;
2130 height = (width * minAY) / minAX;
2136 if (baseW != 0) {
2137 width = (((width - baseW) / winc) * winc) + baseW;
2138 } else {
2139 width = (((width - minW) / winc) * winc) + minW;
2142 if (baseH != 0) {
2143 height = (((height - baseH) / hinc) * hinc) + baseH;
2144 } else {
2145 height = (((height - minH) / hinc) * hinc) + minH;
2148 /* broken stupid apps may cause preposterous values for these.. */
2149 if (width > 0)
2150 *nwidth = width;
2151 if (height > 0)
2152 *nheight = height;
2156 void
2157 wWindowCropSize(WWindow *wwin, int maxW, int maxH,
2158 int *width, int *height)
2160 int baseW = 0, baseH = 0;
2161 int winc = 1, hinc = 1;
2163 if (wwin->normal_hints) {
2164 baseW = wwin->normal_hints->base_width;
2165 baseH = wwin->normal_hints->base_height;
2167 winc = wwin->normal_hints->width_inc;
2168 hinc = wwin->normal_hints->height_inc;
2171 if (*width > maxW)
2172 *width = maxW - (maxW - baseW) % winc;
2174 if (*height > maxH)
2175 *height = maxH - (maxH - baseH) % hinc;
2179 void
2180 wWindowChangeWorkspace(WWindow *wwin, int workspace)
2182 WScreen *scr = wwin->screen_ptr;
2183 WApplication *wapp;
2184 int unmap = 0;
2186 if (workspace >= scr->workspace_count || workspace < 0
2187 || workspace == wwin->frame->workspace)
2188 return;
2190 if (workspace != scr->current_workspace) {
2191 /* Sent to other workspace. Unmap window */
2192 if ((wwin->flags.mapped
2193 || wwin->flags.shaded
2194 || (wwin->flags.miniaturized && !wPreferences.sticky_icons))
2195 && !IS_OMNIPRESENT(wwin) && !wwin->flags.changing_workspace) {
2197 wapp = wApplicationOf(wwin->main_window);
2198 if (wapp) {
2199 wapp->last_workspace = workspace;
2201 if (wwin->flags.miniaturized) {
2202 if (wwin->icon) {
2203 XUnmapWindow(dpy, wwin->icon->core->window);
2204 wwin->icon->mapped = 0;
2206 } else {
2207 unmap = 1;
2208 wSetFocusTo(scr, NULL);
2211 } else {
2212 /* brought to current workspace. Map window */
2213 if (wwin->flags.miniaturized && !wPreferences.sticky_icons) {
2214 if (wwin->icon) {
2215 XMapWindow(dpy, wwin->icon->core->window);
2216 wwin->icon->mapped = 1;
2218 } else if (!wwin->flags.mapped &&
2219 !(wwin->flags.miniaturized || wwin->flags.hidden)) {
2220 wWindowMap(wwin);
2223 if (!IS_OMNIPRESENT(wwin)) {
2224 int oldWorkspace = wwin->frame->workspace;
2226 wwin->frame->workspace = workspace;
2228 WMPostNotificationName(WMNChangedWorkspace, wwin, (void*)oldWorkspace);
2231 if (unmap) {
2232 wWindowUnmap(wwin);
2237 void
2238 wWindowSynthConfigureNotify(WWindow *wwin)
2240 XEvent sevent;
2242 sevent.type = ConfigureNotify;
2243 sevent.xconfigure.display = dpy;
2244 sevent.xconfigure.event = wwin->client_win;
2245 sevent.xconfigure.window = wwin->client_win;
2247 sevent.xconfigure.x = wwin->client.x;
2248 sevent.xconfigure.y = wwin->client.y;
2249 sevent.xconfigure.width = wwin->client.width;
2250 sevent.xconfigure.height = wwin->client.height;
2252 sevent.xconfigure.border_width = wwin->old_border_width;
2253 if (!HAS_TITLEBAR(wwin))
2254 sevent.xconfigure.above = None;
2255 else
2256 sevent.xconfigure.above = wwin->frame->titlebar->window;
2258 sevent.xconfigure.override_redirect = False;
2259 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
2260 XFlush(dpy);
2265 *----------------------------------------------------------------------
2266 * wWindowConfigure--
2267 * Configures the frame, decorations and client window to the
2268 * specified geometry. The geometry is not checked for validity,
2269 * wWindowConstrainSize() must be used for that.
2270 * The size parameters are for the client window, but the position is
2271 * for the frame.
2272 * The client window receives a ConfigureNotify event, according
2273 * to what ICCCM says.
2275 * Returns:
2276 * None
2278 * Side effects:
2279 * Window size and position are changed and client window receives
2280 * a ConfigureNotify event.
2281 *----------------------------------------------------------------------
2283 void
2284 wWindowConfigure(wwin, req_x, req_y, req_width, req_height)
2285 WWindow *wwin;
2286 int req_x, req_y; /* new position of the frame */
2287 int req_width, req_height; /* new size of the client */
2289 int synth_notify = False;
2290 int resize;
2292 resize = (req_width!=wwin->client.width
2293 || req_height!=wwin->client.height);
2295 * if the window is being moved but not resized then
2296 * send a synthetic ConfigureNotify
2298 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y) && !resize) {
2299 synth_notify = True;
2302 if (WFLAGP(wwin, dont_move_off))
2303 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2304 req_width, req_height);
2305 if (resize) {
2306 if (req_width < MIN_WINDOW_SIZE)
2307 req_width = MIN_WINDOW_SIZE;
2308 if (req_height < MIN_WINDOW_SIZE)
2309 req_height = MIN_WINDOW_SIZE;
2311 /* If growing, resize inner part before frame,
2312 * if shrinking, resize frame before.
2313 * This will prevent the frame (that can have a different color)
2314 * to be exposed, causing flicker */
2315 if (req_height > wwin->frame->core->height
2316 || req_width > wwin->frame->core->width)
2317 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2319 if (wwin->flags.shaded) {
2320 wFrameWindowConfigure(wwin->frame, req_x, req_y,
2321 req_width, wwin->frame->core->height);
2322 wwin->old_geometry.height = req_height;
2323 } else {
2324 int h;
2326 h = req_height + wwin->frame->top_width
2327 + wwin->frame->bottom_width;
2329 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, h);
2332 if (!(req_height > wwin->frame->core->height
2333 || req_width > wwin->frame->core->width))
2334 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2336 wwin->client.x = req_x;
2337 wwin->client.y = req_y + wwin->frame->top_width;
2338 wwin->client.width = req_width;
2339 wwin->client.height = req_height;
2340 } else {
2341 wwin->client.x = req_x;
2342 wwin->client.y = req_y + wwin->frame->top_width;
2344 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2346 wwin->frame_x = req_x;
2347 wwin->frame_y = req_y;
2348 if (HAS_BORDER(wwin)) {
2349 wwin->client.x += FRAME_BORDER_WIDTH;
2350 wwin->client.y += FRAME_BORDER_WIDTH;
2353 #ifdef SHAPE
2354 if (wShapeSupported && wwin->flags.shaped && resize) {
2355 wWindowSetShape(wwin);
2357 #endif
2359 if (synth_notify)
2360 wWindowSynthConfigureNotify(wwin);
2361 XFlush(dpy);
2365 void
2366 wWindowMove(wwin, req_x, req_y)
2367 WWindow *wwin;
2368 int req_x, req_y; /* new position of the frame */
2370 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2371 int synth_notify = False;
2373 /* Send a synthetic ConfigureNotify event for every window movement. */
2374 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y)) {
2375 synth_notify = True;
2377 #else
2378 /* A single synthetic ConfigureNotify event is sent at the end of
2379 * a completed (opaque) movement in moveres.c */
2380 #endif
2382 if (WFLAGP(wwin, dont_move_off))
2383 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2384 wwin->frame->core->width, wwin->frame->core->height);
2386 wwin->client.x = req_x;
2387 wwin->client.y = req_y + wwin->frame->top_width;
2388 if (HAS_BORDER(wwin)) {
2389 wwin->client.x += FRAME_BORDER_WIDTH;
2390 wwin->client.y += FRAME_BORDER_WIDTH;
2393 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2395 wwin->frame_x = req_x;
2396 wwin->frame_y = req_y;
2398 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2399 if (synth_notify)
2400 wWindowSynthConfigureNotify(wwin);
2401 #endif
2405 void
2406 wWindowUpdateButtonImages(WWindow *wwin)
2408 WScreen *scr = wwin->screen_ptr;
2409 Pixmap pixmap, mask;
2410 WFrameWindow *fwin = wwin->frame;
2412 if (!HAS_TITLEBAR(wwin))
2413 return;
2415 /* miniaturize button */
2417 if (!WFLAGP(wwin, no_miniaturize_button)) {
2418 if (wwin->wm_gnustep_attr
2419 && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
2420 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
2422 if (wwin->wm_gnustep_attr->flags&GSMiniaturizeMaskAttr) {
2423 mask = wwin->wm_gnustep_attr->miniaturize_mask;
2424 } else {
2425 mask = None;
2428 if (fwin->lbutton_image
2429 && (fwin->lbutton_image->image != pixmap
2430 || fwin->lbutton_image->mask != mask)) {
2431 wPixmapDestroy(fwin->lbutton_image);
2432 fwin->lbutton_image = NULL;
2435 if (!fwin->lbutton_image) {
2436 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
2437 fwin->lbutton_image->client_owned = 1;
2438 fwin->lbutton_image->client_owned_mask = 1;
2440 } else {
2441 if (fwin->lbutton_image && !fwin->lbutton_image->shared) {
2442 wPixmapDestroy(fwin->lbutton_image);
2444 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
2448 #ifdef XKB_BUTTON_HINT
2449 if (!WFLAGP(wwin, no_language_button)) {
2450 if (fwin->languagebutton_image &&
2451 !fwin->languagebutton_image->shared) {
2452 wPixmapDestroy(fwin->languagebutton_image);
2454 fwin->languagebutton_image =
2455 scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
2457 #endif
2459 /* close button */
2461 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2462 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2464 if (!WFLAGP(wwin, no_close_button)) {
2465 if (wwin->wm_gnustep_attr
2466 && wwin->wm_gnustep_attr->flags & GSClosePixmapAttr) {
2467 pixmap = wwin->wm_gnustep_attr->close_pixmap;
2469 if (wwin->wm_gnustep_attr->flags&GSCloseMaskAttr)
2470 mask = wwin->wm_gnustep_attr->close_mask;
2471 else
2472 mask = None;
2474 if (fwin->rbutton_image && (fwin->rbutton_image->image != pixmap
2475 || fwin->rbutton_image->mask != mask)) {
2476 wPixmapDestroy(fwin->rbutton_image);
2477 fwin->rbutton_image = NULL;
2480 if (!fwin->rbutton_image) {
2481 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
2482 fwin->rbutton_image->client_owned = 1;
2483 fwin->rbutton_image->client_owned_mask = 1;
2486 } else if (WFLAGP(wwin, kill_close)) {
2488 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2489 wPixmapDestroy(fwin->rbutton_image);
2491 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
2493 } else if (MGFLAGP(wwin, broken_close)) {
2495 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2496 wPixmapDestroy(fwin->rbutton_image);
2498 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
2500 } else {
2502 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2503 wPixmapDestroy(fwin->rbutton_image);
2505 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
2509 /* force buttons to be redrawn */
2510 fwin->flags.need_texture_change = 1;
2511 wFrameWindowPaint(fwin);
2516 *---------------------------------------------------------------------------
2517 * wWindowConfigureBorders--
2518 * Update window border configuration according to attribute flags.
2520 *---------------------------------------------------------------------------
2522 void
2523 wWindowConfigureBorders(WWindow *wwin)
2525 if (wwin->frame) {
2526 int flags;
2527 int newy, oldh;
2529 flags = WFF_LEFT_BUTTON|WFF_RIGHT_BUTTON;
2531 #ifdef XKB_BUTTON_HINT
2532 flags |= WFF_LANGUAGE_BUTTON;
2533 #endif
2535 if (HAS_TITLEBAR(wwin))
2536 flags |= WFF_TITLEBAR;
2537 if (HAS_RESIZEBAR(wwin) && IS_RESIZABLE(wwin))
2538 flags |= WFF_RESIZEBAR;
2539 if (HAS_BORDER(wwin))
2540 flags |= WFF_BORDER;
2541 if (wwin->flags.shaded)
2542 flags |= WFF_IS_SHADED;
2544 oldh = wwin->frame->top_width;
2545 wFrameWindowUpdateBorders(wwin->frame, flags);
2546 if (oldh != wwin->frame->top_width) {
2547 newy = wwin->frame_y + oldh - wwin->frame->top_width;
2549 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2550 wWindowConfigure(wwin, wwin->frame_x, newy,
2551 wwin->client.width, wwin->client.height);
2554 flags = 0;
2555 if (!WFLAGP(wwin, no_miniaturize_button)
2556 && wwin->frame->flags.hide_left_button)
2557 flags |= WFF_LEFT_BUTTON;
2559 #ifdef XKB_BUTTON_HINT
2560 if (!WFLAGP(wwin, no_language_button)
2561 && wwin->frame->flags.hide_language_button) {
2562 flags |= WFF_LANGUAGE_BUTTON;
2564 #endif
2566 if (!WFLAGP(wwin, no_close_button)
2567 && wwin->frame->flags.hide_right_button)
2568 flags |= WFF_RIGHT_BUTTON;
2570 if (flags!=0) {
2571 wWindowUpdateButtonImages(wwin);
2572 wFrameWindowShowButton(wwin->frame, flags);
2575 flags = 0;
2576 if (WFLAGP(wwin, no_miniaturize_button)
2577 && !wwin->frame->flags.hide_left_button)
2578 flags |= WFF_LEFT_BUTTON;
2580 #ifdef XKB_BUTTON_HINT
2581 if (WFLAGP(wwin, no_language_button)
2582 && !wwin->frame->flags.hide_language_button)
2583 flags |= WFF_LANGUAGE_BUTTON;
2584 #endif
2586 if (WFLAGP(wwin, no_close_button)
2587 && !wwin->frame->flags.hide_right_button)
2588 flags |= WFF_RIGHT_BUTTON;
2590 if (flags!=0)
2591 wFrameWindowHideButton(wwin->frame, flags);
2593 #ifdef SHAPE
2594 if (wShapeSupported && wwin->flags.shaped) {
2595 wWindowSetShape(wwin);
2597 #endif
2602 void
2603 wWindowSaveState(WWindow *wwin)
2605 CARD32 data[10];
2606 int i;
2608 memset(data, 0, sizeof(CARD32)*10);
2609 data[0] = wwin->frame->workspace;
2610 data[1] = wwin->flags.miniaturized;
2611 data[2] = wwin->flags.shaded;
2612 data[3] = wwin->flags.hidden;
2613 data[4] = wwin->flags.maximized;
2614 if (wwin->flags.maximized == 0) {
2615 data[5] = wwin->frame_x;
2616 data[6] = wwin->frame_y;
2617 data[7] = wwin->frame->core->width;
2618 data[8] = wwin->frame->core->height;
2619 } else {
2620 data[5] = wwin->old_geometry.x;
2621 data[6] = wwin->old_geometry.y;
2622 data[7] = wwin->old_geometry.width;
2623 data[8] = wwin->old_geometry.height;
2626 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
2627 if (wwin->screen_ptr->shortcutWindows[i] &&
2628 WMCountInArray(wwin->screen_ptr->shortcutWindows[i], wwin))
2629 data[9] |= 1<<i;
2631 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
2632 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
2633 (unsigned char *)data, 10);
2637 static int
2638 getSavedState(Window window, WSavedState **state)
2640 Atom type_ret;
2641 int fmt_ret;
2642 unsigned long nitems_ret;
2643 unsigned long bytes_after_ret;
2644 CARD32 *data;
2646 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
2647 True, _XA_WINDOWMAKER_STATE,
2648 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
2649 (unsigned char **)&data)!=Success || !data)
2650 return 0;
2652 *state = wmalloc(sizeof(WSavedState));
2654 (*state)->workspace = data[0];
2655 (*state)->miniaturized = data[1];
2656 (*state)->shaded = data[2];
2657 (*state)->hidden = data[3];
2658 (*state)->maximized = data[4];
2659 (*state)->x = data[5];
2660 (*state)->y = data[6];
2661 (*state)->w = data[7];
2662 (*state)->h = data[8];
2663 (*state)->window_shortcuts = data[9];
2665 XFree(data);
2667 if (*state && type_ret==_XA_WINDOWMAKER_STATE)
2668 return 1;
2669 else
2670 return 0;
2674 #ifdef SHAPE
2675 void
2676 wWindowClearShape(WWindow *wwin)
2678 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
2679 0, wwin->frame->top_width, None, ShapeSet);
2680 XFlush(dpy);
2683 void
2684 wWindowSetShape(WWindow *wwin)
2686 XRectangle rect[2];
2687 int count;
2688 #ifdef OPTIMIZE_SHAPE
2689 XRectangle *rects;
2690 XRectangle *urec;
2691 int ordering;
2693 /* only shape is the client's */
2694 if (!HAS_TITLEBAR(wwin) && !HAS_RESIZEBAR(wwin)) {
2695 goto alt_code;
2698 /* Get array of rectangles describing the shape mask */
2699 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding,
2700 &count, &ordering);
2701 if (!rects) {
2702 goto alt_code;
2705 urec = malloc(sizeof(XRectangle)*(count+2));
2706 if (!urec) {
2707 XFree(rects);
2708 goto alt_code;
2711 /* insert our decoration rectangles in the rect list */
2712 memcpy(urec, rects, sizeof(XRectangle)*count);
2713 XFree(rects);
2715 if (HAS_TITLEBAR(wwin)) {
2716 urec[count].x = -1;
2717 urec[count].y = -1 - wwin->frame->top_width;
2718 urec[count].width = wwin->frame->core->width + 2;
2719 urec[count].height = wwin->frame->top_width + 1;
2720 count++;
2722 if (HAS_RESIZEBAR(wwin)) {
2723 urec[count].x = -1;
2724 urec[count].y = wwin->frame->core->height
2725 - wwin->frame->bottom_width - wwin->frame->top_width;
2726 urec[count].width = wwin->frame->core->width + 2;
2727 urec[count].height = wwin->frame->bottom_width + 1;
2728 count++;
2731 /* shape our frame window */
2732 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2733 0, wwin->frame->top_width, urec, count,
2734 ShapeSet, Unsorted);
2735 XFlush(dpy);
2736 wfree(urec);
2737 return;
2739 alt_code:
2740 #endif /* OPTIMIZE_SHAPE */
2741 count = 0;
2742 if (HAS_TITLEBAR(wwin)) {
2743 rect[count].x = -1;
2744 rect[count].y = -1;
2745 rect[count].width = wwin->frame->core->width + 2;
2746 rect[count].height = wwin->frame->top_width + 1;
2747 count++;
2749 if (HAS_RESIZEBAR(wwin)) {
2750 rect[count].x = -1;
2751 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
2752 rect[count].width = wwin->frame->core->width + 2;
2753 rect[count].height = wwin->frame->bottom_width + 1;
2754 count++;
2756 if (count > 0) {
2757 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2758 0, 0, rect, count, ShapeSet, Unsorted);
2760 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
2761 0, wwin->frame->top_width, wwin->client_win,
2762 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
2763 XFlush(dpy);
2765 #endif /* SHAPE */
2767 /* ====================================================================== */
2769 static FocusMode
2770 getFocusMode(WWindow *wwin)
2772 FocusMode mode;
2774 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
2775 if (wwin->wm_hints->input == True) {
2776 if (wwin->protocols.TAKE_FOCUS)
2777 mode = WFM_LOCALLY_ACTIVE;
2778 else
2779 mode = WFM_PASSIVE;
2780 } else {
2781 if (wwin->protocols.TAKE_FOCUS)
2782 mode = WFM_GLOBALLY_ACTIVE;
2783 else
2784 mode = WFM_NO_INPUT;
2786 } else {
2787 mode = WFM_PASSIVE;
2789 return mode;
2793 void
2794 wWindowSetKeyGrabs(WWindow *wwin)
2796 int i;
2797 WShortKey *key;
2799 for (i=0; i<WKBD_LAST; i++) {
2800 key = &wKeyBindings[i];
2802 if (key->keycode==0)
2803 continue;
2804 if (key->modifier!=AnyModifier) {
2805 XGrabKey(dpy, key->keycode, key->modifier|LockMask,
2806 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2807 #ifdef NUMLOCK_HACK
2808 /* Also grab all modifier combinations possible that include,
2809 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2810 * work even if the NumLock/ScrollLock key is on.
2812 wHackedGrabKey(key->keycode, key->modifier,
2813 wwin->frame->core->window, True, GrabModeAsync,
2814 GrabModeAsync);
2815 #endif
2817 XGrabKey(dpy, key->keycode, key->modifier,
2818 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2821 #ifndef LITE
2822 wRootMenuBindShortcuts(wwin->frame->core->window);
2823 #endif
2828 void
2829 wWindowResetMouseGrabs(WWindow *wwin)
2831 /* Mouse grabs can't be done on the client window because of
2832 * ICCCM and because clients that try to do the same will crash.
2834 * But there is a problem wich makes tbar buttons of unfocused
2835 * windows not usable as the click goes to the frame window instead
2836 * of the button itself. Must figure a way to fix that.
2839 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2841 if (!WFLAGP(wwin, no_bind_mouse)) {
2842 /* grabs for Meta+drag */
2843 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2844 True, ButtonPressMask|ButtonReleaseMask,
2845 GrabModeSync, GrabModeAsync, None, None);
2848 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable)
2849 && !wwin->flags.is_gnustep) {
2850 /* the passive grabs to focus the window */
2851 /* if (wPreferences.focus_mode == WKF_CLICK) */
2852 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2853 True, ButtonPressMask|ButtonReleaseMask,
2854 GrabModeSync, GrabModeAsync, None, None);
2856 XFlush(dpy);
2860 void
2861 wWindowUpdateGNUstepAttr(WWindow *wwin, GNUstepWMAttributes *attr)
2863 if (attr->flags & GSExtraFlagsAttr) {
2864 if (MGFLAGP(wwin, broken_close) !=
2865 (attr->extra_flags & GSDocumentEditedFlag)) {
2866 wwin->client_flags.broken_close = !MGFLAGP(wwin, broken_close);
2867 wWindowUpdateButtonImages(wwin);
2873 WMagicNumber
2874 wWindowAddSavedState(char *instance, char *class, char *command,
2875 pid_t pid, WSavedState *state)
2877 WWindowState *wstate;
2879 wstate = malloc(sizeof(WWindowState));
2880 if (!wstate)
2881 return 0;
2883 memset(wstate, 0, sizeof(WWindowState));
2884 wstate->pid = pid;
2885 if (instance)
2886 wstate->instance = wstrdup(instance);
2887 if (class)
2888 wstate->class = wstrdup(class);
2889 if (command)
2890 wstate->command = wstrdup(command);
2891 wstate->state = state;
2893 wstate->next = windowState;
2894 windowState = wstate;
2896 #ifdef DEBUG
2897 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2898 class, command);
2899 #endif
2901 return wstate;
2905 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2908 WMagicNumber
2909 wWindowGetSavedState(Window win)
2911 char *instance, *class, *command=NULL;
2912 WWindowState *wstate = windowState;
2914 if (!wstate)
2915 return NULL;
2917 command = GetCommandForWindow(win);
2918 if (!command)
2919 return NULL;
2921 if (PropGetWMClass(win, &class, &instance)) {
2922 while (wstate) {
2923 if (SAME(instance, wstate->instance) &&
2924 SAME(class, wstate->class) &&
2925 SAME(command, wstate->command)) {
2926 break;
2928 wstate = wstate->next;
2930 } else {
2931 wstate = NULL;
2934 #ifdef DEBUG
2935 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2936 class, command);
2937 #endif
2939 if (command) wfree(command);
2940 if (instance) XFree(instance);
2941 if (class) XFree(class);
2943 return wstate;
2947 void
2948 wWindowDeleteSavedState(WMagicNumber id)
2950 WWindowState *tmp, *wstate=(WWindowState*)id;
2952 if (!wstate || !windowState)
2953 return;
2955 tmp = windowState;
2956 if (tmp==wstate) {
2957 windowState = wstate->next;
2958 #ifdef DEBUG
2959 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2960 wstate, wstate->instance, wstate->class, wstate->command);
2961 #endif
2962 if (wstate->instance) wfree(wstate->instance);
2963 if (wstate->class) wfree(wstate->class);
2964 if (wstate->command) wfree(wstate->command);
2965 wfree(wstate->state);
2966 wfree(wstate);
2967 } else {
2968 while (tmp->next) {
2969 if (tmp->next==wstate) {
2970 tmp->next=wstate->next;
2971 #ifdef DEBUG
2972 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2973 wstate, wstate->instance, wstate->class, wstate->command);
2974 #endif
2975 if (wstate->instance) wfree(wstate->instance);
2976 if (wstate->class) wfree(wstate->class);
2977 if (wstate->command) wfree(wstate->command);
2978 wfree(wstate->state);
2979 wfree(wstate);
2980 break;
2982 tmp = tmp->next;
2988 void
2989 wWindowDeleteSavedStatesForPID(pid_t pid)
2991 WWindowState *tmp, *wstate;
2993 if (!windowState)
2994 return;
2996 tmp = windowState;
2997 if (tmp->pid == pid) {
2998 wstate = windowState;
2999 windowState = tmp->next;
3000 #ifdef DEBUG
3001 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
3002 wstate, wstate->instance, wstate->class, wstate->command);
3003 #endif
3004 if (wstate->instance) wfree(wstate->instance);
3005 if (wstate->class) wfree(wstate->class);
3006 if (wstate->command) wfree(wstate->command);
3007 wfree(wstate->state);
3008 wfree(wstate);
3009 } else {
3010 while (tmp->next) {
3011 if (tmp->next->pid==pid) {
3012 wstate = tmp->next;
3013 tmp->next = wstate->next;
3014 #ifdef DEBUG
3015 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
3016 wstate, wstate->instance, wstate->class, wstate->command);
3017 #endif
3018 if (wstate->instance) wfree(wstate->instance);
3019 if (wstate->class) wfree(wstate->class);
3020 if (wstate->command) wfree(wstate->command);
3021 wfree(wstate->state);
3022 wfree(wstate);
3023 break;
3025 tmp = tmp->next;
3031 void
3032 wWindowSetOmnipresent(WWindow *wwin, Bool flag)
3034 if (wwin->flags.omnipresent == flag)
3035 return;
3037 wwin->flags.omnipresent = flag;
3038 WMPostNotificationName(WMNChangedState, wwin, "omnipresent");
3042 /* ====================================================================== */
3044 static void
3045 resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
3047 WWindow *wwin = data;
3049 #ifndef NUMLOCK_HACK
3050 if ((event->xbutton.state & ValidModMask)
3051 != (event->xbutton.state & ~LockMask)) {
3052 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
3053 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3055 #endif
3057 event->xbutton.state &= ValidModMask;
3059 CloseWindowMenu(wwin->screen_ptr);
3061 if (wPreferences.focus_mode==WKF_CLICK
3062 && !(event->xbutton.state&ControlMask)
3063 && !WFLAGP(wwin, no_focusable)) {
3064 wSetFocusTo(wwin->screen_ptr, wwin);
3067 if (event->xbutton.button == Button1)
3068 wRaiseFrame(wwin->frame->core);
3070 if (event->xbutton.window != wwin->frame->resizebar->window) {
3071 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
3072 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
3073 GrabModeAsync, GrabModeAsync, None,
3074 None, CurrentTime)!=GrabSuccess) {
3075 #ifdef DEBUG0
3076 wwarning("pointer grab failed for window move");
3077 #endif
3078 return;
3082 if (event->xbutton.state & MOD_MASK) {
3083 /* move the window */
3084 wMouseMoveWindow(wwin, event);
3085 XUngrabPointer(dpy, CurrentTime);
3086 } else {
3087 wMouseResizeWindow(wwin, event);
3088 XUngrabPointer(dpy, CurrentTime);
3094 static void
3095 titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
3097 WWindow *wwin = data;
3099 event->xbutton.state &= ValidModMask;
3101 if (event->xbutton.button==Button1) {
3102 if (event->xbutton.state == 0) {
3103 if (!WFLAGP(wwin, no_shadeable)) {
3104 /* shade window */
3105 if (wwin->flags.shaded)
3106 wUnshadeWindow(wwin);
3107 else
3108 wShadeWindow(wwin);
3110 } else {
3111 int dir = 0;
3113 if (event->xbutton.state & ControlMask)
3114 dir |= MAX_VERTICAL;
3116 if (event->xbutton.state & ShiftMask) {
3117 dir |= MAX_HORIZONTAL;
3118 if (!(event->xbutton.state & ControlMask))
3119 wSelectWindow(wwin, !wwin->flags.selected);
3122 /* maximize window */
3123 if (dir!=0 && IS_RESIZABLE(wwin)) {
3124 int ndir = dir ^ wwin->flags.maximized;
3126 if (ndir != 0) {
3127 wMaximizeWindow(wwin, ndir);
3128 } else {
3129 wUnmaximizeWindow(wwin);
3133 } else if (event->xbutton.button==Button3) {
3134 if (event->xbutton.state & MOD_MASK) {
3135 wHideOtherApplications(wwin);
3137 } else if (event->xbutton.button==Button2) {
3138 wSelectWindow(wwin, !wwin->flags.selected);
3139 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelUp) {
3140 wShadeWindow(wwin);
3141 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelDown) {
3142 wUnshadeWindow(wwin);
3147 static void
3148 frameMouseDown(WObjDescriptor *desc, XEvent *event)
3150 WWindow *wwin = desc->parent;
3152 event->xbutton.state &= ValidModMask;
3154 CloseWindowMenu(wwin->screen_ptr);
3156 if (/*wPreferences.focus_mode==WKF_CLICK
3157 &&*/ !(event->xbutton.state&ControlMask)
3158 && !WFLAGP(wwin, no_focusable)) {
3159 wSetFocusTo(wwin->screen_ptr, wwin);
3161 if (event->xbutton.button == Button1) {
3162 wRaiseFrame(wwin->frame->core);
3165 if (event->xbutton.state & MOD_MASK) {
3166 /* move the window */
3167 if (XGrabPointer(dpy, wwin->client_win, False,
3168 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
3169 GrabModeAsync, GrabModeAsync, None,
3170 None, CurrentTime)!=GrabSuccess) {
3171 #ifdef DEBUG0
3172 wwarning("pointer grab failed for window move");
3173 #endif
3174 return;
3176 if (event->xbutton.button == Button3)
3177 wMouseResizeWindow(wwin, event);
3178 else if (event->xbutton.button==Button1 || event->xbutton.button==Button2)
3179 wMouseMoveWindow(wwin, event);
3180 XUngrabPointer(dpy, CurrentTime);
3185 static void
3186 titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
3188 WWindow *wwin = (WWindow*)data;
3190 #ifndef NUMLOCK_HACK
3191 if ((event->xbutton.state & ValidModMask)
3192 != (event->xbutton.state & ~LockMask)) {
3193 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
3194 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3196 #endif
3197 event->xbutton.state &= ValidModMask;
3199 CloseWindowMenu(wwin->screen_ptr);
3201 if (wPreferences.focus_mode==WKF_CLICK
3202 && !(event->xbutton.state&ControlMask)
3203 && !WFLAGP(wwin, no_focusable)) {
3204 wSetFocusTo(wwin->screen_ptr, wwin);
3207 if (event->xbutton.button == Button1
3208 || event->xbutton.button == Button2) {
3210 if (event->xbutton.button == Button1) {
3211 if (event->xbutton.state & MOD_MASK) {
3212 wLowerFrame(wwin->frame->core);
3213 } else {
3214 wRaiseFrame(wwin->frame->core);
3217 if ((event->xbutton.state & ShiftMask)
3218 && !(event->xbutton.state & ControlMask)) {
3219 wSelectWindow(wwin, !wwin->flags.selected);
3220 return;
3222 if (event->xbutton.window != wwin->frame->titlebar->window
3223 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
3224 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
3225 GrabModeAsync, GrabModeAsync, None,
3226 None, CurrentTime)!=GrabSuccess) {
3227 #ifdef DEBUG0
3228 wwarning("pointer grab failed for window move");
3229 #endif
3230 return;
3233 /* move the window */
3234 wMouseMoveWindow(wwin, event);
3236 XUngrabPointer(dpy, CurrentTime);
3237 } else if (event->xbutton.button == Button3 && event->xbutton.state==0
3238 && !wwin->flags.internal_window
3239 && !WCHECK_STATE(WSTATE_MODAL)) {
3240 WObjDescriptor *desc;
3242 if (event->xbutton.window != wwin->frame->titlebar->window
3243 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
3244 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
3245 GrabModeAsync, GrabModeAsync, None,
3246 None, CurrentTime)!=GrabSuccess) {
3247 #ifdef DEBUG0
3248 wwarning("pointer grab failed for window move");
3249 #endif
3250 return;
3253 OpenWindowMenu(wwin, event->xbutton.x_root,
3254 wwin->frame_y+wwin->frame->top_width, False);
3256 /* allow drag select */
3257 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
3258 event->xany.send_event = True;
3259 (*desc->handle_mousedown)(desc, event);
3261 XUngrabPointer(dpy, CurrentTime);
3267 static void
3268 windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
3270 WWindow *wwin = data;
3272 event->xbutton.state &= ValidModMask;
3274 CloseWindowMenu(wwin->screen_ptr);
3276 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3277 return;
3279 /* if control-click, kill the client */
3280 if (event->xbutton.state & ControlMask) {
3281 wClientKill(wwin);
3282 } else {
3283 if (wwin->protocols.DELETE_WINDOW && event->xbutton.state==0) {
3284 /* send delete message */
3285 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3291 static void
3292 windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
3294 WWindow *wwin = data;
3296 CloseWindowMenu(wwin->screen_ptr);
3298 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3299 return;
3301 /* send delete message */
3302 if (wwin->protocols.DELETE_WINDOW) {
3303 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3304 } else {
3305 wClientKill(wwin);
3310 #ifdef XKB_BUTTON_HINT
3311 static void
3312 windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event)
3314 WWindow *wwin = data;
3315 WFrameWindow *fwin = wwin->frame;
3316 WScreen *scr = fwin->screen_ptr;
3317 XkbStateRec staterec;
3318 int tl;
3320 if (event->xbutton.button != Button1 && event->xbutton.button != Button3)
3321 return;
3322 tl = wwin->frame->languagemode;
3323 wwin->frame->languagemode = wwin->frame->last_languagemode;
3324 wwin->frame->last_languagemode = tl;
3325 wSetFocusTo(scr, wwin);
3326 wwin->frame->languagebutton_image =
3327 wwin->frame->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 +
3328 wwin->frame->languagemode];
3329 wFrameWindowUpdateLanguageButton(wwin->frame);
3330 if (event->xbutton.button == Button3)
3331 return;
3332 wRaiseFrame(fwin->core);
3334 #endif
3337 static void
3338 windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
3340 WWindow *wwin = data;
3342 event->xbutton.state &= ValidModMask;
3344 CloseWindowMenu(wwin->screen_ptr);
3346 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3347 return;
3349 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state==0) {
3350 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
3351 LastTimestamp);
3352 } else {
3353 WApplication *wapp;
3354 if ((event->xbutton.state & ControlMask) ||
3355 (event->xbutton.button == Button3)) {
3357 wapp = wApplicationOf(wwin->main_window);
3358 if (wapp && !WFLAGP(wwin, no_appicon))
3359 wHideApplication(wapp);
3360 } else if (event->xbutton.state==0) {
3361 wIconifyWindow(wwin);