- Fixed sloppy focus bug
[wmaker-crm.git] / src / window.c
blobbee7d63ca8dea4c4032210056b43679b8e26f465
1 /* window.c - client window managing stuffs
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997-2003 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.
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 KWM_HINTS
63 # include "kwm.h"
64 #endif
65 #ifdef GNOME_STUFF
66 # include "gnome.h"
67 #endif
68 #ifdef OLWM_HINTS
69 # include "openlook.h"
70 #endif
72 /****** Global Variables ******/
74 extern WShortKey wKeyBindings[WKBD_LAST];
76 #ifdef SHAPE
77 extern Bool wShapeSupported;
78 #endif
80 /* contexts */
81 extern XContext wWinContext;
83 /* cursors */
84 extern Cursor wCursor[WCUR_LAST];
86 /* protocol atoms */
87 extern Atom _XA_WM_DELETE_WINDOW;
88 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
90 extern Atom _XA_WINDOWMAKER_STATE;
92 extern WPreferences wPreferences;
94 #define MOD_MASK wPreferences.modifier_mask
96 extern Time LastTimestamp;
98 /* superfluous... */
99 extern void DoWindowBirth(WWindow*);
103 /***** Local Stuff *****/
106 static WWindowState *windowState=NULL;
110 /* local functions */
111 static FocusMode getFocusMode(WWindow *wwin);
113 static int getSavedState(Window window, WSavedState **state);
115 static void setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints);
117 /* event handlers */
120 /* frame window (during window grabs) */
121 static void frameMouseDown(WObjDescriptor *desc, XEvent *event);
123 /* close button */
124 static void windowCloseClick(WCoreWindow *sender, void *data, XEvent *event);
125 static void windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event);
127 /* iconify button */
128 static void windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event);
130 #ifdef XKB_BUTTON_HINT
131 static void windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event);
132 #endif
134 static void titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
135 static void titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event);
137 static void resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
140 /****** Notification Observers ******/
142 static void
143 appearanceObserver(void *self, WMNotification *notif)
145 WWindow *wwin = (WWindow*)self;
146 int flags = (int)WMGetNotificationClientData(notif);
148 if (!wwin->frame || (!wwin->frame->titlebar && !wwin->frame->resizebar))
149 return;
151 if (flags & WFontSettings) {
152 wWindowConfigureBorders(wwin);
153 if(wwin->flags.shaded) {
154 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
155 wwin->frame->top_width - 1);
157 wwin->client.y = wwin->frame_y - wwin->client.height
158 + wwin->frame->top_width;
159 wWindowSynthConfigureNotify(wwin);
162 if (flags & WTextureSettings) {
163 wwin->frame->flags.need_texture_remake = 1;
165 if (flags & (WTextureSettings | WColorSettings)) {
166 if (wwin->frame->titlebar)
167 XClearWindow(dpy, wwin->frame->titlebar->window);
169 wFrameWindowPaint(wwin->frame);
173 /************************************/
175 WWindow*
176 wWindowFor(Window window)
178 WObjDescriptor *desc;
180 if (window==None)
181 return NULL;
183 if (XFindContext(dpy, window, wWinContext, (XPointer*)&desc)==XCNOENT)
184 return NULL;
186 if (desc->parent_type==WCLASS_WINDOW)
187 return desc->parent;
188 else if (desc->parent_type==WCLASS_FRAME) {
189 WFrameWindow *frame = (WFrameWindow*)desc->parent;
190 if (frame->flags.is_client_window_frame)
191 return frame->child;
194 return NULL;
198 WWindow*
199 wWindowCreate()
201 WWindow *wwin;
203 wwin = wmalloc(sizeof(WWindow));
204 wretain(wwin);
206 memset(wwin, 0, sizeof(WWindow));
208 wwin->client_descriptor.handle_mousedown = frameMouseDown;
209 wwin->client_descriptor.parent = wwin;
210 wwin->client_descriptor.self = wwin;
211 wwin->client_descriptor.parent_type = WCLASS_WINDOW;
213 return wwin;
217 void
218 wWindowDestroy(WWindow *wwin)
220 int i;
222 if (wwin->screen_ptr->cmap_window == wwin) {
223 wwin->screen_ptr->cmap_window = NULL;
226 WMRemoveNotificationObserver(wwin);
228 wwin->flags.destroyed = 1;
230 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
231 if (!wwin->screen_ptr->shortcutWindows[i])
232 continue;
234 WMRemoveFromArray(wwin->screen_ptr->shortcutWindows[i], wwin);
236 if (!WMGetArrayItemCount(wwin->screen_ptr->shortcutWindows[i])) {
237 WMFreeArray(wwin->screen_ptr->shortcutWindows[i]);
238 wwin->screen_ptr->shortcutWindows[i] = NULL;
242 if (wwin->fake_group && wwin->fake_group->retainCount>0) {
243 wwin->fake_group->retainCount--;
244 if (wwin->fake_group->retainCount==0 && wwin->fake_group->leader!=None) {
245 XDestroyWindow(dpy, wwin->fake_group->leader);
246 wwin->fake_group->leader = None;
247 wwin->fake_group->origLeader = None;
248 XFlush(dpy);
252 if (wwin->normal_hints)
253 XFree(wwin->normal_hints);
255 if (wwin->wm_hints)
256 XFree(wwin->wm_hints);
258 if (wwin->wm_instance)
259 XFree(wwin->wm_instance);
261 if (wwin->wm_class)
262 XFree(wwin->wm_class);
264 if (wwin->wm_gnustep_attr)
265 wfree(wwin->wm_gnustep_attr);
267 if (wwin->cmap_windows)
268 XFree(wwin->cmap_windows);
270 XDeleteContext(dpy, wwin->client_win, wWinContext);
272 if (wwin->frame)
273 wFrameWindowDestroy(wwin->frame);
275 if (wwin->icon) {
276 RemoveFromStackList(wwin->icon->core);
277 wIconDestroy(wwin->icon);
278 if (wPreferences.auto_arrange_icons)
279 wArrangeIcons(wwin->screen_ptr, True);
281 wrelease(wwin);
287 static void
288 setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints)
290 if (gs_hints->flags & GSWindowStyleAttr) {
291 if (gs_hints->window_style == WMBorderlessWindowMask) {
292 wwin->client_flags.no_border = 1;
293 wwin->client_flags.no_titlebar = 1;
294 wwin->client_flags.no_closable = 1;
295 wwin->client_flags.no_miniaturizable = 1;
296 wwin->client_flags.no_resizable = 1;
297 wwin->client_flags.no_close_button = 1;
298 wwin->client_flags.no_miniaturize_button = 1;
299 wwin->client_flags.no_resizebar = 1;
300 } else {
301 wwin->client_flags.no_close_button =
302 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
304 wwin->client_flags.no_closable =
305 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
307 wwin->client_flags.no_miniaturize_button =
308 ((gs_hints->window_style & WMMiniaturizableWindowMask)?0:1);
310 wwin->client_flags.no_miniaturizable =
311 wwin->client_flags.no_miniaturize_button;
313 wwin->client_flags.no_resizebar =
314 ((gs_hints->window_style & WMResizableWindowMask)?0:1);
316 wwin->client_flags.no_resizable = wwin->client_flags.no_resizebar;
318 /* these attributes supposedly imply in the existence
319 * of a titlebar */
320 if (gs_hints->window_style & (WMResizableWindowMask|
321 WMClosableWindowMask|
322 WMMiniaturizableWindowMask)) {
323 wwin->client_flags.no_titlebar = 0;
324 } else {
325 wwin->client_flags.no_titlebar =
326 ((gs_hints->window_style & WMTitledWindowMask)?0:1);
330 } else {
331 /* setup the defaults */
332 wwin->client_flags.no_border = 0;
333 wwin->client_flags.no_titlebar = 0;
334 wwin->client_flags.no_closable = 0;
335 wwin->client_flags.no_miniaturizable = 0;
336 wwin->client_flags.no_resizable = 0;
337 wwin->client_flags.no_close_button = 0;
338 wwin->client_flags.no_miniaturize_button = 0;
339 wwin->client_flags.no_resizebar = 0;
341 if (gs_hints->extra_flags & GSNoApplicationIconFlag) {
342 wwin->client_flags.no_appicon = 1;
347 void
348 wWindowCheckAttributeSanity(WWindow *wwin, WWindowAttributes *wflags,
349 WWindowAttributes *mask)
351 if (wflags->no_appicon && mask->no_appicon)
352 wflags->emulate_appicon = 0;
354 if (wwin->main_window!=None) {
355 WApplication *wapp = wApplicationOf(wwin->main_window);
356 if (wapp && !wapp->flags.emulated)
357 wflags->emulate_appicon = 0;
360 if (wwin->transient_for!=None
361 && wwin->transient_for!=wwin->screen_ptr->root_win)
362 wflags->emulate_appicon = 0;
364 if (wflags->sunken && mask->sunken && wflags->floating && mask->floating)
365 wflags->sunken = 0;
370 void
371 wWindowSetupInitialAttributes(WWindow *wwin, int *level, int *workspace)
373 WScreen *scr = wwin->screen_ptr;
375 /* sets global default stuff */
376 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
377 &wwin->client_flags, NULL, True);
379 * Decoration setting is done in this precedence (lower to higher)
380 * - use global default in the resource database
381 * - guess some settings
382 * - use GNUstep/external window attributes
383 * - set hints specified for the app in the resource DB
386 WSETUFLAG(wwin, broken_close, 0);
388 if (wwin->protocols.DELETE_WINDOW)
389 WSETUFLAG(wwin, kill_close, 0);
390 else
391 WSETUFLAG(wwin, kill_close, 1);
393 /* transients can't be iconified or maximized */
394 if (wwin->transient_for!=None && wwin->transient_for!=scr->root_win) {
395 WSETUFLAG(wwin, no_miniaturizable, 1);
396 WSETUFLAG(wwin, no_miniaturize_button, 1);
399 /* if the window can't be resized, remove the resizebar */
400 if (wwin->normal_hints->flags & (PMinSize|PMaxSize)
401 && (wwin->normal_hints->min_width==wwin->normal_hints->max_width)
402 && (wwin->normal_hints->min_height==wwin->normal_hints->max_height)) {
403 WSETUFLAG(wwin, no_resizable, 1);
404 WSETUFLAG(wwin, no_resizebar, 1);
407 /* set GNUstep window attributes */
408 if (wwin->wm_gnustep_attr) {
409 setupGNUstepHints(wwin, wwin->wm_gnustep_attr);
411 if (wwin->wm_gnustep_attr->flags & GSWindowLevelAttr) {
413 *level = wwin->wm_gnustep_attr->window_level;
415 * INT_MIN is the only illegal window level.
417 if (*level == INT_MIN)
418 *level = INT_MIN + 1;
419 } else {
420 /* setup defaults */
421 *level = WMNormalLevel;
423 } else {
424 int tmp_workspace = -1;
425 int tmp_level = INT_MIN; /* INT_MIN is never used by the window levels */
426 Bool check;
428 check = False;
430 #ifdef MWM_HINTS
431 wMWMCheckClientHints(wwin);
432 #endif /* MWM_HINTS */
434 #ifdef GNOME_STUFF
435 check = wGNOMECheckClientHints(wwin, &tmp_level, &tmp_workspace);
436 #endif /* GNOME_STUFF */
438 #ifdef KWM_HINTS
439 if (!check)
440 wKWMCheckClientHints(wwin, &tmp_level, &tmp_workspace);
441 #endif /* KWM_HINTS */
443 #ifdef OLWM_HINTS
444 wOLWMCheckClientHints(wwin);
445 #endif /* OLWM_HINTS */
447 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
448 * have INT_MIN that means that no window level was requested. -Dan
450 if (tmp_level == INT_MIN) {
451 if (WFLAGP(wwin, floating))
452 *level = WMFloatingLevel;
453 else if (WFLAGP(wwin, sunken))
454 *level = WMSunkenLevel;
455 else
456 *level = WMNormalLevel;
457 } else {
458 *level = tmp_level;
461 if (tmp_workspace >= 0) {
462 *workspace = tmp_workspace % scr->workspace_count;
467 * Set attributes specified only for that window/class.
468 * This might do duplicate work with the 1st wDefaultFillAttributes().
470 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
471 &wwin->user_flags, &wwin->defined_user_flags,
472 False);
474 * Sanity checks for attributes that depend on other attributes
476 if (wwin->user_flags.no_appicon && wwin->defined_user_flags.no_appicon)
477 wwin->user_flags.emulate_appicon = 0;
479 if (wwin->main_window!=None) {
480 WApplication *wapp = wApplicationOf(wwin->main_window);
481 if (wapp && !wapp->flags.emulated)
482 wwin->user_flags.emulate_appicon = 0;
485 if (wwin->transient_for!=None
486 && wwin->transient_for!=wwin->screen_ptr->root_win)
487 wwin->user_flags.emulate_appicon = 0;
489 if (wwin->user_flags.sunken && wwin->defined_user_flags.sunken
490 && wwin->user_flags.floating && wwin->defined_user_flags.floating)
491 wwin->user_flags.sunken = 0;
493 WSETUFLAG(wwin, no_shadeable, WFLAGP(wwin, no_titlebar));
496 /* windows that have takefocus=False shouldn't take focus at all */
497 if (wwin->focus_mode == WFM_NO_INPUT) {
498 wwin->client_flags.no_focusable = 1;
505 Bool
506 wWindowCanReceiveFocus(WWindow *wwin)
508 if (!wwin->flags.mapped && (!wwin->flags.shaded || wwin->flags.hidden))
509 return False;
510 if (WFLAGP(wwin, no_focusable) || wwin->flags.miniaturized)
511 return False;
512 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
513 return False;
515 return True;
519 Bool
520 wWindowObscuresWindow(WWindow *wwin, WWindow *obscured)
522 int w1, h1, w2, h2;
524 w1 = wwin->frame->core->width;
525 h1 = wwin->frame->core->height;
526 w2 = obscured->frame->core->width;
527 h2 = obscured->frame->core->height;
529 if (!IS_OMNIPRESENT(wwin) && !IS_OMNIPRESENT(obscured)
530 && wwin->frame->workspace != obscured->frame->workspace)
531 return False;
533 if (wwin->frame_x + w1 < obscured->frame_x
534 || wwin->frame_y + h1 < obscured->frame_y
535 || wwin->frame_x > obscured->frame_x + w2
536 || wwin->frame_y > obscured->frame_y + h2) {
537 return False;
540 return True;
544 static Window
545 createFakeWindowGroupLeader(WScreen *scr, Window win, char *instance, char *class)
547 XClassHint *classHint;
548 XWMHints *hints;
549 Window leader;
550 int argc;
551 char **argv;
553 leader = XCreateSimpleWindow(dpy, scr->root_win, 10, 10, 10, 10, 0, 0, 0);
554 /* set class hint */
555 classHint = XAllocClassHint();
556 classHint->res_name = instance;
557 classHint->res_class = class;
558 XSetClassHint(dpy, leader, classHint);
559 XFree(classHint);
561 /* inherit these from the original leader if available */
562 hints = XGetWMHints(dpy, win);
563 if (!hints) {
564 hints = XAllocWMHints();
565 hints->flags = 0;
567 /* set window group leader to self */
568 hints->window_group = leader;
569 hints->flags |= WindowGroupHint;
570 XSetWMHints(dpy, leader, hints);
571 XFree(hints);
573 if (XGetCommand(dpy, win, &argv, &argc)!=0 && argc > 0) {
574 XSetCommand(dpy, leader, argv, argc);
575 XFreeStringList(argv);
578 return leader;
582 static int
583 matchIdentifier(void *item, void *cdata)
585 return (strcmp(((WFakeGroupLeader*)item)->identifier, (char*)cdata)==0);
590 *----------------------------------------------------------------
591 * wManageWindow--
592 * reparents the window and allocates a descriptor for it.
593 * Window manager hints and other hints are fetched to configure
594 * the window decoration attributes and others. User preferences
595 * for the window are used if available, to configure window
596 * decorations and some behaviour.
597 * If in startup, windows that are override redirect,
598 * unmapped and never were managed and are Withdrawn are not
599 * managed.
601 * Returns:
602 * the new window descriptor
604 * Side effects:
605 * The window is reparented and appropriate notification
606 * is done to the client. Input mask for the window is setup.
607 * The window descriptor is also associated with various window
608 * contexts and inserted in the head of the window list.
609 * Event handler contexts are associated for some objects
610 * (buttons, titlebar and resizebar)
612 *----------------------------------------------------------------
614 WWindow*
615 wManageWindow(WScreen *scr, Window window)
617 WWindow *wwin;
618 int x, y;
619 unsigned width, height;
620 XWindowAttributes wattribs;
621 XSetWindowAttributes attribs;
622 WWindowState *win_state;
623 WWindow *transientOwner = NULL;
624 int window_level;
625 int wm_state;
626 int foo;
627 int workspace = -1;
628 char *title;
629 Bool withdraw = False;
630 Bool raise = False;
632 /* mutex. */
633 /* XGrabServer(dpy); */
634 XSync(dpy, False);
635 /* make sure the window is still there */
636 if (!XGetWindowAttributes(dpy, window, &wattribs)) {
637 XUngrabServer(dpy);
638 return NULL;
641 /* if it's an override-redirect, ignore it */
642 if (wattribs.override_redirect) {
643 XUngrabServer(dpy);
644 return NULL;
647 wm_state = PropGetWindowState(window);
649 /* if it's startup and the window is unmapped, don't manage it */
650 if (scr->flags.startup && wm_state < 0 && wattribs.map_state==IsUnmapped) {
651 XUngrabServer(dpy);
652 return NULL;
655 if (!wFetchName(dpy, window, &title)) {
656 title = NULL;
659 #ifdef KWM_HINTS
660 if (title && !wKWMManageableClient(scr, window, title)) {
661 XFree(title);
662 XUngrabServer(dpy);
663 return NULL;
665 #endif /* KWM_HINTS */
668 wwin = wWindowCreate();
670 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
672 #ifdef DEBUG
673 printf("managing window %x\n", (unsigned)window);
674 #endif
676 #ifdef SHAPE
677 if (wShapeSupported) {
678 int junk;
679 unsigned int ujunk;
680 int b_shaped;
682 XShapeSelectInput(dpy, window, ShapeNotifyMask);
683 XShapeQueryExtents(dpy, window, &b_shaped, &junk, &junk, &ujunk,
684 &ujunk, &junk, &junk, &junk, &ujunk, &ujunk);
685 wwin->flags.shaped = b_shaped;
687 #endif
690 *--------------------------------------------------
692 * Get hints and other information in properties
694 *--------------------------------------------------
696 PropGetWMClass(window, &wwin->wm_class, &wwin->wm_instance);
698 /* setup descriptor */
699 wwin->client_win = window;
700 wwin->screen_ptr = scr;
702 wwin->old_border_width = wattribs.border_width;
704 wwin->event_mask = CLIENT_EVENTS;
705 attribs.event_mask = CLIENT_EVENTS;
706 attribs.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask;
707 attribs.save_under = False;
708 XChangeWindowAttributes(dpy, window, CWEventMask|CWDontPropagate
709 |CWSaveUnder, &attribs);
710 XSetWindowBorderWidth(dpy, window, 0);
712 /* get hints from GNUstep app */
713 if (wwin->wm_class != 0 && strcmp(wwin->wm_class, "GNUstep") == 0) {
714 wwin->flags.is_gnustep = 1;
716 if (!PropGetGNUstepWMAttr(window, &wwin->wm_gnustep_attr)) {
717 wwin->wm_gnustep_attr = NULL;
720 wwin->client_leader = PropGetClientLeader(window);
721 if (wwin->client_leader!=None)
722 wwin->main_window = wwin->client_leader;
724 wwin->wm_hints = XGetWMHints(dpy, window);
726 if (wwin->wm_hints) {
727 if (wwin->wm_hints->flags & StateHint) {
729 if (wwin->wm_hints->initial_state == IconicState) {
731 wwin->flags.miniaturized = 1;
733 } else if (wwin->wm_hints->initial_state == WithdrawnState) {
735 withdraw = True;
739 if (wwin->wm_hints->flags & WindowGroupHint) {
740 wwin->group_id = wwin->wm_hints->window_group;
741 /* window_group has priority over CLIENT_LEADER */
742 wwin->main_window = wwin->group_id;
743 } else {
744 wwin->group_id = None;
747 if (wwin->wm_hints->flags & UrgencyHint)
748 wwin->flags.urgent = 1;
749 } else {
750 wwin->group_id = None;
753 PropGetProtocols(window, &wwin->protocols);
755 if (!XGetTransientForHint(dpy, window, &wwin->transient_for)) {
756 wwin->transient_for = None;
757 } else {
758 if (wwin->transient_for==None || wwin->transient_for==window) {
759 wwin->transient_for = scr->root_win;
760 } else {
761 transientOwner = wWindowFor(wwin->transient_for);
762 if (transientOwner && transientOwner->main_window!=None) {
763 wwin->main_window = transientOwner->main_window;
764 } /*else {
765 wwin->main_window = None;
770 /* guess the focus mode */
771 wwin->focus_mode = getFocusMode(wwin);
773 /* get geometry stuff */
774 wClientGetNormalHints(wwin, &wattribs, True, &x, &y, &width, &height);
776 /* printf( "wManageWindow: %d %d %d %d\n", x, y, width, height);*/
778 /* get colormap windows */
779 GetColormapWindows(wwin);
782 *--------------------------------------------------
784 * Setup the decoration/window attributes and
785 * geometry
787 *--------------------------------------------------
790 wWindowSetupInitialAttributes(wwin, &window_level, &workspace);
792 #ifdef OLWM_HINTS
793 if (wwin->client_flags.olwm_transient && wwin->transient_for==None
794 && wwin->group_id != None && wwin->group_id != window) {
796 transientOwner = wWindowFor(wwin->group_id);
798 if (transientOwner) {
799 wwin->transient_for = wwin->group_id;
801 /* transients can't be iconified or maximized */
802 if (wwin->transient_for) {
803 WSETUFLAG(wwin, no_miniaturizable, 1);
804 WSETUFLAG(wwin, no_miniaturize_button, 1);
808 #endif /* OLWM_HINTS */
810 /* Make broken apps behave as a nice app. */
811 if (WFLAGP(wwin, emulate_appicon)) {
812 wwin->main_window = wwin->client_win;
815 wwin->orig_main_window = wwin->main_window;
817 if (wwin->flags.is_gnustep) {
818 WSETUFLAG(wwin, shared_appicon, 0);
821 if (wwin->main_window) {
822 extern Atom _XA_WINDOWMAKER_MENU;
823 XTextProperty text_prop;
825 if (XGetTextProperty(dpy, wwin->main_window, &text_prop,
826 _XA_WINDOWMAKER_MENU)) {
827 WSETUFLAG(wwin, shared_appicon, 0);
831 if (!withdraw && wwin->main_window && WFLAGP(wwin, shared_appicon)) {
832 char *buffer, *instance, *class;
833 WFakeGroupLeader *fPtr;
834 int index;
836 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
839 PropGetWMClass(wwin->main_window, &class, &instance);
840 buffer = StrConcatDot(instance, class);
842 index = WMFindInArray(scr->fakeGroupLeaders, matchIdentifier, (void*)buffer);
843 if (index != WANotFound) {
844 fPtr = WMGetFromArray(scr->fakeGroupLeaders, index);
845 if (fPtr->retainCount == 0) {
846 fPtr->leader = createFakeWindowGroupLeader(scr, wwin->main_window,
847 instance, class);
849 fPtr->retainCount++;
850 #undef method2
851 if (fPtr->origLeader==None) {
852 #ifdef method2
853 if (ADEQUATE(wwin->group_id)) {
854 fPtr->retainCount++;
855 fPtr->origLeader = wwin->group_id;
856 } else if (ADEQUATE(wwin->client_leader)) {
857 fPtr->retainCount++;
858 fPtr->origLeader = wwin->client_leader;
859 } else if (ADEQUATE(wwin->main_window)) {
860 fPtr->retainCount++;
861 fPtr->origLeader = wwin->main_window;
863 #else
864 if (ADEQUATE(wwin->main_window)) {
865 fPtr->retainCount++;
866 fPtr->origLeader = wwin->main_window;
868 #endif
870 wwin->fake_group = fPtr;
871 /*wwin->group_id = fPtr->leader;*/
872 wwin->main_window = fPtr->leader;
873 wfree(buffer);
874 } else {
875 fPtr = (WFakeGroupLeader*)wmalloc(sizeof(WFakeGroupLeader));
877 fPtr->identifier = buffer;
878 fPtr->leader = createFakeWindowGroupLeader(scr, wwin->main_window,
879 instance, class);
880 fPtr->origLeader = None;
881 fPtr->retainCount = 1;
883 WMAddToArray(scr->fakeGroupLeaders, fPtr);
885 #ifdef method2
886 if (ADEQUATE(wwin->group_id)) {
887 fPtr->retainCount++;
888 fPtr->origLeader = wwin->group_id;
889 } else if (ADEQUATE(wwin->client_leader)) {
890 fPtr->retainCount++;
891 fPtr->origLeader = wwin->client_leader;
892 } else if (ADEQUATE(wwin->main_window)) {
893 fPtr->retainCount++;
894 fPtr->origLeader = wwin->main_window;
896 #else
897 if (ADEQUATE(wwin->main_window)) {
898 fPtr->retainCount++;
899 fPtr->origLeader = wwin->main_window;
901 #endif
902 wwin->fake_group = fPtr;
903 /*wwin->group_id = fPtr->leader;*/
904 wwin->main_window = fPtr->leader;
906 if (instance)
907 XFree(instance);
908 if (class)
909 XFree(class);
911 #undef method2
912 #undef ADEQUATE
916 *------------------------------------------------------------
918 * Setup the initial state of the window
920 *------------------------------------------------------------
923 if (WFLAGP(wwin, start_miniaturized) && !WFLAGP(wwin, no_miniaturizable)) {
924 wwin->flags.miniaturized = 1;
927 if (WFLAGP(wwin, start_maximized) && !WFLAGP(wwin, no_resizable)) {
928 wwin->flags.maximized = MAX_VERTICAL|MAX_HORIZONTAL;
932 Bool bla;
934 bla = False;
935 #ifdef GNOME_STUFF
936 bla = wGNOMECheckInitialClientState(wwin);
937 #endif
938 #ifdef KWM_HINTS
939 if (!bla)
940 wKWMCheckClientInitialState(wwin);
941 #endif
944 /* apply previous state if it exists and we're in startup */
945 if (scr->flags.startup && wm_state >= 0) {
947 if (wm_state == IconicState) {
949 wwin->flags.miniaturized = 1;
951 } else if (wm_state == WithdrawnState) {
953 withdraw = True;
957 /* if there is a saved state (from file), restore it */
958 win_state = NULL;
959 if (wwin->main_window!=None/* && wwin->main_window!=window*/) {
960 win_state = (WWindowState*)wWindowGetSavedState(wwin->main_window);
961 } else {
962 win_state = (WWindowState*)wWindowGetSavedState(window);
964 if (win_state && !withdraw) {
966 if (win_state->state->hidden>0)
967 wwin->flags.hidden = win_state->state->hidden;
969 if (win_state->state->shaded>0 && !WFLAGP(wwin, no_shadeable))
970 wwin->flags.shaded = win_state->state->shaded;
972 if (win_state->state->miniaturized>0 &&
973 !WFLAGP(wwin, no_miniaturizable)) {
974 wwin->flags.miniaturized = win_state->state->miniaturized;
977 if (!IS_OMNIPRESENT(wwin)) {
978 int w = wDefaultGetStartWorkspace(scr, wwin->wm_instance,
979 wwin->wm_class);
980 if (w < 0 || w >= scr->workspace_count) {
981 workspace = win_state->state->workspace;
982 if (workspace >= scr->workspace_count)
983 workspace = scr->current_workspace;
984 } else {
985 workspace = w;
987 } else {
988 workspace = scr->current_workspace;
992 /* if we're restarting, restore saved state (from hints).
993 * This will overwrite previous */
995 WSavedState *wstate;
997 if (getSavedState(window, &wstate)) {
998 wwin->flags.shaded = wstate->shaded;
999 wwin->flags.hidden = wstate->hidden;
1000 wwin->flags.miniaturized = wstate->miniaturized;
1001 wwin->flags.maximized = wstate->maximized;
1002 if (wwin->flags.maximized) {
1003 wwin->old_geometry.x = wstate->x;
1004 wwin->old_geometry.y = wstate->y;
1005 wwin->old_geometry.width = wstate->w;
1006 wwin->old_geometry.height = wstate->h;
1009 workspace = wstate->workspace;
1010 } else {
1011 wstate = NULL;
1014 /* restore window shortcut */
1015 if (wstate != NULL || win_state != NULL) {
1016 unsigned mask = 0;
1018 if (win_state != NULL)
1019 mask = win_state->state->window_shortcuts;
1021 if (wstate != NULL && mask == 0)
1022 mask = wstate->window_shortcuts;
1024 if (mask > 0) {
1025 int i;
1027 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
1028 if (mask & (1<<i)) {
1029 if (!scr->shortcutWindows[i])
1030 scr->shortcutWindows[i] = WMCreateArray(4);
1032 WMAddToArray(scr->shortcutWindows[i], wwin);
1037 if (wstate != NULL) {
1038 wfree(wstate);
1042 /* don't let transients start miniaturized if their owners are not */
1043 if (transientOwner && !transientOwner->flags.miniaturized
1044 && wwin->flags.miniaturized && !withdraw) {
1045 wwin->flags.miniaturized = 0;
1046 if (wwin->wm_hints)
1047 wwin->wm_hints->initial_state = NormalState;
1050 /* set workspace on which the window starts */
1051 if (workspace >= 0) {
1052 if (workspace > scr->workspace_count-1) {
1053 workspace = workspace % scr->workspace_count;
1055 } else {
1056 int w;
1058 w = wDefaultGetStartWorkspace(scr, wwin->wm_instance, wwin->wm_class);
1060 if (w >= 0 && w < scr->workspace_count && !(IS_OMNIPRESENT(wwin))) {
1062 workspace = w;
1064 } else {
1065 if (wPreferences.open_transients_with_parent && transientOwner) {
1067 workspace = transientOwner->frame->workspace;
1069 } else {
1071 workspace = scr->current_workspace;
1076 /* setup window geometry */
1077 if (win_state && win_state->state->w > 0) {
1078 width = win_state->state->w;
1079 height = win_state->state->h;
1081 wWindowConstrainSize(wwin, &width, &height);
1083 /* do not ask for window placement if the window is
1084 * transient, during startup, if the initial workspace is another one
1085 * or if the window wants to start iconic.
1086 * If geometry was saved, restore it. */
1088 Bool dontBring = False;
1090 if (win_state && win_state->state->w > 0) {
1091 x = win_state->state->x;
1092 y = win_state->state->y;
1093 } else if ((wwin->transient_for==None
1094 || wPreferences.window_placement!=WPM_MANUAL)
1095 && !scr->flags.startup
1096 && workspace == scr->current_workspace
1097 && !wwin->flags.miniaturized
1098 && !wwin->flags.maximized
1099 && !(wwin->normal_hints->flags & (USPosition|PPosition))) {
1101 if (transientOwner && transientOwner->flags.mapped) {
1102 int offs = WMAX(20, 2*transientOwner->frame->top_width);
1103 WMRect rect;
1104 int head;
1106 x = transientOwner->frame_x +
1107 abs((transientOwner->frame->core->width - width)/2) + offs;
1108 y = transientOwner->frame_y +
1109 abs((transientOwner->frame->core->height - height)/3) + offs;
1112 * limit transient windows to be inside their parent's head
1114 rect.pos.x = transientOwner->frame_x;
1115 rect.pos.y = transientOwner->frame_y;
1116 rect.size.width = transientOwner->frame->core->width;
1117 rect.size.height = transientOwner->frame->core->height;
1119 head = wGetHeadForRect(scr, rect);
1120 rect = wGetRectForHead(scr, head);
1122 if (x < rect.pos.x)
1123 x = rect.pos.x;
1124 else if (x + width > rect.pos.x + rect.size.width)
1125 x = rect.pos.x + rect.size.width - width;
1127 if (y < rect.pos.y)
1128 y = rect.pos.y;
1129 else if (y + height > rect.pos.y + rect.size.height)
1130 y = rect.pos.y + rect.size.height - height;
1132 } else {
1133 PlaceWindow(wwin, &x, &y, width, height);
1135 if (wPreferences.window_placement == WPM_MANUAL) {
1136 dontBring = True;
1138 } else if (scr->xine_info.count &&
1139 (wwin->normal_hints->flags & PPosition)) {
1140 int head, flags;
1141 WMRect rect;
1142 int reposition = 0;
1145 * Make spash screens come out in the center of a head
1146 * trouble is that most splashies never get here
1147 * they are managed trough atoms but god knows where.
1148 * Dan, do you know ?
1150 * Most of them are not managed, they are set
1151 * OverrideRedirect, which means we can't do anything about
1152 * them. -alfredo
1154 #if 0
1155 printf( "xinerama PPosition: x: %d %d\n", x, (scr->scr_width - width)/2);
1156 printf( "xinerama PPosition: y: %d %d\n", y, (scr->scr_height - height)/2);
1158 if ( (unsigned)(x + (width - scr->scr_width)/2 + 10) < 20 &&
1159 (unsigned)(y + (height - scr->scr_height)/2 + 10) < 20) {
1161 reposition = 1;
1163 } else
1164 #endif
1167 * xinerama checks for: across head and dead space
1169 rect.pos.x = x;
1170 rect.pos.y = y;
1171 rect.size.width = width;
1172 rect.size.height = height;
1174 head = wGetRectPlacementInfo(scr, rect, &flags);
1176 if (flags & XFLAG_DEAD)
1177 reposition = 1;
1179 if (flags & XFLAG_MULTIPLE)
1180 reposition = 2;
1183 switch (reposition) {
1184 case 1:
1185 head = wGetHeadForPointerLocation(scr);
1186 rect = wGetRectForHead(scr, head);
1188 x = rect.pos.x + (x * rect.size.width)/scr->scr_width;
1189 y = rect.pos.y + (y * rect.size.height)/scr->scr_height;
1190 break;
1192 case 2:
1193 rect = wGetRectForHead(scr, head);
1195 if (x < rect.pos.x)
1196 x = rect.pos.x;
1197 else if (x + width > rect.pos.x + rect.size.width)
1198 x = rect.pos.x + rect.size.width - width;
1200 if (y < rect.pos.y)
1201 y = rect.pos.y;
1202 else if (y + height > rect.pos.y + rect.size.height)
1203 y = rect.pos.y + rect.size.height - height;
1205 break;
1207 default:
1208 break;
1212 if (WFLAGP(wwin, dont_move_off) && dontBring)
1213 wScreenBringInside(scr, &x, &y, width, height);
1216 if (wwin->flags.urgent) {
1217 if (!IS_OMNIPRESENT(wwin))
1218 wwin->flags.omnipresent ^= 1;
1222 *--------------------------------------------------
1224 * Create frame, borders and do reparenting
1226 *--------------------------------------------------
1228 foo = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
1229 #ifdef XKB_BUTTON_HINT
1230 if (wPreferences.modelock)
1231 foo |= WFF_LANGUAGE_BUTTON;
1232 #endif
1233 if (!WFLAGP(wwin, no_titlebar))
1234 foo |= WFF_TITLEBAR;
1235 if (!WFLAGP(wwin, no_resizebar))
1236 foo |= WFF_RESIZEBAR;
1237 if (!WFLAGP(wwin, no_border))
1238 foo |= WFF_BORDER;
1240 wwin->frame = wFrameWindowCreate(scr, window_level,
1241 x, y, width, height,
1242 &wPreferences.window_title_clearance, foo,
1243 scr->window_title_texture,
1244 scr->resizebar_texture,
1245 scr->window_title_color,
1246 &scr->title_font);
1248 wwin->frame->flags.is_client_window_frame = 1;
1249 wwin->frame->flags.justification = wPreferences.title_justification;
1251 /* setup button images */
1252 wWindowUpdateButtonImages(wwin);
1254 /* hide unused buttons */
1255 foo = 0;
1256 if (WFLAGP(wwin, no_close_button))
1257 foo |= WFF_RIGHT_BUTTON;
1258 if (WFLAGP(wwin, no_miniaturize_button))
1259 foo |= WFF_LEFT_BUTTON;
1260 #ifdef XKB_BUTTON_HINT
1261 if (WFLAGP(wwin, no_language_button) || WFLAGP(wwin, no_focusable))
1262 foo |= WFF_LANGUAGE_BUTTON;
1263 #endif
1264 if (foo!=0)
1265 wFrameWindowHideButton(wwin->frame, foo);
1267 wwin->frame->child = wwin;
1269 #ifdef OLWM_HINTS
1270 /* emulate olwm push pin. Make the button look as pushed-in for
1271 * the pinned-out state. When the button is clicked, it will
1272 * revert to the normal position, which means the pin is pinned-in.
1274 if (wwin->flags.olwm_push_pin_out)
1275 wFrameWindowUpdatePushButton(wwin->frame, True);
1276 #endif /* OLWM_HINTS */
1279 wwin->frame->workspace = workspace;
1281 wwin->frame->on_click_left = windowIconifyClick;
1282 #ifdef XKB_BUTTON_HINT
1283 if (wPreferences.modelock)
1284 wwin->frame->on_click_language = windowLanguageClick;
1285 #endif
1287 wwin->frame->on_click_right = windowCloseClick;
1288 wwin->frame->on_dblclick_right = windowCloseDblClick;
1290 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1291 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1293 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1296 XSelectInput(dpy, wwin->client_win,
1297 wwin->event_mask & ~StructureNotifyMask);
1299 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1300 0, wwin->frame->top_width);
1302 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1306 int gx, gy;
1308 wClientGetGravityOffsets(wwin, &gx, &gy);
1310 /* if gravity is to the south, account for the border sizes */
1311 if (gy > 0)
1312 y -= wwin->frame->top_width + wwin->frame->bottom_width;
1316 * wWindowConfigure() will init the client window's size
1317 * (wwin->client.{width,height}) and all other geometry
1318 * related variables (frame_x,frame_y)
1320 wWindowConfigure(wwin, x, y, width, height);
1322 /* to make sure the window receives it's new position after reparenting */
1323 wWindowSynthConfigureNotify(wwin);
1326 *--------------------------------------------------
1328 * Setup descriptors and save window to internal
1329 * lists
1331 *--------------------------------------------------
1334 if (wwin->main_window!=None) {
1335 WApplication *app;
1336 WWindow *leader;
1338 /* Leader windows do not necessary set themselves as leaders.
1339 * If this is the case, point the leader of this window to
1340 * itself */
1341 leader = wWindowFor(wwin->main_window);
1342 if (leader && leader->main_window==None) {
1343 leader->main_window = leader->client_win;
1345 app = wApplicationCreate(scr, wwin->main_window);
1346 if (app) {
1347 app->last_workspace = workspace;
1349 app->main_window_desc->fake_group = wwin->fake_group;
1352 * Do application specific stuff, like setting application
1353 * wide attributes.
1356 if (wwin->flags.hidden) {
1357 /* if the window was set to hidden because it was hidden
1358 * in a previous incarnation and that state was restored */
1359 app->flags.hidden = 1;
1360 } else if (app->flags.hidden) {
1361 if (WFLAGP(app->main_window_desc, start_hidden)) {
1362 wwin->flags.hidden = 1;
1363 } else {
1364 wUnhideApplication(app, False, False);
1365 raise = True;
1371 /* setup the frame descriptor */
1372 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1373 wwin->frame->core->descriptor.parent = wwin;
1374 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1376 /* don't let windows go away if we die */
1377 XAddToSaveSet(dpy, window);
1379 XLowerWindow(dpy, window);
1381 /* if window is in this workspace and should be mapped, then map it */
1382 if (!wwin->flags.miniaturized
1383 && (workspace == scr->current_workspace || IS_OMNIPRESENT(wwin))
1384 && !wwin->flags.hidden && !withdraw) {
1386 /* The following "if" is to avoid crashing of clients that expect
1387 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1388 * after the return from this function.
1390 if (wwin->wm_hints && (wwin->wm_hints->flags & StateHint)) {
1391 wClientSetState(wwin, wwin->wm_hints->initial_state, None);
1392 } else {
1393 wClientSetState(wwin, NormalState, None);
1396 #if 0
1397 /* if not auto focus, then map the window under the currently
1398 * focused window */
1399 #define _WIDTH(w) (w)->frame->core->width
1400 #define _HEIGHT(w) (w)->frame->core->height
1401 if (!wPreferences.auto_focus && scr->focused_window
1402 && !scr->flags.startup && !transientOwner
1403 && ((wWindowObscuresWindow(wwin, scr->focused_window)
1404 && (_WIDTH(wwin) > (_WIDTH(scr->focused_window)*5)/3
1405 || _HEIGHT(wwin) > (_HEIGHT(scr->focused_window)*5)/3)
1406 && WINDOW_LEVEL(scr->focused_window) == WINDOW_LEVEL(wwin))
1407 || wwin->flags.maximized)) {
1408 MoveInStackListUnder(scr->focused_window->frame->core,
1409 wwin->frame->core);
1411 #undef _WIDTH
1412 #undef _HEIGHT
1414 #endif
1416 if (wPreferences.superfluous && !wPreferences.no_animations
1417 && !scr->flags.startup &&
1418 (wwin->transient_for==None || wwin->transient_for==scr->root_win)
1420 * The brain damaged idiotic non-click to focus modes will
1421 * have trouble with this because:
1423 * 1. window is created and mapped by the client
1424 * 2. window is mapped by wmaker in small size
1425 * 3. window is animated to grow to normal size
1426 * 4. this function returns to normal event loop
1427 * 5. eventually, the EnterNotify event that would trigger
1428 * the window focusing (if the mouse is over that window)
1429 * will be processed by wmaker.
1430 * But since this event will be rather delayed
1431 * (step 3 has a large delay) the time when the event ocurred
1432 * and when it is processed, the client that owns that window
1433 * will reject the XSetInputFocus() for it.
1435 && (wPreferences.focus_mode==WKF_CLICK
1436 || wPreferences.auto_focus)) {
1437 DoWindowBirth(wwin);
1440 wWindowMap(wwin);
1443 /* setup stacking descriptor */
1444 if (transientOwner) {
1445 wwin->frame->core->stacking->child_of = transientOwner->frame->core;
1446 } else {
1447 wwin->frame->core->stacking->child_of = NULL;
1451 if (!scr->focused_window) {
1452 /* first window on the list */
1453 wwin->next = NULL;
1454 wwin->prev = NULL;
1455 scr->focused_window = wwin;
1456 } else {
1457 WWindow *tmp;
1459 /* add window at beginning of focus window list */
1460 tmp = scr->focused_window;
1461 while (tmp->prev)
1462 tmp = tmp->prev;
1463 tmp->prev = wwin;
1464 wwin->next = tmp;
1465 wwin->prev = NULL;
1468 /* raise is set to true if we un-hid the app when this window was born.
1469 * we raise, else old windows of this app will be above this new one. */
1470 if (raise) {
1471 wRaiseFrame(wwin->frame->core);
1474 /* Update name must come after WApplication stuff is done */
1475 wWindowUpdateName(wwin, title);
1476 if (title)
1477 XFree(title);
1479 XUngrabServer(dpy);
1482 *--------------------------------------------------
1484 * Final preparations before window is ready to go
1486 *--------------------------------------------------
1489 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1492 if (!wwin->flags.miniaturized && workspace == scr->current_workspace
1493 && !wwin->flags.hidden) {
1494 if (((transientOwner && transientOwner->flags.focused)
1495 || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable))
1496 wSetFocusTo(scr, wwin);
1498 wWindowResetMouseGrabs(wwin);
1500 if (!WFLAGP(wwin, no_bind_keys)) {
1501 wWindowSetKeyGrabs(wwin);
1505 WMPostNotificationName(WMNManaged, wwin, NULL);
1508 wColormapInstallForWindow(scr, scr->cmap_window);
1511 #ifdef OLWM_HINTS
1512 if (wwin->client_flags.olwm_warp_to_pin && wwin->frame->titlebar != NULL
1513 && !WFLAGP(wwin, no_close_button) && !withdraw) {
1515 XWarpPointer(dpy, None, None, 0, 0, 0, 0,
1516 wwin->frame_x + width - wwin->frame->titlebar->height * 2,
1517 wwin->frame_y);
1519 #endif
1522 *------------------------------------------------------------
1523 * Setup Notification Observers
1524 *------------------------------------------------------------
1526 WMAddNotificationObserver(appearanceObserver, wwin,
1527 WNWindowAppearanceSettingsChanged, wwin);
1531 *--------------------------------------------------
1533 * Cleanup temporary stuff
1535 *--------------------------------------------------
1538 if (win_state)
1539 wWindowDeleteSavedState(win_state);
1541 /* If the window must be withdrawed, then do it now.
1542 * Must do some optimization, 'though */
1543 if (withdraw) {
1544 wwin->flags.mapped = 0;
1545 wClientSetState(wwin, WithdrawnState, None);
1546 wUnmanageWindow(wwin, True, False);
1547 wwin = NULL;
1550 return wwin;
1557 WWindow*
1558 wManageInternalWindow(WScreen *scr, Window window, Window owner,
1559 char *title, int x, int y, int width, int height)
1561 WWindow *wwin;
1562 int foo;
1564 wwin = wWindowCreate();
1566 WMAddNotificationObserver(appearanceObserver, wwin,
1567 WNWindowAppearanceSettingsChanged, wwin);
1569 wwin->flags.internal_window = 1;
1571 WSETUFLAG(wwin, omnipresent, 1);
1572 WSETUFLAG(wwin, no_shadeable, 1);
1573 WSETUFLAG(wwin, no_resizable, 1);
1574 WSETUFLAG(wwin, no_miniaturizable, 1);
1576 wwin->focus_mode = WFM_PASSIVE;
1578 wwin->client_win = window;
1579 wwin->screen_ptr = scr;
1581 wwin->transient_for = owner;
1583 wwin->client.x = x;
1584 wwin->client.y = y;
1585 wwin->client.width = width;
1586 wwin->client.height = height;
1588 wwin->frame_x = wwin->client.x;
1589 wwin->frame_y = wwin->client.y;
1592 foo = WFF_RIGHT_BUTTON|WFF_BORDER;
1593 foo |= WFF_TITLEBAR;
1594 #ifdef XKB_BUTTON_HINT
1595 foo |= WFF_LANGUAGE_BUTTON;
1596 #endif
1598 wwin->frame = wFrameWindowCreate(scr, WMFloatingLevel,
1599 wwin->frame_x, wwin->frame_y,
1600 width, height,
1601 &wPreferences.window_title_clearance, foo,
1602 scr->window_title_texture,
1603 scr->resizebar_texture,
1604 scr->window_title_color,
1605 &scr->title_font);
1607 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
1609 wwin->frame->flags.is_client_window_frame = 1;
1610 wwin->frame->flags.justification = wPreferences.title_justification;
1612 wFrameWindowChangeTitle(wwin->frame, title);
1614 /* setup button images */
1615 wWindowUpdateButtonImages(wwin);
1617 /* hide buttons */
1618 wFrameWindowHideButton(wwin->frame, WFF_RIGHT_BUTTON);
1620 wwin->frame->child = wwin;
1622 wwin->frame->workspace = wwin->screen_ptr->current_workspace;
1624 #ifdef XKB_BUTTON_HINT
1625 if (wPreferences.modelock)
1626 wwin->frame->on_click_language = windowLanguageClick;
1627 #endif
1629 wwin->frame->on_click_right = windowCloseClick;
1631 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1632 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1634 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1636 wwin->client.y += wwin->frame->top_width;
1637 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1638 0, wwin->frame->top_width);
1640 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y,
1641 wwin->client.width, wwin->client.height);
1643 /* setup the frame descriptor */
1644 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1645 wwin->frame->core->descriptor.parent = wwin;
1646 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1649 XLowerWindow(dpy, window);
1650 XMapSubwindows(dpy, wwin->frame->core->window);
1652 /* setup stacking descriptor */
1653 if (wwin->transient_for!=None && wwin->transient_for!=scr->root_win) {
1654 WWindow *tmp;
1655 tmp = wWindowFor(wwin->transient_for);
1656 if (tmp)
1657 wwin->frame->core->stacking->child_of = tmp->frame->core;
1658 } else {
1659 wwin->frame->core->stacking->child_of = NULL;
1663 if (!scr->focused_window) {
1664 /* first window on the list */
1665 wwin->next = NULL;
1666 wwin->prev = NULL;
1667 scr->focused_window = wwin;
1668 } else {
1669 WWindow *tmp;
1671 /* add window at beginning of focus window list */
1672 tmp = scr->focused_window;
1673 while (tmp->prev)
1674 tmp = tmp->prev;
1675 tmp->prev = wwin;
1676 wwin->next = tmp;
1677 wwin->prev = NULL;
1680 if (wwin->flags.is_gnustep == 0)
1681 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1683 /* if (wPreferences.auto_focus)*/
1684 wSetFocusTo(scr, wwin);
1686 wWindowResetMouseGrabs(wwin);
1688 wWindowSetKeyGrabs(wwin);
1690 return wwin;
1695 *----------------------------------------------------------------------
1696 * wUnmanageWindow--
1697 * Removes the frame window from a window and destroys all data
1698 * related to it. The window will be reparented back to the root window
1699 * if restore is True.
1701 * Side effects:
1702 * Everything related to the window is destroyed and the window
1703 * is removed from the window lists. Focus is set to the previous on the
1704 * window list.
1705 *----------------------------------------------------------------------
1707 void
1708 wUnmanageWindow(WWindow *wwin, Bool restore, Bool destroyed)
1710 WCoreWindow *frame = wwin->frame->core;
1711 WWindow *owner = NULL;
1712 WWindow *newFocusedWindow = NULL;
1713 int wasFocused;
1714 WScreen *scr = wwin->screen_ptr;
1717 /* First close attribute editor window if open */
1718 if (wwin->flags.inspector_open) {
1719 wCloseInspectorForWindow(wwin);
1722 /* Close window menu if it's open for this window */
1723 if (wwin->flags.menu_open_for_me) {
1724 CloseWindowMenu(scr);
1727 if (!destroyed) {
1728 if (!wwin->flags.internal_window)
1729 XRemoveFromSaveSet(dpy, wwin->client_win);
1731 XSelectInput(dpy, wwin->client_win, NoEventMask);
1733 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
1734 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->client_win);
1737 XUnmapWindow(dpy, frame->window);
1739 XUnmapWindow(dpy, wwin->client_win);
1741 /* deselect window */
1742 wSelectWindow(wwin, False);
1744 /* remove all pending events on window */
1745 /* I think this only matters for autoraise */
1746 if (wPreferences.raise_delay)
1747 WMDeleteTimerWithClientData(wwin->frame->core);
1749 XFlush(dpy);
1751 /* reparent the window back to the root */
1752 if (restore)
1753 wClientRestore(wwin);
1755 if (wwin->transient_for!=scr->root_win) {
1756 owner = wWindowFor(wwin->transient_for);
1757 if (owner) {
1758 if (!owner->flags.semi_focused) {
1759 owner = NULL;
1760 } else {
1761 owner->flags.semi_focused = 0;
1766 wasFocused = wwin->flags.focused;
1768 /* remove from window focus list */
1769 if (!wwin->prev && !wwin->next) {
1770 /* was the only window */
1771 scr->focused_window = NULL;
1772 newFocusedWindow = NULL;
1773 } else {
1774 WWindow *tmp;
1776 if (wwin->prev)
1777 wwin->prev->next = wwin->next;
1778 if (wwin->next)
1779 wwin->next->prev = wwin->prev;
1780 else {
1781 scr->focused_window = wwin->prev;
1782 scr->focused_window->next = NULL;
1785 if (wPreferences.focus_mode==WKF_CLICK) {
1787 /* if in click to focus mode and the window
1788 * was a transient, focus the owner window
1790 tmp = NULL;
1791 if (wPreferences.focus_mode==WKF_CLICK) {
1792 tmp = wWindowFor(wwin->transient_for);
1793 if (tmp && (!tmp->flags.mapped || WFLAGP(tmp, no_focusable))) {
1794 tmp = NULL;
1797 /* otherwise, focus the next one in the focus list */
1798 if (!tmp) {
1799 tmp = scr->focused_window;
1800 while (tmp) { /* look for one in the window list first */
1801 if (!WFLAGP(tmp, no_focusable) && !WFLAGP(tmp, skip_window_list)
1802 && (tmp->flags.mapped || tmp->flags.shaded))
1803 break;
1804 tmp = tmp->prev;
1806 if (!tmp) { /* if unsuccessful, choose any focusable window */
1807 tmp = scr->focused_window;
1808 while (tmp) {
1809 if (!WFLAGP(tmp, no_focusable)
1810 && (tmp->flags.mapped || tmp->flags.shaded))
1811 break;
1812 tmp = tmp->prev;
1817 newFocusedWindow = tmp;
1819 } else if (wPreferences.focus_mode==WKF_SLOPPY) {
1820 unsigned int mask;
1821 int foo;
1822 Window bar, win;
1824 /* This is to let the root window get the keyboard input
1825 * if Sloppy focus mode and no other window get focus.
1826 * This way keybindings will not freeze.
1828 tmp = NULL;
1829 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
1830 &foo, &foo, &foo, &foo, &mask))
1831 tmp = wWindowFor(win);
1832 if (tmp == wwin)
1833 tmp = NULL;
1834 newFocusedWindow = tmp;
1835 } else {
1836 newFocusedWindow = NULL;
1840 if (!wwin->flags.internal_window) {
1841 WMPostNotificationName(WMNUnmanaged, wwin, NULL);
1844 #ifdef DEBUG
1845 printf("destroying window %x frame %x\n", (unsigned)wwin->client_win,
1846 (unsigned)frame->window);
1847 #endif
1849 if (wasFocused) {
1850 if (newFocusedWindow != owner && owner) {
1851 if (wwin->flags.is_gnustep == 0)
1852 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1854 wSetFocusTo(scr, newFocusedWindow);
1856 wWindowDestroy(wwin);
1857 XFlush(dpy);
1861 void
1862 wWindowMap(WWindow *wwin)
1864 XMapWindow(dpy, wwin->frame->core->window);
1865 if (!wwin->flags.shaded) {
1866 /* window will be remapped when getting MapNotify */
1867 XSelectInput(dpy, wwin->client_win,
1868 wwin->event_mask & ~StructureNotifyMask);
1869 XMapWindow(dpy, wwin->client_win);
1870 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1872 wwin->flags.mapped = 1;
1877 void
1878 wWindowUnmap(WWindow *wwin)
1880 wwin->flags.mapped = 0;
1882 /* prevent window withdrawal when getting UnmapNotify */
1883 XSelectInput(dpy, wwin->client_win,
1884 wwin->event_mask & ~StructureNotifyMask);
1885 XUnmapWindow(dpy, wwin->client_win);
1886 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1888 XUnmapWindow(dpy, wwin->frame->core->window);
1893 void
1894 wWindowFocus(WWindow *wwin, WWindow *owin)
1896 WWindow *nowner;
1897 WWindow *oowner;
1899 #ifdef KEEP_XKB_LOCK_STATUS
1900 if (wPreferences.modelock) {
1901 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1903 #endif /* KEEP_XKB_LOCK_STATUS */
1905 wwin->flags.semi_focused = 0;
1907 if (wwin->flags.is_gnustep == 0)
1908 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1910 wwin->flags.focused = 1;
1912 wWindowResetMouseGrabs(wwin);
1914 WMPostNotificationName(WMNChangedFocus, wwin, (void*)True);
1916 if (owin == wwin || !owin)
1917 return;
1919 nowner = wWindowFor(wwin->transient_for);
1921 /* new window is a transient for the old window */
1922 if (nowner == owin) {
1923 owin->flags.semi_focused = 1;
1924 wWindowUnfocus(nowner);
1925 return;
1928 oowner = wWindowFor(owin->transient_for);
1930 /* new window is owner of old window */
1931 if (wwin == oowner) {
1932 wWindowUnfocus(owin);
1933 return;
1936 if (!nowner) {
1937 wWindowUnfocus(owin);
1938 return;
1941 /* new window has same owner of old window */
1942 if (oowner == nowner) {
1943 /* prevent unfocusing of owner */
1944 oowner->flags.semi_focused = 0;
1945 wWindowUnfocus(owin);
1946 oowner->flags.semi_focused = 1;
1948 return;
1951 /* nowner != NULL && oowner != nowner */
1952 nowner->flags.semi_focused = 1;
1953 wWindowUnfocus(nowner);
1954 wWindowUnfocus(owin);
1958 void
1959 wWindowUnfocus(WWindow *wwin)
1961 CloseWindowMenu(wwin->screen_ptr);
1963 if (wwin->flags.is_gnustep == 0)
1964 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused
1965 ? WS_PFOCUSED : WS_UNFOCUSED);
1967 if (wwin->transient_for!=None
1968 && wwin->transient_for!=wwin->screen_ptr->root_win) {
1969 WWindow *owner;
1970 owner = wWindowFor(wwin->transient_for);
1971 if (owner && owner->flags.semi_focused) {
1972 owner->flags.semi_focused = 0;
1973 if (owner->flags.mapped || owner->flags.shaded) {
1974 wWindowUnfocus(owner);
1975 wFrameWindowPaint(owner->frame);
1979 wwin->flags.focused = 0;
1981 wWindowResetMouseGrabs(wwin);
1983 WMPostNotificationName(WMNChangedFocus, wwin, (void*)False);
1987 void
1988 wWindowUpdateName(WWindow *wwin, char *newTitle)
1990 char *title;
1992 if (!wwin->frame)
1993 return;
1995 wwin->flags.wm_name_changed = 1;
1997 if (!newTitle) {
1998 /* the hint was removed */
1999 title = DEF_WINDOW_TITLE;
2000 } else {
2001 title = newTitle;
2004 if (wFrameWindowChangeTitle(wwin->frame, title)) {
2005 WMPostNotificationName(WMNChangedName, wwin, NULL);
2012 *----------------------------------------------------------------------
2014 * wWindowConstrainSize--
2015 * Constrains size for the client window, taking the maximal size,
2016 * window resize increments and other size hints into account.
2018 * Returns:
2019 * The closest size to what was given that the client window can
2020 * have.
2022 *----------------------------------------------------------------------
2024 void
2025 wWindowConstrainSize(WWindow *wwin, int *nwidth, int *nheight)
2027 int width = *nwidth;
2028 int height = *nheight;
2029 int winc = 1;
2030 int hinc = 1;
2031 int minW = 1, minH = 1;
2032 int maxW = wwin->screen_ptr->scr_width*2;
2033 int maxH = wwin->screen_ptr->scr_height*2;
2034 int minAX = -1, minAY = -1;
2035 int maxAX = -1, maxAY = -1;
2036 int baseW = 0;
2037 int baseH = 0;
2039 if (wwin->normal_hints) {
2040 winc = wwin->normal_hints->width_inc;
2041 hinc = wwin->normal_hints->height_inc;
2042 minW = wwin->normal_hints->min_width;
2043 minH = wwin->normal_hints->min_height;
2044 maxW = wwin->normal_hints->max_width;
2045 maxH = wwin->normal_hints->max_height;
2046 if (wwin->normal_hints->flags & PAspect) {
2047 minAX = wwin->normal_hints->min_aspect.x;
2048 minAY = wwin->normal_hints->min_aspect.y;
2049 maxAX = wwin->normal_hints->max_aspect.x;
2050 maxAY = wwin->normal_hints->max_aspect.y;
2053 baseW = wwin->normal_hints->base_width;
2054 baseH = wwin->normal_hints->base_height;
2057 if (width < minW)
2058 width = minW;
2059 if (height < minH)
2060 height = minH;
2062 if (width > maxW)
2063 width = maxW;
2064 if (height > maxH)
2065 height = maxH;
2067 /* aspect ratio code borrowed from olwm */
2068 if (minAX > 0) {
2069 /* adjust max aspect ratio */
2070 if (!(maxAX == 1 && maxAY == 1) && width * maxAY > height * maxAX) {
2071 if (maxAX > maxAY) {
2072 height = (width * maxAY) / maxAX;
2073 if (height > maxH) {
2074 height = maxH;
2075 width = (height * maxAX) / maxAY;
2077 } else {
2078 width = (height * maxAX) / maxAY;
2079 if (width > maxW) {
2080 width = maxW;
2081 height = (width * maxAY) / maxAX;
2086 /* adjust min aspect ratio */
2087 if (!(minAX == 1 && minAY == 1) && width * minAY < height * minAX) {
2088 if (minAX > minAY) {
2089 height = (width * minAY) / minAX;
2090 if (height < minH) {
2091 height = minH;
2092 width = (height * minAX) / minAY;
2094 } else {
2095 width = (height * minAX) / minAY;
2096 if (width < minW) {
2097 width = minW;
2098 height = (width * minAY) / minAX;
2104 if (baseW != 0) {
2105 width = (((width - baseW) / winc) * winc) + baseW;
2106 } else {
2107 width = (((width - minW) / winc) * winc) + minW;
2110 if (baseH != 0) {
2111 height = (((height - baseH) / hinc) * hinc) + baseH;
2112 } else {
2113 height = (((height - minH) / hinc) * hinc) + minH;
2116 /* broken stupid apps may cause preposterous values for these.. */
2117 if (width > 0)
2118 *nwidth = width;
2119 if (height > 0)
2120 *nheight = height;
2124 void
2125 wWindowCropSize(WWindow *wwin, int maxW, int maxH,
2126 int *width, int *height)
2128 int baseW = 0, baseH = 0;
2129 int winc = 1, hinc = 1;
2131 if (wwin->normal_hints) {
2132 baseW = wwin->normal_hints->base_width;
2133 baseH = wwin->normal_hints->base_height;
2135 winc = wwin->normal_hints->width_inc;
2136 hinc = wwin->normal_hints->height_inc;
2139 if (*width > maxW)
2140 *width = maxW - (maxW - baseW) % winc;
2142 if (*height > maxH)
2143 *height = maxH - (maxH - baseH) % hinc;
2147 void
2148 wWindowChangeWorkspace(WWindow *wwin, int workspace)
2150 WScreen *scr = wwin->screen_ptr;
2151 WApplication *wapp;
2152 int unmap = 0;
2154 if (workspace >= scr->workspace_count || workspace < 0
2155 || workspace == wwin->frame->workspace)
2156 return;
2158 if (workspace != scr->current_workspace) {
2159 /* Sent to other workspace. Unmap window */
2160 if ((wwin->flags.mapped
2161 || wwin->flags.shaded
2162 || (wwin->flags.miniaturized && !wPreferences.sticky_icons))
2163 && !IS_OMNIPRESENT(wwin) && !wwin->flags.changing_workspace) {
2165 wapp = wApplicationOf(wwin->main_window);
2166 if (wapp) {
2167 wapp->last_workspace = workspace;
2169 if (wwin->flags.miniaturized) {
2170 if (wwin->icon) {
2171 XUnmapWindow(dpy, wwin->icon->core->window);
2172 wwin->icon->mapped = 0;
2174 } else {
2175 unmap = 1;
2176 wSetFocusTo(scr, NULL);
2179 } else {
2180 /* brought to current workspace. Map window */
2181 if (wwin->flags.miniaturized && !wPreferences.sticky_icons) {
2182 if (wwin->icon) {
2183 XMapWindow(dpy, wwin->icon->core->window);
2184 wwin->icon->mapped = 1;
2186 } else if (!wwin->flags.mapped &&
2187 !(wwin->flags.miniaturized || wwin->flags.hidden)) {
2188 wWindowMap(wwin);
2191 if (!IS_OMNIPRESENT(wwin)) {
2192 int oldWorkspace = wwin->frame->workspace;
2194 wwin->frame->workspace = workspace;
2196 WMPostNotificationName(WMNChangedWorkspace, wwin, (void*)oldWorkspace);
2199 if (unmap) {
2200 wWindowUnmap(wwin);
2205 void
2206 wWindowSynthConfigureNotify(WWindow *wwin)
2208 XEvent sevent;
2210 sevent.type = ConfigureNotify;
2211 sevent.xconfigure.display = dpy;
2212 sevent.xconfigure.event = wwin->client_win;
2213 sevent.xconfigure.window = wwin->client_win;
2215 sevent.xconfigure.x = wwin->client.x;
2216 sevent.xconfigure.y = wwin->client.y;
2217 sevent.xconfigure.width = wwin->client.width;
2218 sevent.xconfigure.height = wwin->client.height;
2220 sevent.xconfigure.border_width = wwin->old_border_width;
2221 if (WFLAGP(wwin, no_titlebar))
2222 sevent.xconfigure.above = None;
2223 else
2224 sevent.xconfigure.above = wwin->frame->titlebar->window;
2226 sevent.xconfigure.override_redirect = False;
2227 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
2228 #ifdef KWM_HINTS
2229 wKWMSendEventMessage(wwin, WKWMChangedClient);
2230 #endif
2231 XFlush(dpy);
2236 *----------------------------------------------------------------------
2237 * wWindowConfigure--
2238 * Configures the frame, decorations and client window to the
2239 * specified geometry. The geometry is not checked for validity,
2240 * wWindowConstrainSize() must be used for that.
2241 * The size parameters are for the client window, but the position is
2242 * for the frame.
2243 * The client window receives a ConfigureNotify event, according
2244 * to what ICCCM says.
2246 * Returns:
2247 * None
2249 * Side effects:
2250 * Window size and position are changed and client window receives
2251 * a ConfigureNotify event.
2252 *----------------------------------------------------------------------
2254 void
2255 wWindowConfigure(wwin, req_x, req_y, req_width, req_height)
2256 WWindow *wwin;
2257 int req_x, req_y; /* new position of the frame */
2258 int req_width, req_height; /* new size of the client */
2260 int synth_notify = False;
2261 int resize;
2263 resize = (req_width!=wwin->client.width
2264 || req_height!=wwin->client.height);
2266 * if the window is being moved but not resized then
2267 * send a synthetic ConfigureNotify
2269 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y) && !resize) {
2270 synth_notify = True;
2273 if (WFLAGP(wwin, dont_move_off))
2274 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2275 req_width, req_height);
2276 if (resize) {
2277 if (req_width < MIN_WINDOW_SIZE)
2278 req_width = MIN_WINDOW_SIZE;
2279 if (req_height < MIN_WINDOW_SIZE)
2280 req_height = MIN_WINDOW_SIZE;
2282 /* If growing, resize inner part before frame,
2283 * if shrinking, resize frame before.
2284 * This will prevent the frame (that can have a different color)
2285 * to be exposed, causing flicker */
2286 if (req_height > wwin->frame->core->height
2287 || req_width > wwin->frame->core->width)
2288 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2290 if (wwin->flags.shaded) {
2291 wFrameWindowConfigure(wwin->frame, req_x, req_y,
2292 req_width, wwin->frame->core->height);
2293 wwin->old_geometry.height = req_height;
2294 } else {
2295 int h;
2297 h = req_height + wwin->frame->top_width
2298 + wwin->frame->bottom_width;
2300 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, h);
2303 if (!(req_height > wwin->frame->core->height
2304 || req_width > wwin->frame->core->width))
2305 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2307 wwin->client.x = req_x;
2308 wwin->client.y = req_y + wwin->frame->top_width;
2309 wwin->client.width = req_width;
2310 wwin->client.height = req_height;
2311 } else {
2312 wwin->client.x = req_x;
2313 wwin->client.y = req_y + wwin->frame->top_width;
2315 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2317 wwin->frame_x = req_x;
2318 wwin->frame_y = req_y;
2319 if (!WFLAGP(wwin, no_border)) {
2320 wwin->client.x += FRAME_BORDER_WIDTH;
2321 wwin->client.y += FRAME_BORDER_WIDTH;
2324 #ifdef SHAPE
2325 if (wShapeSupported && wwin->flags.shaped && resize) {
2326 wWindowSetShape(wwin);
2328 #endif
2330 if (synth_notify)
2331 wWindowSynthConfigureNotify(wwin);
2332 XFlush(dpy);
2336 void
2337 wWindowMove(wwin, req_x, req_y)
2338 WWindow *wwin;
2339 int req_x, req_y; /* new position of the frame */
2341 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2342 int synth_notify = False;
2344 /* Send a synthetic ConfigureNotify event for every window movement. */
2345 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y)) {
2346 synth_notify = True;
2348 #else
2349 /* A single synthetic ConfigureNotify event is sent at the end of
2350 * a completed (opaque) movement in moveres.c */
2351 #endif
2353 if (WFLAGP(wwin, dont_move_off))
2354 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2355 wwin->frame->core->width, wwin->frame->core->height);
2357 wwin->client.x = req_x;
2358 wwin->client.y = req_y + wwin->frame->top_width;
2359 if (!WFLAGP(wwin, no_border)) {
2360 wwin->client.x += FRAME_BORDER_WIDTH;
2361 wwin->client.y += FRAME_BORDER_WIDTH;
2364 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2366 wwin->frame_x = req_x;
2367 wwin->frame_y = req_y;
2369 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2370 if (synth_notify)
2371 wWindowSynthConfigureNotify(wwin);
2372 #endif
2376 void
2377 wWindowUpdateButtonImages(WWindow *wwin)
2379 WScreen *scr = wwin->screen_ptr;
2380 Pixmap pixmap, mask;
2381 WFrameWindow *fwin = wwin->frame;
2383 if (WFLAGP(wwin, no_titlebar))
2384 return;
2386 /* miniaturize button */
2388 if (!WFLAGP(wwin, no_miniaturize_button)) {
2389 if (wwin->wm_gnustep_attr
2390 && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
2391 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
2393 if (wwin->wm_gnustep_attr->flags&GSMiniaturizeMaskAttr) {
2394 mask = wwin->wm_gnustep_attr->miniaturize_mask;
2395 } else {
2396 mask = None;
2399 if (fwin->lbutton_image
2400 && (fwin->lbutton_image->image != pixmap
2401 || fwin->lbutton_image->mask != mask)) {
2402 wPixmapDestroy(fwin->lbutton_image);
2403 fwin->lbutton_image = NULL;
2406 if (!fwin->lbutton_image) {
2407 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
2408 fwin->lbutton_image->client_owned = 1;
2409 fwin->lbutton_image->client_owned_mask = 1;
2411 } else {
2412 if (fwin->lbutton_image && !fwin->lbutton_image->shared) {
2413 wPixmapDestroy(fwin->lbutton_image);
2415 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
2419 #ifdef XKB_BUTTON_HINT
2420 if (!WFLAGP(wwin, no_language_button)) {
2421 if (fwin->languagebutton_image &&
2422 !fwin->languagebutton_image->shared) {
2423 wPixmapDestroy(fwin->languagebutton_image);
2425 fwin->languagebutton_image =
2426 scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
2428 #endif
2430 /* close button */
2432 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2433 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2435 if (!WFLAGP(wwin, no_close_button)) {
2436 if (wwin->wm_gnustep_attr
2437 && wwin->wm_gnustep_attr->flags & GSClosePixmapAttr) {
2438 pixmap = wwin->wm_gnustep_attr->close_pixmap;
2440 if (wwin->wm_gnustep_attr->flags&GSCloseMaskAttr)
2441 mask = wwin->wm_gnustep_attr->close_mask;
2442 else
2443 mask = None;
2445 if (fwin->rbutton_image && (fwin->rbutton_image->image != pixmap
2446 || fwin->rbutton_image->mask != mask)) {
2447 wPixmapDestroy(fwin->rbutton_image);
2448 fwin->rbutton_image = NULL;
2451 if (!fwin->rbutton_image) {
2452 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
2453 fwin->rbutton_image->client_owned = 1;
2454 fwin->rbutton_image->client_owned_mask = 1;
2457 } else if (WFLAGP(wwin, kill_close)) {
2459 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2460 wPixmapDestroy(fwin->rbutton_image);
2462 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
2464 } else if (MGFLAGP(wwin, broken_close)) {
2466 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2467 wPixmapDestroy(fwin->rbutton_image);
2469 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
2471 } else {
2473 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2474 wPixmapDestroy(fwin->rbutton_image);
2476 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
2480 /* force buttons to be redrawn */
2481 fwin->flags.need_texture_change = 1;
2482 wFrameWindowPaint(fwin);
2487 *---------------------------------------------------------------------------
2488 * wWindowConfigureBorders--
2489 * Update window border configuration according to attribute flags.
2491 *---------------------------------------------------------------------------
2493 void
2494 wWindowConfigureBorders(WWindow *wwin)
2496 if (wwin->frame) {
2497 int flags;
2498 int newy, oldh;
2500 flags = WFF_LEFT_BUTTON|WFF_RIGHT_BUTTON;
2501 #ifdef XKB_BUTTON_HINT
2502 flags |= WFF_LANGUAGE_BUTTON;
2503 #endif
2504 if (!WFLAGP(wwin, no_titlebar))
2505 flags |= WFF_TITLEBAR;
2506 if (!WFLAGP(wwin, no_resizebar) && !WFLAGP(wwin, no_resizable))
2507 flags |= WFF_RESIZEBAR;
2508 if (!WFLAGP(wwin, no_border))
2509 flags |= WFF_BORDER;
2510 if (wwin->flags.shaded)
2511 flags |= WFF_IS_SHADED;
2513 oldh = wwin->frame->top_width;
2514 wFrameWindowUpdateBorders(wwin->frame, flags);
2515 if (oldh != wwin->frame->top_width) {
2516 newy = wwin->frame_y + oldh - wwin->frame->top_width;
2518 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2519 wWindowConfigure(wwin, wwin->frame_x, newy,
2520 wwin->client.width, wwin->client.height);
2523 flags = 0;
2524 if (!WFLAGP(wwin, no_miniaturize_button)
2525 && wwin->frame->flags.hide_left_button)
2526 flags |= WFF_LEFT_BUTTON;
2528 #ifdef XKB_BUTTON_HINT
2529 if (!WFLAGP(wwin, no_language_button)
2530 && wwin->frame->flags.hide_language_button)
2531 flags |= WFF_LANGUAGE_BUTTON;
2532 #endif
2534 if (!WFLAGP(wwin, no_close_button)
2535 && wwin->frame->flags.hide_right_button)
2536 flags |= WFF_RIGHT_BUTTON;
2538 if (flags!=0) {
2539 wWindowUpdateButtonImages(wwin);
2540 wFrameWindowShowButton(wwin->frame, flags);
2543 flags = 0;
2544 if (WFLAGP(wwin, no_miniaturize_button)
2545 && !wwin->frame->flags.hide_left_button)
2546 flags |= WFF_LEFT_BUTTON;
2548 #ifdef XKB_BUTTON_HINT
2549 if (WFLAGP(wwin, no_language_button)
2550 && !wwin->frame->flags.hide_language_button)
2551 flags |= WFF_LANGUAGE_BUTTON;
2552 #endif
2554 if (WFLAGP(wwin, no_close_button)
2555 && !wwin->frame->flags.hide_right_button)
2556 flags |= WFF_RIGHT_BUTTON;
2558 if (flags!=0)
2559 wFrameWindowHideButton(wwin->frame, flags);
2561 #ifdef SHAPE
2562 if (wShapeSupported && wwin->flags.shaped) {
2563 wWindowSetShape(wwin);
2565 #endif
2570 void
2571 wWindowSaveState(WWindow *wwin)
2573 CARD32 data[10];
2574 int i;
2576 memset(data, 0, sizeof(CARD32)*10);
2577 data[0] = wwin->frame->workspace;
2578 data[1] = wwin->flags.miniaturized;
2579 data[2] = wwin->flags.shaded;
2580 data[3] = wwin->flags.hidden;
2581 data[4] = wwin->flags.maximized;
2582 if (wwin->flags.maximized == 0) {
2583 data[5] = wwin->frame_x;
2584 data[6] = wwin->frame_y;
2585 data[7] = wwin->frame->core->width;
2586 data[8] = wwin->frame->core->height;
2587 } else {
2588 data[5] = wwin->old_geometry.x;
2589 data[6] = wwin->old_geometry.y;
2590 data[7] = wwin->old_geometry.width;
2591 data[8] = wwin->old_geometry.height;
2594 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
2595 if (wwin->screen_ptr->shortcutWindows[i] &&
2596 WMCountInArray(wwin->screen_ptr->shortcutWindows[i], wwin))
2597 data[9] |= 1<<i;
2599 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
2600 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
2601 (unsigned char *)data, 10);
2605 static int
2606 getSavedState(Window window, WSavedState **state)
2608 Atom type_ret;
2609 int fmt_ret;
2610 unsigned long nitems_ret;
2611 unsigned long bytes_after_ret;
2612 CARD32 *data;
2614 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
2615 True, _XA_WINDOWMAKER_STATE,
2616 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
2617 (unsigned char **)&data)!=Success || !data)
2618 return 0;
2620 *state = wmalloc(sizeof(WSavedState));
2622 (*state)->workspace = data[0];
2623 (*state)->miniaturized = data[1];
2624 (*state)->shaded = data[2];
2625 (*state)->hidden = data[3];
2626 (*state)->maximized = data[4];
2627 (*state)->x = data[5];
2628 (*state)->y = data[6];
2629 (*state)->w = data[7];
2630 (*state)->h = data[8];
2631 (*state)->window_shortcuts = data[9];
2633 XFree(data);
2635 if (*state && type_ret==_XA_WINDOWMAKER_STATE)
2636 return 1;
2637 else
2638 return 0;
2642 #ifdef SHAPE
2643 void
2644 wWindowClearShape(WWindow *wwin)
2646 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
2647 0, wwin->frame->top_width, None, ShapeSet);
2648 XFlush(dpy);
2651 void
2652 wWindowSetShape(WWindow *wwin)
2654 XRectangle rect[2];
2655 int count;
2656 #ifdef OPTIMIZE_SHAPE
2657 XRectangle *rects;
2658 XRectangle *urec;
2659 int ordering;
2661 /* only shape is the client's */
2662 if (WFLAGP(wwin, no_titlebar) && WFLAGP(wwin, no_resizebar)) {
2663 goto alt_code;
2666 /* Get array of rectangles describing the shape mask */
2667 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding,
2668 &count, &ordering);
2669 if (!rects) {
2670 goto alt_code;
2673 urec = malloc(sizeof(XRectangle)*(count+2));
2674 if (!urec) {
2675 XFree(rects);
2676 goto alt_code;
2679 /* insert our decoration rectangles in the rect list */
2680 memcpy(urec, rects, sizeof(XRectangle)*count);
2681 XFree(rects);
2683 if (!WFLAGP(wwin, no_titlebar)) {
2684 urec[count].x = -1;
2685 urec[count].y = -1 - wwin->frame->top_width;
2686 urec[count].width = wwin->frame->core->width + 2;
2687 urec[count].height = wwin->frame->top_width + 1;
2688 count++;
2690 if (!WFLAGP(wwin, no_resizebar)) {
2691 urec[count].x = -1;
2692 urec[count].y = wwin->frame->core->height
2693 - wwin->frame->bottom_width - wwin->frame->top_width;
2694 urec[count].width = wwin->frame->core->width + 2;
2695 urec[count].height = wwin->frame->bottom_width + 1;
2696 count++;
2699 /* shape our frame window */
2700 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2701 0, wwin->frame->top_width, urec, count,
2702 ShapeSet, Unsorted);
2703 XFlush(dpy);
2704 wfree(urec);
2705 return;
2707 alt_code:
2708 #endif /* OPTIMIZE_SHAPE */
2709 count = 0;
2710 if (!WFLAGP(wwin, no_titlebar)) {
2711 rect[count].x = -1;
2712 rect[count].y = -1;
2713 rect[count].width = wwin->frame->core->width + 2;
2714 rect[count].height = wwin->frame->top_width + 1;
2715 count++;
2717 if (!WFLAGP(wwin, no_resizebar)) {
2718 rect[count].x = -1;
2719 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
2720 rect[count].width = wwin->frame->core->width + 2;
2721 rect[count].height = wwin->frame->bottom_width + 1;
2722 count++;
2724 if (count > 0) {
2725 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2726 0, 0, rect, count, ShapeSet, Unsorted);
2728 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
2729 0, wwin->frame->top_width, wwin->client_win,
2730 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
2731 XFlush(dpy);
2733 #endif /* SHAPE */
2735 /* ====================================================================== */
2737 static FocusMode
2738 getFocusMode(WWindow *wwin)
2740 FocusMode mode;
2742 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
2743 if (wwin->wm_hints->input == True) {
2744 if (wwin->protocols.TAKE_FOCUS)
2745 mode = WFM_LOCALLY_ACTIVE;
2746 else
2747 mode = WFM_PASSIVE;
2748 } else {
2749 if (wwin->protocols.TAKE_FOCUS)
2750 mode = WFM_GLOBALLY_ACTIVE;
2751 else
2752 mode = WFM_NO_INPUT;
2754 } else {
2755 mode = WFM_PASSIVE;
2757 return mode;
2761 void
2762 wWindowSetKeyGrabs(WWindow *wwin)
2764 int i;
2765 WShortKey *key;
2767 for (i=0; i<WKBD_LAST; i++) {
2768 key = &wKeyBindings[i];
2770 if (key->keycode==0)
2771 continue;
2772 if (key->modifier!=AnyModifier) {
2773 XGrabKey(dpy, key->keycode, key->modifier|LockMask,
2774 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2775 #ifdef NUMLOCK_HACK
2776 /* Also grab all modifier combinations possible that include,
2777 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2778 * work even if the NumLock/ScrollLock key is on.
2780 wHackedGrabKey(key->keycode, key->modifier,
2781 wwin->frame->core->window, True, GrabModeAsync,
2782 GrabModeAsync);
2783 #endif
2785 XGrabKey(dpy, key->keycode, key->modifier,
2786 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2789 #ifndef LITE
2790 wRootMenuBindShortcuts(wwin->frame->core->window);
2791 #endif
2796 void
2797 wWindowResetMouseGrabs(WWindow *wwin)
2799 /* Mouse grabs can't be done on the client window because of
2800 * ICCCM and because clients that try to do the same will crash.
2802 * But there is a problem wich makes tbar buttons of unfocused
2803 * windows not usable as the click goes to the frame window instead
2804 * of the button itself. Must figure a way to fix that.
2807 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2809 if (!WFLAGP(wwin, no_bind_mouse)) {
2810 /* grabs for Meta+drag */
2811 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2812 True, ButtonPressMask, GrabModeSync,
2813 GrabModeAsync, None, None);
2816 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable)
2817 && !wwin->flags.is_gnustep) {
2818 /* the passive grabs to focus the window */
2819 /* if (wPreferences.focus_mode == WKF_CLICK) */
2820 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2821 True, ButtonPressMask, GrabModeSync, GrabModeAsync,
2822 None, None);
2824 XFlush(dpy);
2828 void
2829 wWindowUpdateGNUstepAttr(WWindow *wwin, GNUstepWMAttributes *attr)
2831 if (attr->flags & GSExtraFlagsAttr) {
2832 if (MGFLAGP(wwin, broken_close) !=
2833 (attr->extra_flags & GSDocumentEditedFlag)) {
2834 wwin->client_flags.broken_close = !MGFLAGP(wwin, broken_close);
2835 wWindowUpdateButtonImages(wwin);
2841 WMagicNumber
2842 wWindowAddSavedState(char *instance, char *class, char *command,
2843 pid_t pid, WSavedState *state)
2845 WWindowState *wstate;
2847 wstate = malloc(sizeof(WWindowState));
2848 if (!wstate)
2849 return 0;
2851 memset(wstate, 0, sizeof(WWindowState));
2852 wstate->pid = pid;
2853 if (instance)
2854 wstate->instance = wstrdup(instance);
2855 if (class)
2856 wstate->class = wstrdup(class);
2857 if (command)
2858 wstate->command = wstrdup(command);
2859 wstate->state = state;
2861 wstate->next = windowState;
2862 windowState = wstate;
2864 #ifdef DEBUG
2865 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2866 class, command);
2867 #endif
2869 return wstate;
2873 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2876 WMagicNumber
2877 wWindowGetSavedState(Window win)
2879 char *instance, *class, *command=NULL;
2880 WWindowState *wstate = windowState;
2881 char **argv;
2882 int argc;
2884 if (!wstate)
2885 return NULL;
2887 if (XGetCommand(dpy, win, &argv, &argc)) {
2888 if (argc > 0)
2889 command = wtokenjoin(argv, argc);
2890 XFreeStringList(argv);
2892 if (!command)
2893 return NULL;
2895 if (PropGetWMClass(win, &class, &instance)) {
2896 while (wstate) {
2897 if (SAME(instance, wstate->instance) &&
2898 SAME(class, wstate->class) &&
2899 SAME(command, wstate->command)) {
2900 break;
2902 wstate = wstate->next;
2904 } else {
2905 wstate = NULL;
2908 #ifdef DEBUG
2909 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2910 class, command);
2911 #endif
2913 if (command) wfree(command);
2914 if (instance) XFree(instance);
2915 if (class) XFree(class);
2917 return wstate;
2921 void
2922 wWindowDeleteSavedState(WMagicNumber id)
2924 WWindowState *tmp, *wstate=(WWindowState*)id;
2926 if (!wstate || !windowState)
2927 return;
2929 tmp = windowState;
2930 if (tmp==wstate) {
2931 windowState = wstate->next;
2932 #ifdef DEBUG
2933 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2934 wstate, wstate->instance, wstate->class, wstate->command);
2935 #endif
2936 if (wstate->instance) wfree(wstate->instance);
2937 if (wstate->class) wfree(wstate->class);
2938 if (wstate->command) wfree(wstate->command);
2939 wfree(wstate->state);
2940 wfree(wstate);
2941 } else {
2942 while (tmp->next) {
2943 if (tmp->next==wstate) {
2944 tmp->next=wstate->next;
2945 #ifdef DEBUG
2946 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2947 wstate, wstate->instance, wstate->class, wstate->command);
2948 #endif
2949 if (wstate->instance) wfree(wstate->instance);
2950 if (wstate->class) wfree(wstate->class);
2951 if (wstate->command) wfree(wstate->command);
2952 wfree(wstate->state);
2953 wfree(wstate);
2954 break;
2956 tmp = tmp->next;
2962 void
2963 wWindowDeleteSavedStatesForPID(pid_t pid)
2965 WWindowState *tmp, *wstate;
2967 if (!windowState)
2968 return;
2970 tmp = windowState;
2971 if (tmp->pid == pid) {
2972 wstate = windowState;
2973 windowState = tmp->next;
2974 #ifdef DEBUG
2975 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2976 wstate, wstate->instance, wstate->class, wstate->command);
2977 #endif
2978 if (wstate->instance) wfree(wstate->instance);
2979 if (wstate->class) wfree(wstate->class);
2980 if (wstate->command) wfree(wstate->command);
2981 wfree(wstate->state);
2982 wfree(wstate);
2983 } else {
2984 while (tmp->next) {
2985 if (tmp->next->pid==pid) {
2986 wstate = tmp->next;
2987 tmp->next = wstate->next;
2988 #ifdef DEBUG
2989 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2990 wstate, wstate->instance, wstate->class, wstate->command);
2991 #endif
2992 if (wstate->instance) wfree(wstate->instance);
2993 if (wstate->class) wfree(wstate->class);
2994 if (wstate->command) wfree(wstate->command);
2995 wfree(wstate->state);
2996 wfree(wstate);
2997 break;
2999 tmp = tmp->next;
3005 void
3006 wWindowSetOmnipresent(WWindow *wwin, Bool flag)
3008 if ( wwin->flags.omnipresent == flag) return;
3010 wwin->flags.omnipresent = flag;
3011 WMPostNotificationName(WMNChangedState, wwin, "omnipresent");
3015 /* ====================================================================== */
3017 static void
3018 resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
3020 WWindow *wwin = data;
3022 #ifndef NUMLOCK_HACK
3023 if ((event->xbutton.state & ValidModMask)
3024 != (event->xbutton.state & ~LockMask)) {
3025 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
3026 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3028 #endif
3030 event->xbutton.state &= ValidModMask;
3032 CloseWindowMenu(wwin->screen_ptr);
3034 if (wPreferences.focus_mode==WKF_CLICK
3035 && !(event->xbutton.state&ControlMask)
3036 && !WFLAGP(wwin, no_focusable)) {
3037 wSetFocusTo(wwin->screen_ptr, wwin);
3040 if (event->xbutton.button == Button1)
3041 wRaiseFrame(wwin->frame->core);
3043 if (event->xbutton.window != wwin->frame->resizebar->window) {
3044 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
3045 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
3046 GrabModeAsync, GrabModeAsync, None,
3047 None, CurrentTime)!=GrabSuccess) {
3048 #ifdef DEBUG0
3049 wwarning("pointer grab failed for window move");
3050 #endif
3051 return;
3055 if (event->xbutton.state & MOD_MASK) {
3056 /* move the window */
3057 wMouseMoveWindow(wwin, event);
3058 XUngrabPointer(dpy, CurrentTime);
3059 } else {
3060 wMouseResizeWindow(wwin, event);
3061 XUngrabPointer(dpy, CurrentTime);
3067 static void
3068 titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
3070 WWindow *wwin = data;
3072 event->xbutton.state &= ValidModMask;
3074 if (event->xbutton.button==Button1) {
3075 if (event->xbutton.state == 0) {
3076 if (!WFLAGP(wwin, no_shadeable)) {
3077 /* shade window */
3078 if (wwin->flags.shaded)
3079 wUnshadeWindow(wwin);
3080 else
3081 wShadeWindow(wwin);
3083 } else {
3084 int dir = 0;
3086 if (event->xbutton.state & ControlMask)
3087 dir |= MAX_VERTICAL;
3089 if (event->xbutton.state & ShiftMask) {
3090 dir |= MAX_HORIZONTAL;
3091 if (!(event->xbutton.state & ControlMask))
3092 wSelectWindow(wwin, !wwin->flags.selected);
3095 /* maximize window */
3096 if (dir!=0 && !WFLAGP(wwin, no_resizable)) {
3097 int ndir = dir ^ wwin->flags.maximized;
3098 if (wwin->flags.maximized != 0)
3099 wUnmaximizeWindow(wwin);
3100 if (ndir != 0)
3101 wMaximizeWindow(wwin, ndir);
3104 } else if (event->xbutton.button==Button3) {
3105 if (event->xbutton.state & MOD_MASK) {
3106 wHideOtherApplications(wwin);
3108 } else if (event->xbutton.button==Button2) {
3109 wSelectWindow(wwin, !wwin->flags.selected);
3110 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelUp) {
3111 wShadeWindow(wwin);
3112 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelDown) {
3113 wUnshadeWindow(wwin);
3118 static void
3119 frameMouseDown(WObjDescriptor *desc, XEvent *event)
3121 WWindow *wwin = desc->parent;
3123 event->xbutton.state &= ValidModMask;
3125 CloseWindowMenu(wwin->screen_ptr);
3127 if (/*wPreferences.focus_mode==WKF_CLICK
3128 &&*/ !(event->xbutton.state&ControlMask)
3129 && !WFLAGP(wwin, no_focusable)) {
3130 wSetFocusTo(wwin->screen_ptr, wwin);
3132 if (event->xbutton.button == Button1) {
3133 wRaiseFrame(wwin->frame->core);
3136 if (event->xbutton.state & MOD_MASK) {
3137 /* move the window */
3138 if (XGrabPointer(dpy, wwin->client_win, False,
3139 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
3140 GrabModeAsync, GrabModeAsync, None,
3141 None, CurrentTime)!=GrabSuccess) {
3142 #ifdef DEBUG0
3143 wwarning("pointer grab failed for window move");
3144 #endif
3145 return;
3147 if (event->xbutton.button == Button3 && !WFLAGP(wwin, no_resizable))
3148 wMouseResizeWindow(wwin, event);
3149 else if (event->xbutton.button==Button1 || event->xbutton.button==Button2)
3150 wMouseMoveWindow(wwin, event);
3151 XUngrabPointer(dpy, CurrentTime);
3156 static void
3157 titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
3159 WWindow *wwin = (WWindow*)data;
3161 #ifndef NUMLOCK_HACK
3162 if ((event->xbutton.state & ValidModMask)
3163 != (event->xbutton.state & ~LockMask)) {
3164 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
3165 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3167 #endif
3168 event->xbutton.state &= ValidModMask;
3170 CloseWindowMenu(wwin->screen_ptr);
3172 if (wPreferences.focus_mode==WKF_CLICK
3173 && !(event->xbutton.state&ControlMask)
3174 && !WFLAGP(wwin, no_focusable)) {
3175 wSetFocusTo(wwin->screen_ptr, wwin);
3178 if (event->xbutton.button == Button1
3179 || event->xbutton.button == Button2) {
3181 if (event->xbutton.button == Button1) {
3182 if (event->xbutton.state & MOD_MASK) {
3183 wLowerFrame(wwin->frame->core);
3184 } else {
3185 wRaiseFrame(wwin->frame->core);
3188 if ((event->xbutton.state & ShiftMask)
3189 && !(event->xbutton.state & ControlMask)) {
3190 wSelectWindow(wwin, !wwin->flags.selected);
3191 return;
3193 if (event->xbutton.window != wwin->frame->titlebar->window
3194 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
3195 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
3196 GrabModeAsync, GrabModeAsync, None,
3197 None, CurrentTime)!=GrabSuccess) {
3198 #ifdef DEBUG0
3199 wwarning("pointer grab failed for window move");
3200 #endif
3201 return;
3204 /* move the window */
3205 wMouseMoveWindow(wwin, event);
3207 XUngrabPointer(dpy, CurrentTime);
3208 } else if (event->xbutton.button == Button3 && event->xbutton.state==0
3209 && !wwin->flags.internal_window
3210 && !WCHECK_STATE(WSTATE_MODAL)) {
3211 WObjDescriptor *desc;
3213 if (event->xbutton.window != wwin->frame->titlebar->window
3214 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
3215 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
3216 GrabModeAsync, GrabModeAsync, None,
3217 None, CurrentTime)!=GrabSuccess) {
3218 #ifdef DEBUG0
3219 wwarning("pointer grab failed for window move");
3220 #endif
3221 return;
3224 OpenWindowMenu(wwin, event->xbutton.x_root,
3225 wwin->frame_y+wwin->frame->top_width, False);
3227 /* allow drag select */
3228 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
3229 event->xany.send_event = True;
3230 (*desc->handle_mousedown)(desc, event);
3232 XUngrabPointer(dpy, CurrentTime);
3238 static void
3239 windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
3241 WWindow *wwin = data;
3243 event->xbutton.state &= ValidModMask;
3245 CloseWindowMenu(wwin->screen_ptr);
3247 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3248 return;
3250 /* if control-click, kill the client */
3251 if (event->xbutton.state & ControlMask) {
3252 wClientKill(wwin);
3253 } else {
3254 #ifdef OLWM_HINTS
3255 if (wwin->flags.olwm_push_pin_out) {
3257 wwin->flags.olwm_push_pin_out = 0;
3259 wOLWMChangePushpinState(wwin, True);
3261 wFrameWindowUpdatePushButton(wwin->frame, False);
3263 return;
3265 #endif
3266 if (wwin->protocols.DELETE_WINDOW && event->xbutton.state==0) {
3267 /* send delete message */
3268 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3274 static void
3275 windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
3277 WWindow *wwin = data;
3279 CloseWindowMenu(wwin->screen_ptr);
3281 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3282 return;
3284 /* send delete message */
3285 if (wwin->protocols.DELETE_WINDOW) {
3286 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3287 } else {
3288 wClientKill(wwin);
3293 #ifdef XKB_BUTTON_HINT
3294 static void
3295 windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event)
3297 WWindow *wwin = data;
3298 WFrameWindow *fwin = wwin->frame;
3299 WScreen *scr = fwin->screen_ptr;
3300 XkbStateRec staterec;
3301 int tl;
3303 if (event->xbutton.button != Button1 && event->xbutton.button != Button3)
3304 return;
3305 tl = wwin->frame->languagemode;
3306 wwin->frame->languagemode = wwin->frame->last_languagemode;
3307 wwin->frame->last_languagemode = tl;
3308 wSetFocusTo(scr, wwin);
3309 wwin->frame->languagebutton_image =
3310 wwin->frame->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 +
3311 wwin->frame->languagemode];
3312 wFrameWindowUpdateLanguageButton(wwin->frame);
3313 if (event->xbutton.button == Button3)
3314 return;
3315 wRaiseFrame(fwin->core);
3317 #endif
3320 static void
3321 windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
3323 WWindow *wwin = data;
3325 event->xbutton.state &= ValidModMask;
3327 CloseWindowMenu(wwin->screen_ptr);
3329 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3330 return;
3332 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state==0) {
3333 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
3334 LastTimestamp);
3335 } else {
3336 WApplication *wapp;
3337 if ((event->xbutton.state & ControlMask) ||
3338 (event->xbutton.button == Button3)) {
3340 wapp = wApplicationOf(wwin->main_window);
3341 if (wapp && !WFLAGP(wwin, no_appicon))
3342 wHideApplication(wapp);
3343 } else if (event->xbutton.state==0) {
3344 wIconifyWindow(wwin);