- improved behaviour for the shared appicon thing.
[wmaker-crm.git] / src / window.c
blob8051d95cfb5defae560ad9b54849de29d01efe03
1 /* window.c - client window managing stuffs
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 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"
58 #ifdef MWM_HINTS
59 # include "motif.h"
60 #endif
61 #ifdef KWM_HINTS
62 # include "kwm.h"
63 #endif
64 #ifdef GNOME_STUFF
65 # include "gnome.h"
66 #endif
67 #ifdef OLWM_HINTS
68 # include "openlook.h"
69 #endif
71 /****** Global Variables ******/
73 extern WShortKey wKeyBindings[WKBD_LAST];
75 #ifdef SHAPE
76 extern Bool wShapeSupported;
77 #endif
79 /* contexts */
80 extern XContext wWinContext;
82 /* cursors */
83 extern Cursor wCursor[WCUR_LAST];
85 /* protocol atoms */
86 extern Atom _XA_WM_DELETE_WINDOW;
87 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
89 extern Atom _XA_WINDOWMAKER_STATE;
91 extern WPreferences wPreferences;
93 #define MOD_MASK wPreferences.modifier_mask
95 extern Time LastTimestamp;
97 /* superfluous... */
98 extern void DoWindowBirth(WWindow*);
102 /***** Local Stuff *****/
105 static WWindowState *windowState=NULL;
109 /* local functions */
110 static FocusMode getFocusMode(WWindow *wwin);
112 static int getSavedState(Window window, WSavedState **state);
114 static void setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints);
116 /* event handlers */
119 /* frame window (during window grabs) */
120 static void frameMouseDown(WObjDescriptor *desc, XEvent *event);
122 /* close button */
123 static void windowCloseClick(WCoreWindow *sender, void *data, XEvent *event);
124 static void windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event);
126 /* iconify button */
127 static void windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event);
129 #ifdef XKB_BUTTON_HINT
130 static void windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event);
131 #endif
133 static void titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
134 static void titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event);
136 static void resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
139 /****** Notification Observers ******/
141 static void
142 appearanceObserver(void *self, WMNotification *notif)
144 WWindow *wwin = (WWindow*)self;
145 int flags = (int)WMGetNotificationClientData(notif);
147 if (!wwin->frame || (!wwin->frame->titlebar && !wwin->frame->resizebar))
148 return;
150 if (flags & WFontSettings) {
151 wWindowConfigureBorders(wwin);
152 if(wwin->flags.shaded) {
153 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
154 wwin->frame->top_width - 1);
156 wwin->client.y = wwin->frame_y - wwin->client.height
157 + wwin->frame->top_width;
158 wWindowSynthConfigureNotify(wwin);
161 if (flags & WTextureSettings) {
162 wwin->frame->flags.need_texture_remake = 1;
164 if (flags & (WTextureSettings | WColorSettings)) {
165 if (wwin->frame->titlebar)
166 XClearWindow(dpy, wwin->frame->titlebar->window);
168 wFrameWindowPaint(wwin->frame);
172 /************************************/
174 WWindow*
175 wWindowFor(Window window)
177 WObjDescriptor *desc;
179 if (window==None)
180 return NULL;
182 if (XFindContext(dpy, window, wWinContext, (XPointer*)&desc)==XCNOENT)
183 return NULL;
185 if (desc->parent_type==WCLASS_WINDOW)
186 return desc->parent;
187 else if (desc->parent_type==WCLASS_FRAME) {
188 WFrameWindow *frame = (WFrameWindow*)desc->parent;
189 if (frame->flags.is_client_window_frame)
190 return frame->child;
193 return NULL;
197 WWindow*
198 wWindowCreate()
200 WWindow *wwin;
202 wwin = wmalloc(sizeof(WWindow));
203 wretain(wwin);
205 memset(wwin, 0, sizeof(WWindow));
207 wwin->client_descriptor.handle_mousedown = frameMouseDown;
208 wwin->client_descriptor.parent = wwin;
209 wwin->client_descriptor.self = wwin;
210 wwin->client_descriptor.parent_type = WCLASS_WINDOW;
212 return wwin;
216 void
217 wWindowDestroy(WWindow *wwin)
219 int i;
221 if (wwin->screen_ptr->cmap_window == wwin) {
222 wwin->screen_ptr->cmap_window = NULL;
225 WMRemoveNotificationObserver(wwin);
227 wwin->flags.destroyed = 1;
229 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
230 if (!wwin->screen_ptr->shortcutWindows[i])
231 continue;
233 WMRemoveFromArray(wwin->screen_ptr->shortcutWindows[i], wwin);
235 if (!WMGetArrayItemCount(wwin->screen_ptr->shortcutWindows[i])) {
236 WMFreeArray(wwin->screen_ptr->shortcutWindows[i]);
237 wwin->screen_ptr->shortcutWindows[i] = NULL;
241 if (wwin->fake_group && wwin->fake_group->retainCount>0) {
242 wwin->fake_group->retainCount--;
243 if (wwin->fake_group->retainCount==0 && wwin->fake_group->leader!=None) {
244 XDestroyWindow(dpy, wwin->fake_group->leader);
245 wwin->fake_group->leader = None;
246 wwin->fake_group->origLeader = None;
247 XFlush(dpy);
251 if (wwin->normal_hints)
252 XFree(wwin->normal_hints);
254 if (wwin->wm_hints)
255 XFree(wwin->wm_hints);
257 if (wwin->wm_instance)
258 XFree(wwin->wm_instance);
260 if (wwin->wm_class)
261 XFree(wwin->wm_class);
263 if (wwin->wm_gnustep_attr)
264 wfree(wwin->wm_gnustep_attr);
266 if (wwin->cmap_windows)
267 XFree(wwin->cmap_windows);
269 XDeleteContext(dpy, wwin->client_win, wWinContext);
271 if (wwin->frame)
272 wFrameWindowDestroy(wwin->frame);
274 if (wwin->icon) {
275 RemoveFromStackList(wwin->icon->core);
276 wIconDestroy(wwin->icon);
277 if (wPreferences.auto_arrange_icons)
278 wArrangeIcons(wwin->screen_ptr, True);
280 wrelease(wwin);
286 static void
287 setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints)
289 if (gs_hints->flags & GSWindowStyleAttr) {
290 if (gs_hints->window_style == WMBorderlessWindowMask) {
291 wwin->client_flags.no_border = 1;
292 wwin->client_flags.no_titlebar = 1;
293 wwin->client_flags.no_closable = 1;
294 wwin->client_flags.no_miniaturizable = 1;
295 wwin->client_flags.no_resizable = 1;
296 wwin->client_flags.no_close_button = 1;
297 wwin->client_flags.no_miniaturize_button = 1;
298 wwin->client_flags.no_resizebar = 1;
299 } else {
300 wwin->client_flags.no_close_button =
301 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
303 wwin->client_flags.no_closable =
304 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
306 wwin->client_flags.no_miniaturize_button =
307 ((gs_hints->window_style & WMMiniaturizableWindowMask)?0:1);
309 wwin->client_flags.no_miniaturizable =
310 wwin->client_flags.no_miniaturize_button;
312 wwin->client_flags.no_resizebar =
313 ((gs_hints->window_style & WMResizableWindowMask)?0:1);
315 wwin->client_flags.no_resizable = wwin->client_flags.no_resizebar;
317 /* these attributes supposedly imply in the existence
318 * of a titlebar */
319 if (gs_hints->window_style & (WMResizableWindowMask|
320 WMClosableWindowMask|
321 WMMiniaturizableWindowMask)) {
322 wwin->client_flags.no_titlebar = 0;
323 } else {
324 wwin->client_flags.no_titlebar =
325 ((gs_hints->window_style & WMTitledWindowMask)?0:1);
329 } else {
330 /* setup the defaults */
331 wwin->client_flags.no_border = 0;
332 wwin->client_flags.no_titlebar = 0;
333 wwin->client_flags.no_closable = 0;
334 wwin->client_flags.no_miniaturizable = 0;
335 wwin->client_flags.no_resizable = 0;
336 wwin->client_flags.no_close_button = 0;
337 wwin->client_flags.no_miniaturize_button = 0;
338 wwin->client_flags.no_resizebar = 0;
340 if (gs_hints->extra_flags & GSNoApplicationIconFlag) {
341 wwin->client_flags.no_appicon = 1;
346 void
347 wWindowCheckAttributeSanity(WWindow *wwin, WWindowAttributes *wflags,
348 WWindowAttributes *mask)
350 if (wflags->no_appicon && mask->no_appicon)
351 wflags->emulate_appicon = 0;
353 if (wwin->main_window!=None) {
354 WApplication *wapp = wApplicationOf(wwin->main_window);
355 if (wapp && !wapp->flags.emulated)
356 wflags->emulate_appicon = 0;
359 if (wwin->transient_for!=None
360 && wwin->transient_for!=wwin->screen_ptr->root_win)
361 wflags->emulate_appicon = 0;
363 if (wflags->sunken && mask->sunken && wflags->floating && mask->floating)
364 wflags->sunken = 0;
369 void
370 wWindowSetupInitialAttributes(WWindow *wwin, int *level, int *workspace)
372 WScreen *scr = wwin->screen_ptr;
374 /* sets global default stuff */
375 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
376 &wwin->client_flags, NULL, True);
378 * Decoration setting is done in this precedence (lower to higher)
379 * - use global default in the resource database
380 * - guess some settings
381 * - use GNUstep/external window attributes
382 * - set hints specified for the app in the resource DB
385 WSETUFLAG(wwin, broken_close, 0);
387 if (wwin->protocols.DELETE_WINDOW)
388 WSETUFLAG(wwin, kill_close, 0);
389 else
390 WSETUFLAG(wwin, kill_close, 1);
392 /* transients can't be iconified or maximized */
393 if (wwin->transient_for) {
394 WSETUFLAG(wwin, no_miniaturizable, 1);
395 WSETUFLAG(wwin, no_miniaturize_button, 1);
398 /* if the window can't be resized, remove the resizebar */
399 if (wwin->normal_hints->flags & (PMinSize|PMaxSize)
400 && (wwin->normal_hints->min_width==wwin->normal_hints->max_width)
401 && (wwin->normal_hints->min_height==wwin->normal_hints->max_height)) {
402 WSETUFLAG(wwin, no_resizable, 1);
403 WSETUFLAG(wwin, no_resizebar, 1);
406 /* set GNUstep window attributes */
407 if (wwin->wm_gnustep_attr) {
408 setupGNUstepHints(wwin, wwin->wm_gnustep_attr);
410 if (wwin->wm_gnustep_attr->flags & GSWindowLevelAttr) {
412 *level = wwin->wm_gnustep_attr->window_level;
414 * INT_MIN is the only illegal window level.
416 if (*level == INT_MIN)
417 *level = INT_MIN + 1;
418 } else {
419 /* setup defaults */
420 *level = WMNormalLevel;
422 } else {
423 int tmp_workspace = -1;
424 int tmp_level = INT_MIN; /* INT_MIN is never used by the window levels */
425 Bool check;
427 check = False;
429 #ifdef MWM_HINTS
430 wMWMCheckClientHints(wwin);
431 #endif /* MWM_HINTS */
433 #ifdef GNOME_STUFF
434 check = wGNOMECheckClientHints(wwin, &tmp_level, &tmp_workspace);
435 #endif /* GNOME_STUFF */
437 #ifdef KWM_HINTS
438 if (!check)
439 wKWMCheckClientHints(wwin, &tmp_level, &tmp_workspace);
440 #endif /* KWM_HINTS */
442 #ifdef OLWM_HINTS
443 wOLWMCheckClientHints(wwin);
444 #endif /* OLWM_HINTS */
446 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
447 * have INT_MIN that means that no window level was requested. -Dan
449 if (tmp_level == INT_MIN) {
450 if (WFLAGP(wwin, floating))
451 *level = WMFloatingLevel;
452 else if (WFLAGP(wwin, sunken))
453 *level = WMSunkenLevel;
454 else
455 *level = WMNormalLevel;
456 } else {
457 *level = tmp_level;
460 if (tmp_workspace >= 0) {
461 *workspace = tmp_workspace % scr->workspace_count;
466 * Set attributes specified only for that window/class.
467 * This might do duplicate work with the 1st wDefaultFillAttributes().
469 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
470 &wwin->user_flags, &wwin->defined_user_flags,
471 False);
473 * Sanity checks for attributes that depend on other attributes
475 if (wwin->user_flags.no_appicon && wwin->defined_user_flags.no_appicon)
476 wwin->user_flags.emulate_appicon = 0;
478 if (wwin->main_window!=None) {
479 WApplication *wapp = wApplicationOf(wwin->main_window);
480 if (wapp && !wapp->flags.emulated)
481 wwin->user_flags.emulate_appicon = 0;
484 if (wwin->transient_for!=None
485 && wwin->transient_for!=wwin->screen_ptr->root_win)
486 wwin->user_flags.emulate_appicon = 0;
488 if (wwin->user_flags.sunken && wwin->defined_user_flags.sunken
489 && wwin->user_flags.floating && wwin->defined_user_flags.floating)
490 wwin->user_flags.sunken = 0;
492 WSETUFLAG(wwin, no_shadeable, WFLAGP(wwin, no_titlebar));
498 Bool
499 wWindowCanReceiveFocus(WWindow *wwin)
501 if (!wwin->flags.mapped && (!wwin->flags.shaded || wwin->flags.hidden))
502 return False;
503 if (WFLAGP(wwin, no_focusable) || wwin->flags.miniaturized)
504 return False;
505 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
506 return False;
508 return True;
512 Bool
513 wWindowObscuresWindow(WWindow *wwin, WWindow *obscured)
515 int w1, h1, w2, h2;
517 w1 = wwin->frame->core->width;
518 h1 = wwin->frame->core->height;
519 w2 = obscured->frame->core->width;
520 h2 = obscured->frame->core->height;
522 if (!IS_OMNIPRESENT(wwin) && !IS_OMNIPRESENT(obscured)
523 && wwin->frame->workspace != obscured->frame->workspace)
524 return False;
526 if (wwin->frame_x + w1 < obscured->frame_x
527 || wwin->frame_y + h1 < obscured->frame_y
528 || wwin->frame_x > obscured->frame_x + w2
529 || wwin->frame_y > obscured->frame_y + h2) {
530 return False;
533 return True;
537 static Window
538 createFakeWindowGroupLeader(WScreen *scr, Window win, char *instance, char *class)
540 XClassHint *classHint;
541 XWMHints *hints;
542 Window leader;
543 int argc;
544 char **argv;
546 leader = XCreateSimpleWindow(dpy, scr->root_win, 10, 10, 10, 10, 0, 0, 0);
547 /* set class hint */
548 classHint = XAllocClassHint();
549 classHint->res_name = instance;
550 classHint->res_class = class;
551 XSetClassHint(dpy, leader, classHint);
552 XFree(classHint);
554 /* set window group leader to self */
555 hints = XAllocWMHints();
556 hints->window_group = leader;
557 hints->flags = WindowGroupHint;
558 XSetWMHints(dpy, leader, hints);
559 XFree(hints);
561 if (XGetCommand(dpy, win, &argv, &argc)!=0 && argc > 0) {
562 XSetCommand(dpy, leader, argv, argc);
563 XFreeStringList(argv);
566 return leader;
570 static int
571 matchIdentifier(void *item, void *cdata)
573 return (strcmp(((WFakeGroupLeader*)item)->identifier, (char*)cdata)==0);
578 *----------------------------------------------------------------
579 * wManageWindow--
580 * reparents the window and allocates a descriptor for it.
581 * Window manager hints and other hints are fetched to configure
582 * the window decoration attributes and others. User preferences
583 * for the window are used if available, to configure window
584 * decorations and some behaviour.
585 * If in startup, windows that are override redirect,
586 * unmapped and never were managed and are Withdrawn are not
587 * managed.
589 * Returns:
590 * the new window descriptor
592 * Side effects:
593 * The window is reparented and appropriate notification
594 * is done to the client. Input mask for the window is setup.
595 * The window descriptor is also associated with various window
596 * contexts and inserted in the head of the window list.
597 * Event handler contexts are associated for some objects
598 * (buttons, titlebar and resizebar)
600 *----------------------------------------------------------------
602 WWindow*
603 wManageWindow(WScreen *scr, Window window)
605 WWindow *wwin;
606 int x, y;
607 unsigned width, height;
608 XWindowAttributes wattribs;
609 XSetWindowAttributes attribs;
610 WWindowState *win_state;
611 WWindow *transientOwner = NULL;
612 int window_level;
613 int wm_state;
614 int foo;
615 int workspace = -1;
616 char *title;
617 Bool withdraw = False;
618 Bool raise = False;
620 /* mutex. */
621 /* XGrabServer(dpy); */
622 XSync(dpy, False);
623 /* make sure the window is still there */
624 if (!XGetWindowAttributes(dpy, window, &wattribs)) {
625 XUngrabServer(dpy);
626 return NULL;
629 /* if it's an override-redirect, ignore it */
630 if (wattribs.override_redirect) {
631 XUngrabServer(dpy);
632 return NULL;
635 wm_state = PropGetWindowState(window);
637 /* if it's startup and the window is unmapped, don't manage it */
638 if (scr->flags.startup && wm_state < 0 && wattribs.map_state==IsUnmapped) {
639 XUngrabServer(dpy);
640 return NULL;
643 if (!wFetchName(dpy, window, &title)) {
644 title = NULL;
647 #ifdef KWM_HINTS
648 if (title && !wKWMManageableClient(scr, window, title)) {
649 XFree(title);
650 XUngrabServer(dpy);
651 return NULL;
653 #endif /* KWM_HINTS */
656 wwin = wWindowCreate();
658 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
660 #ifdef DEBUG
661 printf("managing window %x\n", (unsigned)window);
662 #endif
664 #ifdef SHAPE
665 if (wShapeSupported) {
666 int junk;
667 unsigned int ujunk;
668 int b_shaped;
670 XShapeSelectInput(dpy, window, ShapeNotifyMask);
671 XShapeQueryExtents(dpy, window, &b_shaped, &junk, &junk, &ujunk,
672 &ujunk, &junk, &junk, &junk, &ujunk, &ujunk);
673 wwin->flags.shaped = b_shaped;
675 #endif
678 *--------------------------------------------------
680 * Get hints and other information in properties
682 *--------------------------------------------------
684 PropGetWMClass(window, &wwin->wm_class, &wwin->wm_instance);
686 /* setup descriptor */
687 wwin->client_win = window;
688 wwin->screen_ptr = scr;
690 wwin->old_border_width = wattribs.border_width;
692 wwin->event_mask = CLIENT_EVENTS;
693 attribs.event_mask = CLIENT_EVENTS;
694 attribs.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask;
695 attribs.save_under = False;
696 XChangeWindowAttributes(dpy, window, CWEventMask|CWDontPropagate
697 |CWSaveUnder, &attribs);
698 XSetWindowBorderWidth(dpy, window, 0);
700 /* get hints from GNUstep app */
701 if (wwin->wm_class != 0 && strcmp(wwin->wm_class, "GNUstep") == 0) {
702 wwin->flags.is_gnustep = 1;
704 if (!PropGetGNUstepWMAttr(window, &wwin->wm_gnustep_attr)) {
705 wwin->wm_gnustep_attr = NULL;
708 wwin->client_leader = PropGetClientLeader(window);
709 if (wwin->client_leader!=None)
710 wwin->main_window = wwin->client_leader;
712 wwin->wm_hints = XGetWMHints(dpy, window);
714 if (wwin->wm_hints) {
715 if (wwin->wm_hints->flags & StateHint) {
717 if (wwin->wm_hints->initial_state == IconicState) {
719 wwin->flags.miniaturized = 1;
721 } else if (wwin->wm_hints->initial_state == WithdrawnState) {
723 withdraw = True;
727 if (wwin->wm_hints->flags & WindowGroupHint) {
728 wwin->group_id = wwin->wm_hints->window_group;
729 /* window_group has priority over CLIENT_LEADER */
730 wwin->main_window = wwin->group_id;
731 } else {
732 wwin->group_id = None;
735 if (wwin->wm_hints->flags & UrgencyHint)
736 wwin->flags.urgent = 1;
737 } else {
738 wwin->group_id = None;
741 PropGetProtocols(window, &wwin->protocols);
743 if (!XGetTransientForHint(dpy, window, &wwin->transient_for)) {
744 wwin->transient_for = None;
745 } else {
746 if (wwin->transient_for==None || wwin->transient_for==window) {
747 wwin->transient_for = scr->root_win;
748 } else {
749 transientOwner = wWindowFor(wwin->transient_for);
750 if (transientOwner && transientOwner->main_window!=None) {
751 wwin->main_window = transientOwner->main_window;
752 } /*else {
753 wwin->main_window = None;
758 /* guess the focus mode */
759 wwin->focus_mode = getFocusMode(wwin);
761 /* get geometry stuff */
762 wClientGetNormalHints(wwin, &wattribs, True, &x, &y, &width, &height);
764 /* get colormap windows */
765 GetColormapWindows(wwin);
768 *--------------------------------------------------
770 * Setup the decoration/window attributes and
771 * geometry
773 *--------------------------------------------------
776 wWindowSetupInitialAttributes(wwin, &window_level, &workspace);
778 #ifdef OLWM_HINTS
779 if (wwin->client_flags.olwm_transient && wwin->transient_for==None
780 && wwin->group_id != None && wwin->group_id != window) {
782 transientOwner = wWindowFor(wwin->group_id);
784 if (transientOwner) {
785 wwin->transient_for = wwin->group_id;
787 /* transients can't be iconified or maximized */
788 if (wwin->transient_for) {
789 WSETUFLAG(wwin, no_miniaturizable, 1);
790 WSETUFLAG(wwin, no_miniaturize_button, 1);
794 #endif /* OLWM_HINTS */
796 /* Make broken apps behave as a nice app. */
797 if (WFLAGP(wwin, emulate_appicon)) {
798 wwin->main_window = wwin->client_win;
801 if (!withdraw && wwin->main_window && WFLAGP(wwin, shared_appicon)) {
802 char *buffer, *instance, *class;
803 WFakeGroupLeader *fPtr;
804 int index;
806 PropGetWMClass(wwin->main_window, &class, &instance);
807 buffer = wmalloc(strlen(instance)+strlen(class)+2);
808 sprintf(buffer, "%s.%s", instance, class);
810 index = WMFindInArray(scr->fakeGroupLeaders, matchIdentifier, (void*)buffer);
811 if (index != WANotFound) {
812 fPtr = WMGetFromArray(scr->fakeGroupLeaders, index);
813 if (fPtr->retainCount == 0) {
814 fPtr->leader = createFakeWindowGroupLeader(scr, wwin->main_window,
815 instance, class);
817 fPtr->retainCount++;
818 if (wwin->main_window!=wwin->client_win && fPtr->origLeader==None) {
819 fPtr->retainCount++;
820 fPtr->origLeader = wwin->main_window;
822 wwin->fake_group = fPtr;
823 //wwin->group_id = fPtr->leader;
824 wwin->main_window = fPtr->leader;
825 wfree(buffer);
826 } else {
827 fPtr = (WFakeGroupLeader*)wmalloc(sizeof(WFakeGroupLeader));
829 fPtr->identifier = buffer;
830 fPtr->leader = createFakeWindowGroupLeader(scr, wwin->main_window,
831 instance, class);
832 fPtr->origLeader = None;
833 fPtr->retainCount = 1;
835 WMAddToArray(scr->fakeGroupLeaders, fPtr);
837 if (wwin->main_window!=wwin->client_win) {
838 fPtr->retainCount++;
839 fPtr->origLeader = wwin->main_window;
841 wwin->fake_group = fPtr;
842 //wwin->group_id = fPtr->leader;
843 wwin->main_window = fPtr->leader;
845 if (instance)
846 XFree(instance);
847 if (class)
848 XFree(class);
853 *------------------------------------------------------------
855 * Setup the initial state of the window
857 *------------------------------------------------------------
860 if (WFLAGP(wwin, start_miniaturized) && !WFLAGP(wwin, no_miniaturizable)) {
861 wwin->flags.miniaturized = 1;
864 if (WFLAGP(wwin, start_maximized) && !WFLAGP(wwin, no_resizable)) {
865 wwin->flags.maximized = MAX_VERTICAL|MAX_HORIZONTAL;
869 Bool bla;
871 bla = False;
872 #ifdef GNOME_STUFF
873 bla = wGNOMECheckInitialClientState(wwin);
874 #endif
875 #ifdef KWM_HINTS
876 if (!bla)
877 wKWMCheckClientInitialState(wwin);
878 #endif
881 /* apply previous state if it exists and we're in startup */
882 if (scr->flags.startup && wm_state >= 0) {
884 if (wm_state == IconicState) {
886 wwin->flags.miniaturized = 1;
888 } else if (wm_state == WithdrawnState) {
890 withdraw = True;
894 /* if there is a saved state (from file), restore it */
895 win_state = NULL;
896 if (wwin->main_window!=None/* && wwin->main_window!=window*/) {
897 win_state = (WWindowState*)wWindowGetSavedState(wwin->main_window);
898 } else {
899 win_state = (WWindowState*)wWindowGetSavedState(window);
901 if (win_state && !withdraw) {
903 if (win_state->state->hidden>0)
904 wwin->flags.hidden = win_state->state->hidden;
906 if (win_state->state->shaded>0 && !WFLAGP(wwin, no_shadeable))
907 wwin->flags.shaded = win_state->state->shaded;
909 if (win_state->state->miniaturized>0 &&
910 !WFLAGP(wwin, no_miniaturizable)) {
911 wwin->flags.miniaturized = win_state->state->miniaturized;
914 if (!IS_OMNIPRESENT(wwin)) {
915 int w = wDefaultGetStartWorkspace(scr, wwin->wm_instance,
916 wwin->wm_class);
917 if (w < 0 || w >= scr->workspace_count) {
918 workspace = win_state->state->workspace;
919 if (workspace >= scr->workspace_count)
920 workspace = scr->current_workspace;
921 } else {
922 workspace = w;
924 } else {
925 workspace = scr->current_workspace;
929 /* if we're restarting, restore saved state (from hints).
930 * This will overwrite previous */
932 WSavedState *wstate;
934 if (getSavedState(window, &wstate)) {
935 wwin->flags.shaded = wstate->shaded;
936 wwin->flags.hidden = wstate->hidden;
937 wwin->flags.miniaturized = wstate->miniaturized;
938 wwin->flags.maximized = wstate->maximized;
939 if (wwin->flags.maximized) {
940 wwin->old_geometry.x = wstate->x;
941 wwin->old_geometry.y = wstate->y;
942 wwin->old_geometry.width = wstate->w;
943 wwin->old_geometry.height = wstate->h;
946 workspace = wstate->workspace;
947 } else {
948 wstate = NULL;
951 /* restore window shortcut */
952 if (wstate != NULL || win_state != NULL) {
953 unsigned mask = 0;
955 if (win_state != NULL)
956 mask = win_state->state->window_shortcuts;
958 if (wstate != NULL && mask == 0)
959 mask = wstate->window_shortcuts;
961 if (mask > 0) {
962 int i;
964 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
965 if (mask & (1<<i)) {
966 if (!scr->shortcutWindows[i])
967 scr->shortcutWindows[i] = WMCreateArray(4);
969 WMAddToArray(scr->shortcutWindows[i], wwin);
974 if (wstate != NULL) {
975 wfree(wstate);
979 /* don't let transients start miniaturized if their owners are not */
980 if (transientOwner && !transientOwner->flags.miniaturized
981 && wwin->flags.miniaturized && !withdraw) {
982 wwin->flags.miniaturized = 0;
983 if (wwin->wm_hints)
984 wwin->wm_hints->initial_state = NormalState;
987 /* set workspace on which the window starts */
988 if (workspace >= 0) {
989 if (workspace > scr->workspace_count-1) {
990 workspace = workspace % scr->workspace_count;
992 } else {
993 int w;
995 w = wDefaultGetStartWorkspace(scr, wwin->wm_instance, wwin->wm_class);
997 if (w >= 0 && w < scr->workspace_count && !(IS_OMNIPRESENT(wwin))) {
999 workspace = w;
1001 } else {
1002 if (wPreferences.open_transients_with_parent && transientOwner) {
1004 workspace = transientOwner->frame->workspace;
1006 } else {
1008 workspace = scr->current_workspace;
1013 /* setup window geometry */
1014 if (win_state && win_state->state->w > 0) {
1015 width = win_state->state->w;
1016 height = win_state->state->h;
1018 wWindowConstrainSize(wwin, &width, &height);
1020 /* do not ask for window placement if the window is
1021 * transient, during startup, if the initial workspace is another one
1022 * or if the window wants to start iconic.
1023 * If geometry was saved, restore it. */
1025 Bool dontBring = False;
1027 if (win_state && win_state->state->w > 0) {
1028 x = win_state->state->x;
1029 y = win_state->state->y;
1030 } else if ((wwin->transient_for==None
1031 || wPreferences.window_placement!=WPM_MANUAL)
1032 && !scr->flags.startup
1033 && workspace == scr->current_workspace
1034 && !wwin->flags.miniaturized
1035 && !wwin->flags.maximized
1036 && !(wwin->normal_hints->flags & (USPosition|PPosition))) {
1038 if (transientOwner && transientOwner->flags.mapped) {
1039 int offs = WMAX(20, 2*transientOwner->frame->top_width);
1041 x = transientOwner->frame_x +
1042 abs((transientOwner->frame->core->width - width)/2) + offs;
1043 y = transientOwner->frame_y +
1044 abs((transientOwner->frame->core->height - height)/3) + offs;
1046 if (x < 0)
1047 x = 0;
1048 else if (x + width > scr->scr_width)
1049 x = scr->scr_width - width;
1051 if (y < 0)
1052 y = 0;
1053 else if (y + height > scr->scr_height)
1054 y = scr->scr_height - height;
1055 } else {
1056 PlaceWindow(wwin, &x, &y, width, height);
1058 if (wPreferences.window_placement == WPM_MANUAL)
1059 dontBring = True;
1062 if (WFLAGP(wwin, dont_move_off) && dontBring)
1063 wScreenBringInside(scr, &x, &y, width, height);
1066 if (wwin->flags.urgent) {
1067 if (!IS_OMNIPRESENT(wwin))
1068 wwin->flags.omnipresent ^= 1;
1072 *--------------------------------------------------
1074 * Create frame, borders and do reparenting
1076 *--------------------------------------------------
1078 foo = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
1079 #ifdef XKB_BUTTON_HINT
1080 if (wPreferences.modelock)
1081 foo |= WFF_LANGUAGE_BUTTON;
1082 #endif
1083 if (!WFLAGP(wwin, no_titlebar))
1084 foo |= WFF_TITLEBAR;
1085 if (!WFLAGP(wwin, no_resizebar))
1086 foo |= WFF_RESIZEBAR;
1087 if (!WFLAGP(wwin, no_border))
1088 foo |= WFF_BORDER;
1090 wwin->frame = wFrameWindowCreate(scr, window_level,
1091 x, y, width, height,
1092 &wPreferences.window_title_clearance, foo,
1093 scr->window_title_texture,
1094 scr->resizebar_texture,
1095 scr->window_title_pixel,
1096 &scr->window_title_gc,
1097 &scr->title_font);
1099 wwin->frame->flags.is_client_window_frame = 1;
1100 wwin->frame->flags.justification = wPreferences.title_justification;
1102 /* setup button images */
1103 wWindowUpdateButtonImages(wwin);
1105 /* hide unused buttons */
1106 foo = 0;
1107 if (WFLAGP(wwin, no_close_button))
1108 foo |= WFF_RIGHT_BUTTON;
1109 if (WFLAGP(wwin, no_miniaturize_button))
1110 foo |= WFF_LEFT_BUTTON;
1111 #ifdef XKB_BUTTON_HINT
1112 if (WFLAGP(wwin, no_language_button) || WFLAGP(wwin, no_focusable))
1113 foo |= WFF_LANGUAGE_BUTTON;
1114 #endif
1115 if (foo!=0)
1116 wFrameWindowHideButton(wwin->frame, foo);
1118 wwin->frame->child = wwin;
1120 #ifdef OLWM_HINTS
1121 /* emulate olwm push pin. Make the button look as pushed-in for
1122 * the pinned-out state. When the button is clicked, it will
1123 * revert to the normal position, which means the pin is pinned-in.
1125 if (wwin->flags.olwm_push_pin_out)
1126 wFrameWindowUpdatePushButton(wwin->frame, True);
1127 #endif /* OLWM_HINTS */
1130 wwin->frame->workspace = workspace;
1132 wwin->frame->on_click_left = windowIconifyClick;
1133 #ifdef XKB_BUTTON_HINT
1134 if (wPreferences.modelock)
1135 wwin->frame->on_click_language = windowLanguageClick;
1136 #endif
1138 wwin->frame->on_click_right = windowCloseClick;
1139 wwin->frame->on_dblclick_right = windowCloseDblClick;
1141 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1142 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1144 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1147 XSelectInput(dpy, wwin->client_win,
1148 wwin->event_mask & ~StructureNotifyMask);
1150 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1151 0, wwin->frame->top_width);
1153 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1157 int gx, gy;
1159 wClientGetGravityOffsets(wwin, &gx, &gy);
1161 /* if gravity is to the south, account for the border sizes */
1162 if (gy > 0)
1163 y -= wwin->frame->top_width + wwin->frame->bottom_width;
1167 * wWindowConfigure() will init the client window's size
1168 * (wwin->client.{width,height}) and all other geometry
1169 * related variables (frame_x,frame_y)
1171 wWindowConfigure(wwin, x, y, width, height);
1173 /* to make sure the window receives it's new position after reparenting */
1174 wWindowSynthConfigureNotify(wwin);
1177 *--------------------------------------------------
1179 * Setup descriptors and save window to internal
1180 * lists
1182 *--------------------------------------------------
1185 if (wwin->main_window!=None) {
1186 WApplication *app;
1187 WWindow *leader;
1189 /* Leader windows do not necessary set themselves as leaders.
1190 * If this is the case, point the leader of this window to
1191 * itself */
1192 leader = wWindowFor(wwin->main_window);
1193 if (leader && leader->main_window==None) {
1194 leader->main_window = leader->client_win;
1196 app = wApplicationCreate(scr, wwin->main_window);
1197 if (app) {
1198 app->last_workspace = workspace;
1200 app->main_window_desc->fake_group = wwin->fake_group;
1203 * Do application specific stuff, like setting application
1204 * wide attributes.
1207 if (wwin->flags.hidden) {
1208 /* if the window was set to hidden because it was hidden
1209 * in a previous incarnation and that state was restored */
1210 app->flags.hidden = 1;
1211 } else if (app->flags.hidden) {
1212 if (WFLAGP(app->main_window_desc, start_hidden)) {
1213 wwin->flags.hidden = 1;
1214 } else {
1215 wUnhideApplication(app, False, False);
1216 raise = True;
1222 /* setup the frame descriptor */
1223 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1224 wwin->frame->core->descriptor.parent = wwin;
1225 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1227 /* don't let windows go away if we die */
1228 XAddToSaveSet(dpy, window);
1230 XLowerWindow(dpy, window);
1232 /* if window is in this workspace and should be mapped, then map it */
1233 if (!wwin->flags.miniaturized
1234 && (workspace == scr->current_workspace || IS_OMNIPRESENT(wwin))
1235 && !wwin->flags.hidden && !withdraw) {
1237 /* The following "if" is to avoid crashing of clients that expect
1238 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1239 * after the return from this function.
1241 if (wwin->wm_hints && (wwin->wm_hints->flags & StateHint)) {
1242 wClientSetState(wwin, wwin->wm_hints->initial_state, None);
1243 } else {
1244 wClientSetState(wwin, NormalState, None);
1247 #if 0
1248 /* if not auto focus, then map the window under the currently
1249 * focused window */
1250 #define _WIDTH(w) (w)->frame->core->width
1251 #define _HEIGHT(w) (w)->frame->core->height
1252 if (!wPreferences.auto_focus && scr->focused_window
1253 && !scr->flags.startup && !transientOwner
1254 && ((wWindowObscuresWindow(wwin, scr->focused_window)
1255 && (_WIDTH(wwin) > (_WIDTH(scr->focused_window)*5)/3
1256 || _HEIGHT(wwin) > (_HEIGHT(scr->focused_window)*5)/3)
1257 && WINDOW_LEVEL(scr->focused_window) == WINDOW_LEVEL(wwin))
1258 || wwin->flags.maximized)) {
1259 MoveInStackListUnder(scr->focused_window->frame->core,
1260 wwin->frame->core);
1262 #undef _WIDTH
1263 #undef _HEIGHT
1265 #endif
1267 if (wPreferences.superfluous && !wPreferences.no_animations
1268 && !scr->flags.startup && wwin->transient_for==None
1270 * The brain damaged idiotic non-click to focus modes will
1271 * have trouble with this because:
1273 * 1. window is created and mapped by the client
1274 * 2. window is mapped by wmaker in small size
1275 * 3. window is animated to grow to normal size
1276 * 4. this function returns to normal event loop
1277 * 5. eventually, the EnterNotify event that would trigger
1278 * the window focusing (if the mouse is over that window)
1279 * will be processed by wmaker.
1280 * But since this event will be rather delayed
1281 * (step 3 has a large delay) the time when the event ocurred
1282 * and when it is processed, the client that owns that window
1283 * will reject the XSetInputFocus() for it.
1285 && (wPreferences.focus_mode==WKF_CLICK
1286 || wPreferences.auto_focus)) {
1287 DoWindowBirth(wwin);
1290 wWindowMap(wwin);
1293 /* setup stacking descriptor */
1294 if (transientOwner) {
1295 /* && wPreferences.on_top_transients */
1296 if (transientOwner) {
1297 wwin->frame->core->stacking->child_of =
1298 transientOwner->frame->core;
1300 } else {
1301 wwin->frame->core->stacking->child_of = NULL;
1305 if (!scr->focused_window) {
1306 /* first window on the list */
1307 wwin->next = NULL;
1308 wwin->prev = NULL;
1309 scr->focused_window = wwin;
1310 } else {
1311 WWindow *tmp;
1313 /* add window at beginning of focus window list */
1314 tmp = scr->focused_window;
1315 while (tmp->prev)
1316 tmp = tmp->prev;
1317 tmp->prev = wwin;
1318 wwin->next = tmp;
1319 wwin->prev = NULL;
1322 /* raise is set to true if we un-hid the app when this window was born.
1323 * we raise, else old windows of this app will be above this new one. */
1324 if (raise) {
1325 wRaiseFrame(wwin->frame->core);
1328 /* Update name must come after WApplication stuff is done */
1329 wWindowUpdateName(wwin, title);
1330 if (title)
1331 XFree(title);
1333 XUngrabServer(dpy);
1336 *--------------------------------------------------
1338 * Final preparations before window is ready to go
1340 *--------------------------------------------------
1343 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1346 if (!wwin->flags.miniaturized && workspace == scr->current_workspace
1347 && !wwin->flags.hidden) {
1348 if (((transientOwner && transientOwner->flags.focused)
1349 || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable))
1350 wSetFocusTo(scr, wwin);
1352 wWindowResetMouseGrabs(wwin);
1354 if (!WFLAGP(wwin, no_bind_keys)) {
1355 wWindowSetKeyGrabs(wwin);
1359 WMPostNotificationName(WMNManaged, wwin, NULL);
1362 wColormapInstallForWindow(scr, scr->cmap_window);
1365 #ifdef OLWM_HINTS
1366 if (wwin->client_flags.olwm_warp_to_pin && wwin->frame->titlebar != NULL
1367 && !WFLAGP(wwin, no_close_button) && !withdraw) {
1369 XWarpPointer(dpy, None, None, 0, 0, 0, 0,
1370 wwin->frame_x + width - wwin->frame->titlebar->height * 2,
1371 wwin->frame_y);
1373 #endif
1376 *------------------------------------------------------------
1377 * Setup Notification Observers
1378 *------------------------------------------------------------
1380 WMAddNotificationObserver(appearanceObserver, wwin,
1381 WNWindowAppearanceSettingsChanged, wwin);
1385 *--------------------------------------------------
1387 * Cleanup temporary stuff
1389 *--------------------------------------------------
1392 if (win_state)
1393 wWindowDeleteSavedState(win_state);
1395 /* If the window must be withdrawed, then do it now.
1396 * Must do some optimization, 'though */
1397 if (withdraw) {
1398 wwin->flags.mapped = 0;
1399 wClientSetState(wwin, WithdrawnState, None);
1400 wUnmanageWindow(wwin, True, False);
1401 wwin = NULL;
1404 return wwin;
1411 WWindow*
1412 wManageInternalWindow(WScreen *scr, Window window, Window owner,
1413 char *title, int x, int y, int width, int height)
1415 WWindow *wwin;
1416 int foo;
1418 wwin = wWindowCreate();
1420 WMAddNotificationObserver(appearanceObserver, wwin,
1421 WNWindowAppearanceSettingsChanged, wwin);
1423 wwin->flags.internal_window = 1;
1425 WSETUFLAG(wwin, omnipresent, 1);
1426 WSETUFLAG(wwin, no_shadeable, 1);
1427 WSETUFLAG(wwin, no_resizable, 1);
1428 WSETUFLAG(wwin, no_miniaturizable, 1);
1430 wwin->focus_mode = WFM_PASSIVE;
1432 wwin->client_win = window;
1433 wwin->screen_ptr = scr;
1435 wwin->transient_for = owner;
1437 wwin->client.x = x;
1438 wwin->client.y = y;
1439 wwin->client.width = width;
1440 wwin->client.height = height;
1442 wwin->frame_x = wwin->client.x;
1443 wwin->frame_y = wwin->client.y;
1446 foo = WFF_RIGHT_BUTTON|WFF_BORDER;
1447 foo |= WFF_TITLEBAR;
1448 #ifdef XKB_BUTTON_HINT
1449 foo |= WFF_LANGUAGE_BUTTON;
1450 #endif
1452 wwin->frame = wFrameWindowCreate(scr, WMFloatingLevel,
1453 wwin->frame_x, wwin->frame_y,
1454 width, height,
1455 &wPreferences.window_title_clearance, foo,
1456 scr->window_title_texture,
1457 scr->resizebar_texture,
1458 scr->window_title_pixel,
1459 &scr->window_title_gc,
1460 &scr->title_font);
1462 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
1464 wwin->frame->flags.is_client_window_frame = 1;
1465 wwin->frame->flags.justification = wPreferences.title_justification;
1467 wFrameWindowChangeTitle(wwin->frame, title);
1469 /* setup button images */
1470 wWindowUpdateButtonImages(wwin);
1472 /* hide buttons */
1473 wFrameWindowHideButton(wwin->frame, WFF_RIGHT_BUTTON);
1475 wwin->frame->child = wwin;
1477 wwin->frame->workspace = wwin->screen_ptr->current_workspace;
1479 #ifdef XKB_BUTTON_HINT
1480 if (wPreferences.modelock)
1481 wwin->frame->on_click_language = windowLanguageClick;
1482 #endif
1484 wwin->frame->on_click_right = windowCloseClick;
1486 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1487 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1489 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1491 wwin->client.y += wwin->frame->top_width;
1492 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1493 0, wwin->frame->top_width);
1495 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y,
1496 wwin->client.width, wwin->client.height);
1498 /* setup the frame descriptor */
1499 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1500 wwin->frame->core->descriptor.parent = wwin;
1501 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1504 XLowerWindow(dpy, window);
1505 XMapSubwindows(dpy, wwin->frame->core->window);
1507 /* setup stacking descriptor */
1508 if (
1509 #ifdef removed
1510 wPreferences.on_top_transients &&
1511 #endif
1512 wwin->transient_for!=None
1513 && wwin->transient_for!=scr->root_win) {
1514 WWindow *tmp;
1515 tmp = wWindowFor(wwin->transient_for);
1516 if (tmp)
1517 wwin->frame->core->stacking->child_of = tmp->frame->core;
1518 } else {
1519 wwin->frame->core->stacking->child_of = NULL;
1523 if (!scr->focused_window) {
1524 /* first window on the list */
1525 wwin->next = NULL;
1526 wwin->prev = NULL;
1527 scr->focused_window = wwin;
1528 } else {
1529 WWindow *tmp;
1531 /* add window at beginning of focus window list */
1532 tmp = scr->focused_window;
1533 while (tmp->prev)
1534 tmp = tmp->prev;
1535 tmp->prev = wwin;
1536 wwin->next = tmp;
1537 wwin->prev = NULL;
1540 if (wwin->flags.is_gnustep == 0)
1541 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1543 /* if (wPreferences.auto_focus)*/
1544 wSetFocusTo(scr, wwin);
1546 wWindowResetMouseGrabs(wwin);
1548 wWindowSetKeyGrabs(wwin);
1550 return wwin;
1555 *----------------------------------------------------------------------
1556 * wUnmanageWindow--
1557 * Removes the frame window from a window and destroys all data
1558 * related to it. The window will be reparented back to the root window
1559 * if restore is True.
1561 * Side effects:
1562 * Everything related to the window is destroyed and the window
1563 * is removed from the window lists. Focus is set to the previous on the
1564 * window list.
1565 *----------------------------------------------------------------------
1567 void
1568 wUnmanageWindow(WWindow *wwin, Bool restore, Bool destroyed)
1570 WCoreWindow *frame = wwin->frame->core;
1571 WWindow *owner = NULL;
1572 WWindow *newFocusedWindow = NULL;
1573 int wasFocused;
1574 WScreen *scr = wwin->screen_ptr;
1577 /* First close attribute editor window if open */
1578 if (wwin->flags.inspector_open) {
1579 wCloseInspectorForWindow(wwin);
1582 /* Close window menu if it's open for this window */
1583 if (wwin->flags.menu_open_for_me) {
1584 CloseWindowMenu(scr);
1587 if (!destroyed) {
1588 if (!wwin->flags.internal_window)
1589 XRemoveFromSaveSet(dpy, wwin->client_win);
1591 XSelectInput(dpy, wwin->client_win, NoEventMask);
1593 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
1594 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->client_win);
1597 XUnmapWindow(dpy, frame->window);
1599 XUnmapWindow(dpy, wwin->client_win);
1601 /* deselect window */
1602 wSelectWindow(wwin, False);
1604 /* remove all pending events on window */
1605 /* I think this only matters for autoraise */
1606 if (wPreferences.raise_delay)
1607 WMDeleteTimerWithClientData(wwin->frame->core);
1609 XFlush(dpy);
1611 /* reparent the window back to the root */
1612 if (restore)
1613 wClientRestore(wwin);
1615 if (wwin->transient_for!=scr->root_win) {
1616 owner = wWindowFor(wwin->transient_for);
1617 if (owner) {
1618 if (!owner->flags.semi_focused) {
1619 owner = NULL;
1620 } else {
1621 owner->flags.semi_focused = 0;
1626 wasFocused = wwin->flags.focused;
1628 /* remove from window focus list */
1629 if (!wwin->prev && !wwin->next) {
1630 /* was the only window */
1631 scr->focused_window = NULL;
1632 newFocusedWindow = NULL;
1633 } else {
1634 WWindow *tmp;
1636 if (wwin->prev)
1637 wwin->prev->next = wwin->next;
1638 if (wwin->next)
1639 wwin->next->prev = wwin->prev;
1640 else {
1641 scr->focused_window = wwin->prev;
1642 scr->focused_window->next = NULL;
1645 if (wPreferences.focus_mode==WKF_CLICK) {
1647 /* if in click to focus mode and the window
1648 * was a transient, focus the owner window
1650 tmp = NULL;
1651 if (wPreferences.focus_mode==WKF_CLICK) {
1652 tmp = wWindowFor(wwin->transient_for);
1653 if (tmp && (!tmp->flags.mapped || WFLAGP(tmp, no_focusable))) {
1654 tmp = NULL;
1657 /* otherwise, focus the next one in the focus list */
1658 if (!tmp) {
1659 tmp = scr->focused_window;
1660 while (tmp) { /* look for one in the window list first */
1661 if (!WFLAGP(tmp, no_focusable) && !WFLAGP(tmp, skip_window_list)
1662 && (tmp->flags.mapped || tmp->flags.shaded))
1663 break;
1664 tmp = tmp->prev;
1666 if (!tmp) { /* if unsuccessful, choose any focusable window */
1667 tmp = scr->focused_window;
1668 while (tmp) {
1669 if (!WFLAGP(tmp, no_focusable)
1670 && (tmp->flags.mapped || tmp->flags.shaded))
1671 break;
1672 tmp = tmp->prev;
1677 newFocusedWindow = tmp;
1679 } else if (wPreferences.focus_mode==WKF_SLOPPY) {
1680 unsigned int mask;
1681 int foo;
1682 Window bar, win;
1684 /* This is to let the root window get the keyboard input
1685 * if Sloppy focus mode and no other window get focus.
1686 * This way keybindings will not freeze.
1688 tmp = NULL;
1689 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
1690 &foo, &foo, &foo, &foo, &mask))
1691 tmp = wWindowFor(win);
1692 if (tmp == wwin)
1693 tmp = NULL;
1694 newFocusedWindow = tmp;
1695 } else {
1696 newFocusedWindow = NULL;
1700 if (!wwin->flags.internal_window) {
1701 WMPostNotificationName(WMNUnmanaged, wwin, NULL);
1704 #ifdef DEBUG
1705 printf("destroying window %x frame %x\n", (unsigned)wwin->client_win,
1706 (unsigned)frame->window);
1707 #endif
1709 if (wasFocused) {
1710 if (newFocusedWindow != owner && owner) {
1711 if (wwin->flags.is_gnustep == 0)
1712 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1714 wSetFocusTo(scr, newFocusedWindow);
1716 wWindowDestroy(wwin);
1717 XFlush(dpy);
1721 void
1722 wWindowMap(WWindow *wwin)
1724 XMapWindow(dpy, wwin->frame->core->window);
1725 if (!wwin->flags.shaded) {
1726 /* window will be remapped when getting MapNotify */
1727 XSelectInput(dpy, wwin->client_win,
1728 wwin->event_mask & ~StructureNotifyMask);
1729 XMapWindow(dpy, wwin->client_win);
1730 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1732 wwin->flags.mapped = 1;
1737 void
1738 wWindowUnmap(WWindow *wwin)
1740 wwin->flags.mapped = 0;
1742 /* prevent window withdrawal when getting UnmapNotify */
1743 XSelectInput(dpy, wwin->client_win,
1744 wwin->event_mask & ~StructureNotifyMask);
1745 XUnmapWindow(dpy, wwin->client_win);
1746 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1748 XUnmapWindow(dpy, wwin->frame->core->window);
1753 void
1754 wWindowFocus(WWindow *wwin, WWindow *owin)
1756 WWindow *nowner;
1757 WWindow *oowner;
1759 #ifdef KEEP_XKB_LOCK_STATUS
1760 if (wPreferences.modelock) {
1761 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1763 #endif /* KEEP_XKB_LOCK_STATUS */
1765 wwin->flags.semi_focused = 0;
1767 if (wwin->flags.is_gnustep == 0)
1768 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1770 wwin->flags.focused = 1;
1772 wWindowResetMouseGrabs(wwin);
1774 WMPostNotificationName(WMNChangedFocus, wwin, (void*)True);
1776 if (owin == wwin || !owin)
1777 return;
1779 nowner = wWindowFor(wwin->transient_for);
1781 /* new window is a transient for the old window */
1782 if (nowner == owin) {
1783 owin->flags.semi_focused = 1;
1784 wWindowUnfocus(nowner);
1785 return;
1788 oowner = wWindowFor(owin->transient_for);
1790 /* new window is owner of old window */
1791 if (wwin == oowner) {
1792 wWindowUnfocus(owin);
1793 return;
1796 if (!nowner) {
1797 wWindowUnfocus(owin);
1798 return;
1801 /* new window has same owner of old window */
1802 if (oowner == nowner) {
1803 /* prevent unfocusing of owner */
1804 oowner->flags.semi_focused = 0;
1805 wWindowUnfocus(owin);
1806 oowner->flags.semi_focused = 1;
1808 return;
1811 /* nowner != NULL && oowner != nowner */
1812 nowner->flags.semi_focused = 1;
1813 wWindowUnfocus(nowner);
1814 wWindowUnfocus(owin);
1818 void
1819 wWindowUnfocus(WWindow *wwin)
1821 CloseWindowMenu(wwin->screen_ptr);
1823 if (wwin->flags.is_gnustep == 0)
1824 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused
1825 ? WS_PFOCUSED : WS_UNFOCUSED);
1827 if (wwin->transient_for!=None
1828 && wwin->transient_for!=wwin->screen_ptr->root_win) {
1829 WWindow *owner;
1830 owner = wWindowFor(wwin->transient_for);
1831 if (owner && owner->flags.semi_focused) {
1832 owner->flags.semi_focused = 0;
1833 if (owner->flags.mapped || owner->flags.shaded) {
1834 wWindowUnfocus(owner);
1835 wFrameWindowPaint(owner->frame);
1839 wwin->flags.focused = 0;
1841 wWindowResetMouseGrabs(wwin);
1843 WMPostNotificationName(WMNChangedFocus, wwin, (void*)False);
1847 void
1848 wWindowUpdateName(WWindow *wwin, char *newTitle)
1850 char *title;
1852 if (!wwin->frame)
1853 return;
1855 wwin->flags.wm_name_changed = 1;
1857 if (!newTitle) {
1858 /* the hint was removed */
1859 title = DEF_WINDOW_TITLE;
1860 } else {
1861 title = newTitle;
1864 if (wFrameWindowChangeTitle(wwin->frame, title)) {
1865 WMPostNotificationName(WMNChangedName, wwin, NULL);
1872 *----------------------------------------------------------------------
1874 * wWindowConstrainSize--
1875 * Constrains size for the client window, taking the maximal size,
1876 * window resize increments and other size hints into account.
1878 * Returns:
1879 * The closest size to what was given that the client window can
1880 * have.
1882 *----------------------------------------------------------------------
1884 void
1885 wWindowConstrainSize(WWindow *wwin, int *nwidth, int *nheight)
1887 int width = *nwidth;
1888 int height = *nheight;
1889 int winc = 1;
1890 int hinc = 1;
1891 int minW = 1, minH = 1;
1892 int maxW = wwin->screen_ptr->scr_width*2;
1893 int maxH = wwin->screen_ptr->scr_height*2;
1894 int minAX = -1, minAY = -1;
1895 int maxAX = -1, maxAY = -1;
1896 int baseW = 0;
1897 int baseH = 0;
1899 if (wwin->normal_hints) {
1900 winc = wwin->normal_hints->width_inc;
1901 hinc = wwin->normal_hints->height_inc;
1902 minW = wwin->normal_hints->min_width;
1903 minH = wwin->normal_hints->min_height;
1904 maxW = wwin->normal_hints->max_width;
1905 maxH = wwin->normal_hints->max_height;
1906 if (wwin->normal_hints->flags & PAspect) {
1907 minAX = wwin->normal_hints->min_aspect.x;
1908 minAY = wwin->normal_hints->min_aspect.y;
1909 maxAX = wwin->normal_hints->max_aspect.x;
1910 maxAY = wwin->normal_hints->max_aspect.y;
1913 baseW = wwin->normal_hints->base_width;
1914 baseH = wwin->normal_hints->base_height;
1917 if (width < minW)
1918 width = minW;
1919 if (height < minH)
1920 height = minH;
1922 if (width > maxW)
1923 width = maxW;
1924 if (height > maxH)
1925 height = maxH;
1927 /* aspect ratio code borrowed from olwm */
1928 if (minAX > 0) {
1929 /* adjust max aspect ratio */
1930 if (!(maxAX == 1 && maxAY == 1) && width * maxAY > height * maxAX) {
1931 if (maxAX > maxAY) {
1932 height = (width * maxAY) / maxAX;
1933 if (height > maxH) {
1934 height = maxH;
1935 width = (height * maxAX) / maxAY;
1937 } else {
1938 width = (height * maxAX) / maxAY;
1939 if (width > maxW) {
1940 width = maxW;
1941 height = (width * maxAY) / maxAX;
1946 /* adjust min aspect ratio */
1947 if (!(minAX == 1 && minAY == 1) && width * minAY < height * minAX) {
1948 if (minAX > minAY) {
1949 height = (width * minAY) / minAX;
1950 if (height < minH) {
1951 height = minH;
1952 width = (height * minAX) / minAY;
1954 } else {
1955 width = (height * minAX) / minAY;
1956 if (width < minW) {
1957 width = minW;
1958 height = (width * minAY) / minAX;
1964 if (baseW != 0) {
1965 width = (((width - baseW) / winc) * winc) + baseW;
1966 } else {
1967 width = (((width - minW) / winc) * winc) + minW;
1970 if (baseH != 0) {
1971 height = (((height - baseH) / hinc) * hinc) + baseH;
1972 } else {
1973 height = (((height - minH) / hinc) * hinc) + minH;
1976 /* broken stupid apps may cause preposterous values for these.. */
1977 if (width > 0)
1978 *nwidth = width;
1979 if (height > 0)
1980 *nheight = height;
1984 void
1985 wWindowCropSize(WWindow *wwin, int maxW, int maxH,
1986 int *width, int *height)
1988 int baseW = 0, baseH = 0;
1989 int winc = 1, hinc = 1;
1991 if (wwin->normal_hints) {
1992 baseW = wwin->normal_hints->base_width;
1993 baseH = wwin->normal_hints->base_height;
1995 winc = wwin->normal_hints->width_inc;
1996 hinc = wwin->normal_hints->height_inc;
1999 if (*width > maxW)
2000 *width = maxW - (maxW - baseW) % winc;
2002 if (*height > maxH)
2003 *height = maxH - (maxH - baseH) % hinc;
2007 void
2008 wWindowChangeWorkspace(WWindow *wwin, int workspace)
2010 WScreen *scr = wwin->screen_ptr;
2011 WApplication *wapp;
2012 int unmap = 0;
2014 if (workspace >= scr->workspace_count || workspace < 0
2015 || workspace == wwin->frame->workspace)
2016 return;
2018 if (workspace != scr->current_workspace) {
2019 /* Sent to other workspace. Unmap window */
2020 if ((wwin->flags.mapped
2021 || wwin->flags.shaded
2022 || (wwin->flags.miniaturized && !wPreferences.sticky_icons))
2023 && !IS_OMNIPRESENT(wwin) && !wwin->flags.changing_workspace) {
2025 wapp = wApplicationOf(wwin->main_window);
2026 if (wapp) {
2027 wapp->last_workspace = workspace;
2029 if (wwin->flags.miniaturized) {
2030 if (wwin->icon) {
2031 XUnmapWindow(dpy, wwin->icon->core->window);
2032 wwin->icon->mapped = 0;
2034 } else {
2035 unmap = 1;
2036 wSetFocusTo(scr, NULL);
2039 } else {
2040 /* brought to current workspace. Map window */
2041 if (wwin->flags.miniaturized && !wPreferences.sticky_icons) {
2042 if (wwin->icon) {
2043 XMapWindow(dpy, wwin->icon->core->window);
2044 wwin->icon->mapped = 1;
2046 } else if (!wwin->flags.mapped &&
2047 !(wwin->flags.miniaturized || wwin->flags.hidden)) {
2048 wWindowMap(wwin);
2051 if (!IS_OMNIPRESENT(wwin)) {
2052 int oldWorkspace = wwin->frame->workspace;
2054 wwin->frame->workspace = workspace;
2056 WMPostNotificationName(WMNChangedWorkspace, wwin, (void*)oldWorkspace);
2059 if (unmap) {
2060 wWindowUnmap(wwin);
2065 void
2066 wWindowSynthConfigureNotify(WWindow *wwin)
2068 XEvent sevent;
2070 sevent.type = ConfigureNotify;
2071 sevent.xconfigure.display = dpy;
2072 sevent.xconfigure.event = wwin->client_win;
2073 sevent.xconfigure.window = wwin->client_win;
2075 sevent.xconfigure.x = wwin->client.x;
2076 sevent.xconfigure.y = wwin->client.y;
2077 sevent.xconfigure.width = wwin->client.width;
2078 sevent.xconfigure.height = wwin->client.height;
2080 sevent.xconfigure.border_width = wwin->old_border_width;
2081 if (WFLAGP(wwin, no_titlebar))
2082 sevent.xconfigure.above = None;
2083 else
2084 sevent.xconfigure.above = wwin->frame->titlebar->window;
2086 sevent.xconfigure.override_redirect = False;
2087 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
2088 #ifdef KWM_HINTS
2089 wKWMSendEventMessage(wwin, WKWMChangedClient);
2090 #endif
2091 XFlush(dpy);
2096 *----------------------------------------------------------------------
2097 * wWindowConfigure--
2098 * Configures the frame, decorations and client window to the
2099 * specified geometry. The geometry is not checked for validity,
2100 * wWindowConstrainSize() must be used for that.
2101 * The size parameters are for the client window, but the position is
2102 * for the frame.
2103 * The client window receives a ConfigureNotify event, according
2104 * to what ICCCM says.
2106 * Returns:
2107 * None
2109 * Side effects:
2110 * Window size and position are changed and client window receives
2111 * a ConfigureNotify event.
2112 *----------------------------------------------------------------------
2114 void
2115 wWindowConfigure(wwin, req_x, req_y, req_width, req_height)
2116 WWindow *wwin;
2117 int req_x, req_y; /* new position of the frame */
2118 int req_width, req_height; /* new size of the client */
2120 int synth_notify = False;
2121 int resize;
2123 resize = (req_width!=wwin->client.width
2124 || req_height!=wwin->client.height);
2126 * if the window is being moved but not resized then
2127 * send a synthetic ConfigureNotify
2129 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y) && !resize) {
2130 synth_notify = True;
2133 if (WFLAGP(wwin, dont_move_off))
2134 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2135 req_width, req_height);
2136 if (resize) {
2137 if (req_width < MIN_WINDOW_SIZE)
2138 req_width = MIN_WINDOW_SIZE;
2139 if (req_height < MIN_WINDOW_SIZE)
2140 req_height = MIN_WINDOW_SIZE;
2142 /* If growing, resize inner part before frame,
2143 * if shrinking, resize frame before.
2144 * This will prevent the frame (that can have a different color)
2145 * to be exposed, causing flicker */
2146 if (req_height > wwin->frame->core->height
2147 || req_width > wwin->frame->core->width)
2148 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2150 if (wwin->flags.shaded) {
2151 wFrameWindowConfigure(wwin->frame, req_x, req_y,
2152 req_width, wwin->frame->core->height);
2153 wwin->old_geometry.height = req_height;
2154 } else {
2155 int h;
2157 h = req_height + wwin->frame->top_width
2158 + wwin->frame->bottom_width;
2160 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, h);
2163 if (!(req_height > wwin->frame->core->height
2164 || req_width > wwin->frame->core->width))
2165 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2167 wwin->client.x = req_x;
2168 wwin->client.y = req_y + wwin->frame->top_width;
2169 wwin->client.width = req_width;
2170 wwin->client.height = req_height;
2171 } else {
2172 wwin->client.x = req_x;
2173 wwin->client.y = req_y + wwin->frame->top_width;
2175 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2177 wwin->frame_x = req_x;
2178 wwin->frame_y = req_y;
2179 if (!WFLAGP(wwin, no_border)) {
2180 wwin->client.x += FRAME_BORDER_WIDTH;
2181 wwin->client.y += FRAME_BORDER_WIDTH;
2184 #ifdef SHAPE
2185 if (wShapeSupported && wwin->flags.shaped && resize) {
2186 wWindowSetShape(wwin);
2188 #endif
2190 if (synth_notify)
2191 wWindowSynthConfigureNotify(wwin);
2192 XFlush(dpy);
2196 void
2197 wWindowMove(wwin, req_x, req_y)
2198 WWindow *wwin;
2199 int req_x, req_y; /* new position of the frame */
2201 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2202 int synth_notify = False;
2204 /* Send a synthetic ConfigureNotify event for every window movement. */
2205 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y)) {
2206 synth_notify = True;
2208 #else
2209 /* A single synthetic ConfigureNotify event is sent at the end of
2210 * a completed (opaque) movement in moveres.c */
2211 #endif
2213 if (WFLAGP(wwin, dont_move_off))
2214 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2215 wwin->frame->core->width, wwin->frame->core->height);
2217 wwin->client.x = req_x;
2218 wwin->client.y = req_y + wwin->frame->top_width;
2219 if (!WFLAGP(wwin, no_border)) {
2220 wwin->client.x += FRAME_BORDER_WIDTH;
2221 wwin->client.y += FRAME_BORDER_WIDTH;
2224 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2226 wwin->frame_x = req_x;
2227 wwin->frame_y = req_y;
2229 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2230 if (synth_notify)
2231 wWindowSynthConfigureNotify(wwin);
2232 #endif
2236 void
2237 wWindowUpdateButtonImages(WWindow *wwin)
2239 WScreen *scr = wwin->screen_ptr;
2240 Pixmap pixmap, mask;
2241 WFrameWindow *fwin = wwin->frame;
2243 if (WFLAGP(wwin, no_titlebar))
2244 return;
2246 /* miniaturize button */
2248 if (!WFLAGP(wwin, no_miniaturize_button)) {
2249 if (wwin->wm_gnustep_attr
2250 && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
2251 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
2253 if (wwin->wm_gnustep_attr->flags&GSMiniaturizeMaskAttr) {
2254 mask = wwin->wm_gnustep_attr->miniaturize_mask;
2255 } else {
2256 mask = None;
2259 if (fwin->lbutton_image
2260 && (fwin->lbutton_image->image != pixmap
2261 || fwin->lbutton_image->mask != mask)) {
2262 wPixmapDestroy(fwin->lbutton_image);
2263 fwin->lbutton_image = NULL;
2266 if (!fwin->lbutton_image) {
2267 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
2268 fwin->lbutton_image->client_owned = 1;
2269 fwin->lbutton_image->client_owned_mask = 1;
2271 } else {
2272 if (fwin->lbutton_image && !fwin->lbutton_image->shared) {
2273 wPixmapDestroy(fwin->lbutton_image);
2275 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
2279 #ifdef XKB_BUTTON_HINT
2280 if (!WFLAGP(wwin, no_language_button)) {
2281 if (fwin->languagebutton_image &&
2282 !fwin->languagebutton_image->shared) {
2283 wPixmapDestroy(fwin->languagebutton_image);
2285 fwin->languagebutton_image =
2286 scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
2288 #endif
2290 /* close button */
2292 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2293 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2295 if (!WFLAGP(wwin, no_close_button)) {
2296 if (wwin->wm_gnustep_attr
2297 && wwin->wm_gnustep_attr->flags & GSClosePixmapAttr) {
2298 pixmap = wwin->wm_gnustep_attr->close_pixmap;
2300 if (wwin->wm_gnustep_attr->flags&GSCloseMaskAttr)
2301 mask = wwin->wm_gnustep_attr->close_mask;
2302 else
2303 mask = None;
2305 if (fwin->rbutton_image && (fwin->rbutton_image->image != pixmap
2306 || fwin->rbutton_image->mask != mask)) {
2307 wPixmapDestroy(fwin->rbutton_image);
2308 fwin->rbutton_image = NULL;
2311 if (!fwin->rbutton_image) {
2312 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
2313 fwin->rbutton_image->client_owned = 1;
2314 fwin->rbutton_image->client_owned_mask = 1;
2317 } else if (WFLAGP(wwin, kill_close)) {
2319 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2320 wPixmapDestroy(fwin->rbutton_image);
2322 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
2324 } else if (MGFLAGP(wwin, broken_close)) {
2326 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2327 wPixmapDestroy(fwin->rbutton_image);
2329 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
2331 } else {
2333 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2334 wPixmapDestroy(fwin->rbutton_image);
2336 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
2340 /* force buttons to be redrawn */
2341 fwin->flags.need_texture_change = 1;
2342 wFrameWindowPaint(fwin);
2347 *---------------------------------------------------------------------------
2348 * wWindowConfigureBorders--
2349 * Update window border configuration according to attribute flags.
2351 *---------------------------------------------------------------------------
2353 void
2354 wWindowConfigureBorders(WWindow *wwin)
2356 if (wwin->frame) {
2357 int flags;
2358 int newy, oldh;
2360 flags = WFF_LEFT_BUTTON|WFF_RIGHT_BUTTON;
2361 #ifdef XKB_BUTTON_HINT
2362 flags |= WFF_LANGUAGE_BUTTON;
2363 #endif
2364 if (!WFLAGP(wwin, no_titlebar))
2365 flags |= WFF_TITLEBAR;
2366 if (!WFLAGP(wwin, no_resizebar))
2367 flags |= WFF_RESIZEBAR;
2368 if (!WFLAGP(wwin, no_border))
2369 flags |= WFF_BORDER;
2370 if (wwin->flags.shaded)
2371 flags |= WFF_IS_SHADED;
2373 oldh = wwin->frame->top_width;
2374 wFrameWindowUpdateBorders(wwin->frame, flags);
2375 if (oldh != wwin->frame->top_width) {
2376 newy = wwin->frame_y + oldh - wwin->frame->top_width;
2378 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2379 wWindowConfigure(wwin, wwin->frame_x, newy,
2380 wwin->client.width, wwin->client.height);
2383 flags = 0;
2384 if (!WFLAGP(wwin, no_miniaturize_button)
2385 && wwin->frame->flags.hide_left_button)
2386 flags |= WFF_LEFT_BUTTON;
2388 #ifdef XKB_BUTTON_HINT
2389 if (!WFLAGP(wwin, no_language_button)
2390 && wwin->frame->flags.hide_language_button)
2391 flags |= WFF_LANGUAGE_BUTTON;
2392 #endif
2394 if (!WFLAGP(wwin, no_close_button)
2395 && wwin->frame->flags.hide_right_button)
2396 flags |= WFF_RIGHT_BUTTON;
2398 if (flags!=0) {
2399 wWindowUpdateButtonImages(wwin);
2400 wFrameWindowShowButton(wwin->frame, flags);
2403 flags = 0;
2404 if (WFLAGP(wwin, no_miniaturize_button)
2405 && !wwin->frame->flags.hide_left_button)
2406 flags |= WFF_LEFT_BUTTON;
2408 #ifdef XKB_BUTTON_HINT
2409 if (WFLAGP(wwin, no_language_button)
2410 && !wwin->frame->flags.hide_language_button)
2411 flags |= WFF_LANGUAGE_BUTTON;
2412 #endif
2414 if (WFLAGP(wwin, no_close_button)
2415 && !wwin->frame->flags.hide_right_button)
2416 flags |= WFF_RIGHT_BUTTON;
2418 if (flags!=0)
2419 wFrameWindowHideButton(wwin->frame, flags);
2421 #ifdef SHAPE
2422 if (wShapeSupported && wwin->flags.shaped) {
2423 wWindowSetShape(wwin);
2425 #endif
2430 void
2431 wWindowSaveState(WWindow *wwin)
2433 CARD32 data[10];
2434 int i;
2436 memset(data, 0, sizeof(CARD32)*10);
2437 data[0] = wwin->frame->workspace;
2438 data[1] = wwin->flags.miniaturized;
2439 data[2] = wwin->flags.shaded;
2440 data[3] = wwin->flags.hidden;
2441 data[4] = wwin->flags.maximized;
2442 if (wwin->flags.maximized == 0) {
2443 data[5] = wwin->frame_x;
2444 data[6] = wwin->frame_y;
2445 data[7] = wwin->frame->core->width;
2446 data[8] = wwin->frame->core->height;
2447 } else {
2448 data[5] = wwin->old_geometry.x;
2449 data[6] = wwin->old_geometry.y;
2450 data[7] = wwin->old_geometry.width;
2451 data[8] = wwin->old_geometry.height;
2454 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
2455 if (wwin->screen_ptr->shortcutWindows[i] &&
2456 WMCountInArray(wwin->screen_ptr->shortcutWindows[i], wwin))
2457 data[9] |= 1<<i;
2459 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
2460 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
2461 (unsigned char *)data, 10);
2465 static int
2466 getSavedState(Window window, WSavedState **state)
2468 Atom type_ret;
2469 int fmt_ret;
2470 unsigned long nitems_ret;
2471 unsigned long bytes_after_ret;
2472 CARD32 *data;
2474 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
2475 True, _XA_WINDOWMAKER_STATE,
2476 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
2477 (unsigned char **)&data)!=Success || !data)
2478 return 0;
2480 *state = wmalloc(sizeof(WSavedState));
2482 (*state)->workspace = data[0];
2483 (*state)->miniaturized = data[1];
2484 (*state)->shaded = data[2];
2485 (*state)->hidden = data[3];
2486 (*state)->maximized = data[4];
2487 (*state)->x = data[5];
2488 (*state)->y = data[6];
2489 (*state)->w = data[7];
2490 (*state)->h = data[8];
2491 (*state)->window_shortcuts = data[9];
2493 XFree(data);
2495 if (*state && type_ret==_XA_WINDOWMAKER_STATE)
2496 return 1;
2497 else
2498 return 0;
2502 #ifdef SHAPE
2503 void
2504 wWindowClearShape(WWindow *wwin)
2506 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
2507 0, wwin->frame->top_width, None, ShapeSet);
2508 XFlush(dpy);
2511 void
2512 wWindowSetShape(WWindow *wwin)
2514 XRectangle rect[2];
2515 int count;
2516 #ifdef OPTIMIZE_SHAPE
2517 XRectangle *rects;
2518 XRectangle *urec;
2519 int ordering;
2521 /* only shape is the client's */
2522 if (WFLAGP(wwin, no_titlebar) && WFLAGP(wwin, no_resizebar)) {
2523 goto alt_code;
2526 /* Get array of rectangles describing the shape mask */
2527 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding,
2528 &count, &ordering);
2529 if (!rects) {
2530 goto alt_code;
2533 urec = malloc(sizeof(XRectangle)*(count+2));
2534 if (!urec) {
2535 XFree(rects);
2536 goto alt_code;
2539 /* insert our decoration rectangles in the rect list */
2540 memcpy(urec, rects, sizeof(XRectangle)*count);
2541 XFree(rects);
2543 if (!WFLAGP(wwin, no_titlebar)) {
2544 urec[count].x = -1;
2545 urec[count].y = -1 - wwin->frame->top_width;
2546 urec[count].width = wwin->frame->core->width + 2;
2547 urec[count].height = wwin->frame->top_width + 1;
2548 count++;
2550 if (!WFLAGP(wwin, no_resizebar)) {
2551 urec[count].x = -1;
2552 urec[count].y = wwin->frame->core->height
2553 - wwin->frame->bottom_width - wwin->frame->top_width;
2554 urec[count].width = wwin->frame->core->width + 2;
2555 urec[count].height = wwin->frame->bottom_width + 1;
2556 count++;
2559 /* shape our frame window */
2560 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2561 0, wwin->frame->top_width, urec, count,
2562 ShapeSet, Unsorted);
2563 XFlush(dpy);
2564 wfree(urec);
2565 return;
2567 alt_code:
2568 #endif /* OPTIMIZE_SHAPE */
2569 count = 0;
2570 if (!WFLAGP(wwin, no_titlebar)) {
2571 rect[count].x = -1;
2572 rect[count].y = -1;
2573 rect[count].width = wwin->frame->core->width + 2;
2574 rect[count].height = wwin->frame->top_width + 1;
2575 count++;
2577 if (!WFLAGP(wwin, no_resizebar)) {
2578 rect[count].x = -1;
2579 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
2580 rect[count].width = wwin->frame->core->width + 2;
2581 rect[count].height = wwin->frame->bottom_width + 1;
2582 count++;
2584 if (count > 0) {
2585 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2586 0, 0, rect, count, ShapeSet, Unsorted);
2588 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
2589 0, wwin->frame->top_width, wwin->client_win,
2590 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
2591 XFlush(dpy);
2593 #endif /* SHAPE */
2595 /* ====================================================================== */
2597 static FocusMode
2598 getFocusMode(WWindow *wwin)
2600 FocusMode mode;
2602 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
2603 if (wwin->wm_hints->input == True) {
2604 if (wwin->protocols.TAKE_FOCUS)
2605 mode = WFM_LOCALLY_ACTIVE;
2606 else
2607 mode = WFM_PASSIVE;
2608 } else {
2609 if (wwin->protocols.TAKE_FOCUS)
2610 mode = WFM_GLOBALLY_ACTIVE;
2611 else
2612 mode = WFM_NO_INPUT;
2614 } else {
2615 mode = WFM_PASSIVE;
2617 return mode;
2621 void
2622 wWindowSetKeyGrabs(WWindow *wwin)
2624 int i;
2625 WShortKey *key;
2627 for (i=0; i<WKBD_LAST; i++) {
2628 key = &wKeyBindings[i];
2630 if (key->keycode==0)
2631 continue;
2632 if (key->modifier!=AnyModifier) {
2633 XGrabKey(dpy, key->keycode, key->modifier|LockMask,
2634 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2635 #ifdef NUMLOCK_HACK
2636 /* Also grab all modifier combinations possible that include,
2637 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2638 * work even if the NumLock/ScrollLock key is on.
2640 wHackedGrabKey(key->keycode, key->modifier,
2641 wwin->frame->core->window, True, GrabModeAsync,
2642 GrabModeAsync);
2643 #endif
2645 XGrabKey(dpy, key->keycode, key->modifier,
2646 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2649 #ifndef LITE
2650 wRootMenuBindShortcuts(wwin->frame->core->window);
2651 #endif
2656 void
2657 wWindowResetMouseGrabs(WWindow *wwin)
2659 /* Mouse grabs can't be done on the client window because of
2660 * ICCCM and because clients that try to do the same will crash.
2662 * But there is a problem wich makes tbar buttons of unfocused
2663 * windows not usable as the click goes to the frame window instead
2664 * of the button itself. Must figure a way to fix that.
2667 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2669 if (!WFLAGP(wwin, no_bind_mouse)) {
2670 /* grabs for Meta+drag */
2671 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2672 True, ButtonPressMask, GrabModeSync,
2673 GrabModeAsync, None, None);
2676 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable)
2677 && !wwin->flags.is_gnustep) {
2678 /* the passive grabs to focus the window */
2679 /* if (wPreferences.focus_mode == WKF_CLICK) */
2680 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2681 True, ButtonPressMask, GrabModeSync, GrabModeAsync,
2682 None, None);
2684 XFlush(dpy);
2688 void
2689 wWindowUpdateGNUstepAttr(WWindow *wwin, GNUstepWMAttributes *attr)
2691 if (attr->flags & GSExtraFlagsAttr) {
2692 if (MGFLAGP(wwin, broken_close) !=
2693 (attr->extra_flags & GSDocumentEditedFlag)) {
2694 wwin->client_flags.broken_close = !MGFLAGP(wwin, broken_close);
2695 wWindowUpdateButtonImages(wwin);
2701 WMagicNumber
2702 wWindowAddSavedState(char *instance, char *class, char *command,
2703 pid_t pid, WSavedState *state)
2705 WWindowState *wstate;
2707 wstate = malloc(sizeof(WWindowState));
2708 if (!wstate)
2709 return 0;
2711 memset(wstate, 0, sizeof(WWindowState));
2712 wstate->pid = pid;
2713 if (instance)
2714 wstate->instance = wstrdup(instance);
2715 if (class)
2716 wstate->class = wstrdup(class);
2717 if (command)
2718 wstate->command = wstrdup(command);
2719 wstate->state = state;
2721 wstate->next = windowState;
2722 windowState = wstate;
2724 #ifdef DEBUG
2725 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2726 class, command);
2727 #endif
2729 return wstate;
2733 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2736 WMagicNumber
2737 wWindowGetSavedState(Window win)
2739 char *instance, *class, *command=NULL;
2740 WWindowState *wstate = windowState;
2741 char **argv;
2742 int argc;
2744 if (!wstate)
2745 return NULL;
2747 if (XGetCommand(dpy, win, &argv, &argc)) {
2748 if (argc > 0)
2749 command = wtokenjoin(argv, argc);
2750 XFreeStringList(argv);
2752 if (!command)
2753 return NULL;
2755 if (PropGetWMClass(win, &class, &instance)) {
2756 while (wstate) {
2757 if (SAME(instance, wstate->instance) &&
2758 SAME(class, wstate->class) &&
2759 SAME(command, wstate->command)) {
2760 break;
2762 wstate = wstate->next;
2764 } else {
2765 wstate = NULL;
2768 #ifdef DEBUG
2769 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2770 class, command);
2771 #endif
2773 if (command) wfree(command);
2774 if (instance) XFree(instance);
2775 if (class) XFree(class);
2777 return wstate;
2781 void
2782 wWindowDeleteSavedState(WMagicNumber id)
2784 WWindowState *tmp, *wstate=(WWindowState*)id;
2786 if (!wstate || !windowState)
2787 return;
2789 tmp = windowState;
2790 if (tmp==wstate) {
2791 windowState = wstate->next;
2792 #ifdef DEBUG
2793 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2794 wstate, wstate->instance, wstate->class, wstate->command);
2795 #endif
2796 if (wstate->instance) wfree(wstate->instance);
2797 if (wstate->class) wfree(wstate->class);
2798 if (wstate->command) wfree(wstate->command);
2799 wfree(wstate->state);
2800 wfree(wstate);
2801 } else {
2802 while (tmp->next) {
2803 if (tmp->next==wstate) {
2804 tmp->next=wstate->next;
2805 #ifdef DEBUG
2806 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2807 wstate, wstate->instance, wstate->class, wstate->command);
2808 #endif
2809 if (wstate->instance) wfree(wstate->instance);
2810 if (wstate->class) wfree(wstate->class);
2811 if (wstate->command) wfree(wstate->command);
2812 wfree(wstate->state);
2813 wfree(wstate);
2814 break;
2816 tmp = tmp->next;
2822 void
2823 wWindowDeleteSavedStatesForPID(pid_t pid)
2825 WWindowState *tmp, *wstate;
2827 if (!windowState)
2828 return;
2830 tmp = windowState;
2831 if (tmp->pid == pid) {
2832 wstate = windowState;
2833 windowState = tmp->next;
2834 #ifdef DEBUG
2835 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2836 wstate, wstate->instance, wstate->class, wstate->command);
2837 #endif
2838 if (wstate->instance) wfree(wstate->instance);
2839 if (wstate->class) wfree(wstate->class);
2840 if (wstate->command) wfree(wstate->command);
2841 wfree(wstate->state);
2842 wfree(wstate);
2843 } else {
2844 while (tmp->next) {
2845 if (tmp->next->pid==pid) {
2846 wstate = tmp->next;
2847 tmp->next = wstate->next;
2848 #ifdef DEBUG
2849 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2850 wstate, wstate->instance, wstate->class, wstate->command);
2851 #endif
2852 if (wstate->instance) wfree(wstate->instance);
2853 if (wstate->class) wfree(wstate->class);
2854 if (wstate->command) wfree(wstate->command);
2855 wfree(wstate->state);
2856 wfree(wstate);
2857 break;
2859 tmp = tmp->next;
2865 void
2866 wWindowSetOmnipresent(WWindow *wwin, Bool flag)
2868 wwin->flags.omnipresent = flag;
2870 WMPostNotificationName(WMNChangedState, wwin, "omnipresent");
2874 /* ====================================================================== */
2876 static void
2877 resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2879 WWindow *wwin = data;
2881 #ifndef NUMLOCK_HACK
2882 if ((event->xbutton.state & ValidModMask)
2883 != (event->xbutton.state & ~LockMask)) {
2884 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2885 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2887 #endif
2889 event->xbutton.state &= ValidModMask;
2891 CloseWindowMenu(wwin->screen_ptr);
2893 if (wPreferences.focus_mode==WKF_CLICK
2894 && !(event->xbutton.state&ControlMask)
2895 && !WFLAGP(wwin, no_focusable)) {
2896 wSetFocusTo(wwin->screen_ptr, wwin);
2899 if (event->xbutton.button == Button1)
2900 wRaiseFrame(wwin->frame->core);
2902 if (event->xbutton.window != wwin->frame->resizebar->window) {
2903 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
2904 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2905 GrabModeAsync, GrabModeAsync, None,
2906 None, CurrentTime)!=GrabSuccess) {
2907 #ifdef DEBUG0
2908 wwarning("pointer grab failed for window move");
2909 #endif
2910 return;
2914 if (event->xbutton.state & MOD_MASK) {
2915 /* move the window */
2916 wMouseMoveWindow(wwin, event);
2917 XUngrabPointer(dpy, CurrentTime);
2918 } else {
2919 wMouseResizeWindow(wwin, event);
2920 XUngrabPointer(dpy, CurrentTime);
2926 static void
2927 titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
2929 WWindow *wwin = data;
2931 event->xbutton.state &= ValidModMask;
2933 if (event->xbutton.button==Button1) {
2934 if (event->xbutton.state == 0) {
2935 if (!WFLAGP(wwin, no_shadeable)) {
2936 /* shade window */
2937 if (wwin->flags.shaded)
2938 wUnshadeWindow(wwin);
2939 else
2940 wShadeWindow(wwin);
2942 } else {
2943 int dir = 0;
2945 if (event->xbutton.state & ControlMask)
2946 dir |= MAX_VERTICAL;
2948 if (event->xbutton.state & ShiftMask) {
2949 dir |= MAX_HORIZONTAL;
2950 if (!(event->xbutton.state & ControlMask))
2951 wSelectWindow(wwin, !wwin->flags.selected);
2954 /* maximize window */
2955 if (dir!=0 && !WFLAGP(wwin, no_resizable)) {
2956 int ndir = dir ^ wwin->flags.maximized;
2957 if (wwin->flags.maximized != 0)
2958 wUnmaximizeWindow(wwin);
2959 if (ndir != 0)
2960 wMaximizeWindow(wwin, ndir);
2963 } else if (event->xbutton.button==Button3) {
2964 if (event->xbutton.state & MOD_MASK) {
2965 wHideOtherApplications(wwin);
2967 } else if (event->xbutton.button==Button2) {
2968 wSelectWindow(wwin, !wwin->flags.selected);
2969 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelUp) {
2970 wShadeWindow(wwin);
2971 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelDown) {
2972 wUnshadeWindow(wwin);
2977 static void
2978 frameMouseDown(WObjDescriptor *desc, XEvent *event)
2980 WWindow *wwin = desc->parent;
2982 event->xbutton.state &= ValidModMask;
2984 CloseWindowMenu(wwin->screen_ptr);
2986 if (/*wPreferences.focus_mode==WKF_CLICK
2987 &&*/ !(event->xbutton.state&ControlMask)
2988 && !WFLAGP(wwin, no_focusable)) {
2989 wSetFocusTo(wwin->screen_ptr, wwin);
2991 if (event->xbutton.button == Button1) {
2992 wRaiseFrame(wwin->frame->core);
2995 if (event->xbutton.state & MOD_MASK) {
2996 /* move the window */
2997 if (XGrabPointer(dpy, wwin->client_win, False,
2998 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2999 GrabModeAsync, GrabModeAsync, None,
3000 None, CurrentTime)!=GrabSuccess) {
3001 #ifdef DEBUG0
3002 wwarning("pointer grab failed for window move");
3003 #endif
3004 return;
3006 if (event->xbutton.button == Button3 && !WFLAGP(wwin, no_resizable))
3007 wMouseResizeWindow(wwin, event);
3008 else
3009 wMouseMoveWindow(wwin, event);
3010 XUngrabPointer(dpy, CurrentTime);
3015 static void
3016 titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
3018 WWindow *wwin = (WWindow*)data;
3020 #ifndef NUMLOCK_HACK
3021 if ((event->xbutton.state & ValidModMask)
3022 != (event->xbutton.state & ~LockMask)) {
3023 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
3024 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3026 #endif
3027 event->xbutton.state &= ValidModMask;
3029 CloseWindowMenu(wwin->screen_ptr);
3031 if (wPreferences.focus_mode==WKF_CLICK
3032 && !(event->xbutton.state&ControlMask)
3033 && !WFLAGP(wwin, no_focusable)) {
3034 wSetFocusTo(wwin->screen_ptr, wwin);
3037 if (event->xbutton.button == Button1
3038 || event->xbutton.button == Button2) {
3040 if (event->xbutton.button == Button1) {
3041 if (event->xbutton.state & MOD_MASK) {
3042 wLowerFrame(wwin->frame->core);
3043 } else {
3044 wRaiseFrame(wwin->frame->core);
3047 if ((event->xbutton.state & ShiftMask)
3048 && !(event->xbutton.state & ControlMask)) {
3049 wSelectWindow(wwin, !wwin->flags.selected);
3050 return;
3052 if (event->xbutton.window != wwin->frame->titlebar->window
3053 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
3054 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
3055 GrabModeAsync, GrabModeAsync, None,
3056 None, CurrentTime)!=GrabSuccess) {
3057 #ifdef DEBUG0
3058 wwarning("pointer grab failed for window move");
3059 #endif
3060 return;
3063 /* move the window */
3064 wMouseMoveWindow(wwin, event);
3066 XUngrabPointer(dpy, CurrentTime);
3067 } else if (event->xbutton.button == Button3 && event->xbutton.state==0
3068 && !wwin->flags.internal_window
3069 && !WCHECK_STATE(WSTATE_MODAL)) {
3070 WObjDescriptor *desc;
3072 if (event->xbutton.window != wwin->frame->titlebar->window
3073 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
3074 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
3075 GrabModeAsync, GrabModeAsync, None,
3076 None, CurrentTime)!=GrabSuccess) {
3077 #ifdef DEBUG0
3078 wwarning("pointer grab failed for window move");
3079 #endif
3080 return;
3083 OpenWindowMenu(wwin, event->xbutton.x_root,
3084 wwin->frame_y+wwin->frame->top_width, False);
3086 /* allow drag select */
3087 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
3088 event->xany.send_event = True;
3089 (*desc->handle_mousedown)(desc, event);
3091 XUngrabPointer(dpy, CurrentTime);
3097 static void
3098 windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
3100 WWindow *wwin = data;
3102 event->xbutton.state &= ValidModMask;
3104 CloseWindowMenu(wwin->screen_ptr);
3106 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3107 return;
3109 /* if control-click, kill the client */
3110 if (event->xbutton.state & ControlMask) {
3111 wClientKill(wwin);
3112 } else {
3113 #ifdef OLWM_HINTS
3114 if (wwin->flags.olwm_push_pin_out) {
3116 wwin->flags.olwm_push_pin_out = 0;
3118 wOLWMChangePushpinState(wwin, True);
3120 wFrameWindowUpdatePushButton(wwin->frame, False);
3122 return;
3124 #endif
3125 if (wwin->protocols.DELETE_WINDOW && event->xbutton.state==0) {
3126 /* send delete message */
3127 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3133 static void
3134 windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
3136 WWindow *wwin = data;
3138 CloseWindowMenu(wwin->screen_ptr);
3140 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3141 return;
3143 /* send delete message */
3144 if (wwin->protocols.DELETE_WINDOW) {
3145 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3146 } else {
3147 wClientKill(wwin);
3152 #ifdef XKB_BUTTON_HINT
3153 static void
3154 windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event)
3156 WWindow *wwin = data;
3157 WFrameWindow *fwin = wwin->frame;
3158 WScreen *scr = fwin->screen_ptr;
3159 XkbStateRec staterec;
3160 int tl;
3162 if (event->xbutton.button != Button1 && event->xbutton.button != Button3)
3163 return;
3164 tl = wwin->frame->languagemode;
3165 wwin->frame->languagemode = wwin->frame->last_languagemode;
3166 wwin->frame->last_languagemode = tl;
3167 wSetFocusTo(scr, wwin);
3168 wwin->frame->languagebutton_image =
3169 wwin->frame->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 +
3170 wwin->frame->languagemode];
3171 wFrameWindowUpdateLanguageButton(wwin->frame);
3172 if (event->xbutton.button == Button3)
3173 return;
3174 wRaiseFrame(fwin->core);
3176 #endif
3179 static void
3180 windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
3182 WWindow *wwin = data;
3184 event->xbutton.state &= ValidModMask;
3186 CloseWindowMenu(wwin->screen_ptr);
3188 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3189 return;
3191 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state==0) {
3192 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
3193 LastTimestamp);
3194 } else {
3195 WApplication *wapp;
3196 if ((event->xbutton.state & ControlMask) ||
3197 (event->xbutton.button == Button3)) {
3199 wapp = wApplicationOf(wwin->main_window);
3200 if (wapp && !WFLAGP(wwin, no_appicon))
3201 wHideApplication(wapp);
3202 } else if (event->xbutton.state==0) {
3203 wIconifyWindow(wwin);