- Fixed problem with unhiding taht mapped windows from other workspaces
[wmaker-crm.git] / src / window.c
blobaaaeb3935c01bfa3f8838501cac1ac3787eadcd8
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 (wwin->flags.is_gnustep) {
802 WSETUFLAG(wwin, shared_appicon, 0);
806 extern Atom _XA_WINDOWMAKER_MENU;
807 XTextProperty text_prop;
809 if (XGetTextProperty(dpy, wwin->main_window, &text_prop,
810 _XA_WINDOWMAKER_MENU)) {
811 WSETUFLAG(wwin, shared_appicon, 0);
815 if (!withdraw && wwin->main_window && WFLAGP(wwin, shared_appicon)) {
816 char *buffer, *instance, *class;
817 WFakeGroupLeader *fPtr;
818 int index;
820 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
822 PropGetWMClass(wwin->main_window, &class, &instance);
823 buffer = wmalloc(strlen(instance)+strlen(class)+2);
824 sprintf(buffer, "%s.%s", instance, class);
826 index = WMFindInArray(scr->fakeGroupLeaders, matchIdentifier, (void*)buffer);
827 if (index != WANotFound) {
828 fPtr = WMGetFromArray(scr->fakeGroupLeaders, index);
829 if (fPtr->retainCount == 0) {
830 fPtr->leader = createFakeWindowGroupLeader(scr, wwin->main_window,
831 instance, class);
833 fPtr->retainCount++;
834 #undef method2
835 if (fPtr->origLeader==None) {
836 #ifdef method2
837 if (ADEQUATE(wwin->group_id)) {
838 fPtr->retainCount++;
839 fPtr->origLeader = wwin->group_id;
840 } else if (ADEQUATE(wwin->client_leader)) {
841 fPtr->retainCount++;
842 fPtr->origLeader = wwin->client_leader;
843 } else if (ADEQUATE(wwin->main_window)) {
844 fPtr->retainCount++;
845 fPtr->origLeader = wwin->main_window;
847 #else
848 if (ADEQUATE(wwin->main_window)) {
849 fPtr->retainCount++;
850 fPtr->origLeader = wwin->main_window;
852 #endif
854 wwin->fake_group = fPtr;
855 /*wwin->group_id = fPtr->leader;*/
856 wwin->main_window = fPtr->leader;
857 wfree(buffer);
858 } else {
859 fPtr = (WFakeGroupLeader*)wmalloc(sizeof(WFakeGroupLeader));
861 fPtr->identifier = buffer;
862 fPtr->leader = createFakeWindowGroupLeader(scr, wwin->main_window,
863 instance, class);
864 fPtr->origLeader = None;
865 fPtr->retainCount = 1;
867 WMAddToArray(scr->fakeGroupLeaders, fPtr);
869 #ifdef method2
870 if (ADEQUATE(wwin->group_id)) {
871 fPtr->retainCount++;
872 fPtr->origLeader = wwin->group_id;
873 } else if (ADEQUATE(wwin->client_leader)) {
874 fPtr->retainCount++;
875 fPtr->origLeader = wwin->client_leader;
876 } else if (ADEQUATE(wwin->main_window)) {
877 fPtr->retainCount++;
878 fPtr->origLeader = wwin->main_window;
880 #else
881 if (ADEQUATE(wwin->main_window)) {
882 fPtr->retainCount++;
883 fPtr->origLeader = wwin->main_window;
885 #endif
886 wwin->fake_group = fPtr;
887 /*wwin->group_id = fPtr->leader;*/
888 wwin->main_window = fPtr->leader;
890 if (instance)
891 XFree(instance);
892 if (class)
893 XFree(class);
895 #undef method2
896 #undef ADEQUATE
900 *------------------------------------------------------------
902 * Setup the initial state of the window
904 *------------------------------------------------------------
907 if (WFLAGP(wwin, start_miniaturized) && !WFLAGP(wwin, no_miniaturizable)) {
908 wwin->flags.miniaturized = 1;
911 if (WFLAGP(wwin, start_maximized) && !WFLAGP(wwin, no_resizable)) {
912 wwin->flags.maximized = MAX_VERTICAL|MAX_HORIZONTAL;
916 Bool bla;
918 bla = False;
919 #ifdef GNOME_STUFF
920 bla = wGNOMECheckInitialClientState(wwin);
921 #endif
922 #ifdef KWM_HINTS
923 if (!bla)
924 wKWMCheckClientInitialState(wwin);
925 #endif
928 /* apply previous state if it exists and we're in startup */
929 if (scr->flags.startup && wm_state >= 0) {
931 if (wm_state == IconicState) {
933 wwin->flags.miniaturized = 1;
935 } else if (wm_state == WithdrawnState) {
937 withdraw = True;
941 /* if there is a saved state (from file), restore it */
942 win_state = NULL;
943 if (wwin->main_window!=None/* && wwin->main_window!=window*/) {
944 win_state = (WWindowState*)wWindowGetSavedState(wwin->main_window);
945 } else {
946 win_state = (WWindowState*)wWindowGetSavedState(window);
948 if (win_state && !withdraw) {
950 if (win_state->state->hidden>0)
951 wwin->flags.hidden = win_state->state->hidden;
953 if (win_state->state->shaded>0 && !WFLAGP(wwin, no_shadeable))
954 wwin->flags.shaded = win_state->state->shaded;
956 if (win_state->state->miniaturized>0 &&
957 !WFLAGP(wwin, no_miniaturizable)) {
958 wwin->flags.miniaturized = win_state->state->miniaturized;
961 if (!IS_OMNIPRESENT(wwin)) {
962 int w = wDefaultGetStartWorkspace(scr, wwin->wm_instance,
963 wwin->wm_class);
964 if (w < 0 || w >= scr->workspace_count) {
965 workspace = win_state->state->workspace;
966 if (workspace >= scr->workspace_count)
967 workspace = scr->current_workspace;
968 } else {
969 workspace = w;
971 } else {
972 workspace = scr->current_workspace;
976 /* if we're restarting, restore saved state (from hints).
977 * This will overwrite previous */
979 WSavedState *wstate;
981 if (getSavedState(window, &wstate)) {
982 wwin->flags.shaded = wstate->shaded;
983 wwin->flags.hidden = wstate->hidden;
984 wwin->flags.miniaturized = wstate->miniaturized;
985 wwin->flags.maximized = wstate->maximized;
986 if (wwin->flags.maximized) {
987 wwin->old_geometry.x = wstate->x;
988 wwin->old_geometry.y = wstate->y;
989 wwin->old_geometry.width = wstate->w;
990 wwin->old_geometry.height = wstate->h;
993 workspace = wstate->workspace;
994 } else {
995 wstate = NULL;
998 /* restore window shortcut */
999 if (wstate != NULL || win_state != NULL) {
1000 unsigned mask = 0;
1002 if (win_state != NULL)
1003 mask = win_state->state->window_shortcuts;
1005 if (wstate != NULL && mask == 0)
1006 mask = wstate->window_shortcuts;
1008 if (mask > 0) {
1009 int i;
1011 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
1012 if (mask & (1<<i)) {
1013 if (!scr->shortcutWindows[i])
1014 scr->shortcutWindows[i] = WMCreateArray(4);
1016 WMAddToArray(scr->shortcutWindows[i], wwin);
1021 if (wstate != NULL) {
1022 wfree(wstate);
1026 /* don't let transients start miniaturized if their owners are not */
1027 if (transientOwner && !transientOwner->flags.miniaturized
1028 && wwin->flags.miniaturized && !withdraw) {
1029 wwin->flags.miniaturized = 0;
1030 if (wwin->wm_hints)
1031 wwin->wm_hints->initial_state = NormalState;
1034 /* set workspace on which the window starts */
1035 if (workspace >= 0) {
1036 if (workspace > scr->workspace_count-1) {
1037 workspace = workspace % scr->workspace_count;
1039 } else {
1040 int w;
1042 w = wDefaultGetStartWorkspace(scr, wwin->wm_instance, wwin->wm_class);
1044 if (w >= 0 && w < scr->workspace_count && !(IS_OMNIPRESENT(wwin))) {
1046 workspace = w;
1048 } else {
1049 if (wPreferences.open_transients_with_parent && transientOwner) {
1051 workspace = transientOwner->frame->workspace;
1053 } else {
1055 workspace = scr->current_workspace;
1060 /* setup window geometry */
1061 if (win_state && win_state->state->w > 0) {
1062 width = win_state->state->w;
1063 height = win_state->state->h;
1065 wWindowConstrainSize(wwin, &width, &height);
1067 /* do not ask for window placement if the window is
1068 * transient, during startup, if the initial workspace is another one
1069 * or if the window wants to start iconic.
1070 * If geometry was saved, restore it. */
1072 Bool dontBring = False;
1074 if (win_state && win_state->state->w > 0) {
1075 x = win_state->state->x;
1076 y = win_state->state->y;
1077 } else if ((wwin->transient_for==None
1078 || wPreferences.window_placement!=WPM_MANUAL)
1079 && !scr->flags.startup
1080 && workspace == scr->current_workspace
1081 && !wwin->flags.miniaturized
1082 && !wwin->flags.maximized
1083 && !(wwin->normal_hints->flags & (USPosition|PPosition))) {
1085 if (transientOwner && transientOwner->flags.mapped) {
1086 int offs = WMAX(20, 2*transientOwner->frame->top_width);
1088 x = transientOwner->frame_x +
1089 abs((transientOwner->frame->core->width - width)/2) + offs;
1090 y = transientOwner->frame_y +
1091 abs((transientOwner->frame->core->height - height)/3) + offs;
1093 if (x < 0)
1094 x = 0;
1095 else if (x + width > scr->scr_width)
1096 x = scr->scr_width - width;
1098 if (y < 0)
1099 y = 0;
1100 else if (y + height > scr->scr_height)
1101 y = scr->scr_height - height;
1102 } else {
1103 PlaceWindow(wwin, &x, &y, width, height);
1105 if (wPreferences.window_placement == WPM_MANUAL)
1106 dontBring = True;
1109 if (WFLAGP(wwin, dont_move_off) && dontBring)
1110 wScreenBringInside(scr, &x, &y, width, height);
1113 if (wwin->flags.urgent) {
1114 if (!IS_OMNIPRESENT(wwin))
1115 wwin->flags.omnipresent ^= 1;
1119 *--------------------------------------------------
1121 * Create frame, borders and do reparenting
1123 *--------------------------------------------------
1125 foo = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
1126 #ifdef XKB_BUTTON_HINT
1127 if (wPreferences.modelock)
1128 foo |= WFF_LANGUAGE_BUTTON;
1129 #endif
1130 if (!WFLAGP(wwin, no_titlebar))
1131 foo |= WFF_TITLEBAR;
1132 if (!WFLAGP(wwin, no_resizebar))
1133 foo |= WFF_RESIZEBAR;
1134 if (!WFLAGP(wwin, no_border))
1135 foo |= WFF_BORDER;
1137 wwin->frame = wFrameWindowCreate(scr, window_level,
1138 x, y, width, height,
1139 &wPreferences.window_title_clearance, foo,
1140 scr->window_title_texture,
1141 scr->resizebar_texture,
1142 scr->window_title_pixel,
1143 &scr->window_title_gc,
1144 &scr->title_font);
1146 wwin->frame->flags.is_client_window_frame = 1;
1147 wwin->frame->flags.justification = wPreferences.title_justification;
1149 /* setup button images */
1150 wWindowUpdateButtonImages(wwin);
1152 /* hide unused buttons */
1153 foo = 0;
1154 if (WFLAGP(wwin, no_close_button))
1155 foo |= WFF_RIGHT_BUTTON;
1156 if (WFLAGP(wwin, no_miniaturize_button))
1157 foo |= WFF_LEFT_BUTTON;
1158 #ifdef XKB_BUTTON_HINT
1159 if (WFLAGP(wwin, no_language_button) || WFLAGP(wwin, no_focusable))
1160 foo |= WFF_LANGUAGE_BUTTON;
1161 #endif
1162 if (foo!=0)
1163 wFrameWindowHideButton(wwin->frame, foo);
1165 wwin->frame->child = wwin;
1167 #ifdef OLWM_HINTS
1168 /* emulate olwm push pin. Make the button look as pushed-in for
1169 * the pinned-out state. When the button is clicked, it will
1170 * revert to the normal position, which means the pin is pinned-in.
1172 if (wwin->flags.olwm_push_pin_out)
1173 wFrameWindowUpdatePushButton(wwin->frame, True);
1174 #endif /* OLWM_HINTS */
1177 wwin->frame->workspace = workspace;
1179 wwin->frame->on_click_left = windowIconifyClick;
1180 #ifdef XKB_BUTTON_HINT
1181 if (wPreferences.modelock)
1182 wwin->frame->on_click_language = windowLanguageClick;
1183 #endif
1185 wwin->frame->on_click_right = windowCloseClick;
1186 wwin->frame->on_dblclick_right = windowCloseDblClick;
1188 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1189 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1191 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1194 XSelectInput(dpy, wwin->client_win,
1195 wwin->event_mask & ~StructureNotifyMask);
1197 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1198 0, wwin->frame->top_width);
1200 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1204 int gx, gy;
1206 wClientGetGravityOffsets(wwin, &gx, &gy);
1208 /* if gravity is to the south, account for the border sizes */
1209 if (gy > 0)
1210 y -= wwin->frame->top_width + wwin->frame->bottom_width;
1214 * wWindowConfigure() will init the client window's size
1215 * (wwin->client.{width,height}) and all other geometry
1216 * related variables (frame_x,frame_y)
1218 wWindowConfigure(wwin, x, y, width, height);
1220 /* to make sure the window receives it's new position after reparenting */
1221 wWindowSynthConfigureNotify(wwin);
1224 *--------------------------------------------------
1226 * Setup descriptors and save window to internal
1227 * lists
1229 *--------------------------------------------------
1232 if (wwin->main_window!=None) {
1233 WApplication *app;
1234 WWindow *leader;
1236 /* Leader windows do not necessary set themselves as leaders.
1237 * If this is the case, point the leader of this window to
1238 * itself */
1239 leader = wWindowFor(wwin->main_window);
1240 if (leader && leader->main_window==None) {
1241 leader->main_window = leader->client_win;
1243 app = wApplicationCreate(scr, wwin->main_window);
1244 if (app) {
1245 app->last_workspace = workspace;
1247 app->main_window_desc->fake_group = wwin->fake_group;
1250 * Do application specific stuff, like setting application
1251 * wide attributes.
1254 if (wwin->flags.hidden) {
1255 /* if the window was set to hidden because it was hidden
1256 * in a previous incarnation and that state was restored */
1257 app->flags.hidden = 1;
1258 } else if (app->flags.hidden) {
1259 if (WFLAGP(app->main_window_desc, start_hidden)) {
1260 wwin->flags.hidden = 1;
1261 } else {
1262 wUnhideApplication(app, False, False);
1263 raise = True;
1269 /* setup the frame descriptor */
1270 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1271 wwin->frame->core->descriptor.parent = wwin;
1272 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1274 /* don't let windows go away if we die */
1275 XAddToSaveSet(dpy, window);
1277 XLowerWindow(dpy, window);
1279 /* if window is in this workspace and should be mapped, then map it */
1280 if (!wwin->flags.miniaturized
1281 && (workspace == scr->current_workspace || IS_OMNIPRESENT(wwin))
1282 && !wwin->flags.hidden && !withdraw) {
1284 /* The following "if" is to avoid crashing of clients that expect
1285 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1286 * after the return from this function.
1288 if (wwin->wm_hints && (wwin->wm_hints->flags & StateHint)) {
1289 wClientSetState(wwin, wwin->wm_hints->initial_state, None);
1290 } else {
1291 wClientSetState(wwin, NormalState, None);
1294 #if 0
1295 /* if not auto focus, then map the window under the currently
1296 * focused window */
1297 #define _WIDTH(w) (w)->frame->core->width
1298 #define _HEIGHT(w) (w)->frame->core->height
1299 if (!wPreferences.auto_focus && scr->focused_window
1300 && !scr->flags.startup && !transientOwner
1301 && ((wWindowObscuresWindow(wwin, scr->focused_window)
1302 && (_WIDTH(wwin) > (_WIDTH(scr->focused_window)*5)/3
1303 || _HEIGHT(wwin) > (_HEIGHT(scr->focused_window)*5)/3)
1304 && WINDOW_LEVEL(scr->focused_window) == WINDOW_LEVEL(wwin))
1305 || wwin->flags.maximized)) {
1306 MoveInStackListUnder(scr->focused_window->frame->core,
1307 wwin->frame->core);
1309 #undef _WIDTH
1310 #undef _HEIGHT
1312 #endif
1314 if (wPreferences.superfluous && !wPreferences.no_animations
1315 && !scr->flags.startup && wwin->transient_for==None
1317 * The brain damaged idiotic non-click to focus modes will
1318 * have trouble with this because:
1320 * 1. window is created and mapped by the client
1321 * 2. window is mapped by wmaker in small size
1322 * 3. window is animated to grow to normal size
1323 * 4. this function returns to normal event loop
1324 * 5. eventually, the EnterNotify event that would trigger
1325 * the window focusing (if the mouse is over that window)
1326 * will be processed by wmaker.
1327 * But since this event will be rather delayed
1328 * (step 3 has a large delay) the time when the event ocurred
1329 * and when it is processed, the client that owns that window
1330 * will reject the XSetInputFocus() for it.
1332 && (wPreferences.focus_mode==WKF_CLICK
1333 || wPreferences.auto_focus)) {
1334 DoWindowBirth(wwin);
1337 wWindowMap(wwin);
1340 /* setup stacking descriptor */
1341 if (transientOwner) {
1342 /* && wPreferences.on_top_transients */
1343 if (transientOwner) {
1344 wwin->frame->core->stacking->child_of =
1345 transientOwner->frame->core;
1347 } else {
1348 wwin->frame->core->stacking->child_of = NULL;
1352 if (!scr->focused_window) {
1353 /* first window on the list */
1354 wwin->next = NULL;
1355 wwin->prev = NULL;
1356 scr->focused_window = wwin;
1357 } else {
1358 WWindow *tmp;
1360 /* add window at beginning of focus window list */
1361 tmp = scr->focused_window;
1362 while (tmp->prev)
1363 tmp = tmp->prev;
1364 tmp->prev = wwin;
1365 wwin->next = tmp;
1366 wwin->prev = NULL;
1369 /* raise is set to true if we un-hid the app when this window was born.
1370 * we raise, else old windows of this app will be above this new one. */
1371 if (raise) {
1372 wRaiseFrame(wwin->frame->core);
1375 /* Update name must come after WApplication stuff is done */
1376 wWindowUpdateName(wwin, title);
1377 if (title)
1378 XFree(title);
1380 XUngrabServer(dpy);
1383 *--------------------------------------------------
1385 * Final preparations before window is ready to go
1387 *--------------------------------------------------
1390 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1393 if (!wwin->flags.miniaturized && workspace == scr->current_workspace
1394 && !wwin->flags.hidden) {
1395 if (((transientOwner && transientOwner->flags.focused)
1396 || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable))
1397 wSetFocusTo(scr, wwin);
1399 wWindowResetMouseGrabs(wwin);
1401 if (!WFLAGP(wwin, no_bind_keys)) {
1402 wWindowSetKeyGrabs(wwin);
1406 WMPostNotificationName(WMNManaged, wwin, NULL);
1409 wColormapInstallForWindow(scr, scr->cmap_window);
1412 #ifdef OLWM_HINTS
1413 if (wwin->client_flags.olwm_warp_to_pin && wwin->frame->titlebar != NULL
1414 && !WFLAGP(wwin, no_close_button) && !withdraw) {
1416 XWarpPointer(dpy, None, None, 0, 0, 0, 0,
1417 wwin->frame_x + width - wwin->frame->titlebar->height * 2,
1418 wwin->frame_y);
1420 #endif
1423 *------------------------------------------------------------
1424 * Setup Notification Observers
1425 *------------------------------------------------------------
1427 WMAddNotificationObserver(appearanceObserver, wwin,
1428 WNWindowAppearanceSettingsChanged, wwin);
1432 *--------------------------------------------------
1434 * Cleanup temporary stuff
1436 *--------------------------------------------------
1439 if (win_state)
1440 wWindowDeleteSavedState(win_state);
1442 /* If the window must be withdrawed, then do it now.
1443 * Must do some optimization, 'though */
1444 if (withdraw) {
1445 wwin->flags.mapped = 0;
1446 wClientSetState(wwin, WithdrawnState, None);
1447 wUnmanageWindow(wwin, True, False);
1448 wwin = NULL;
1451 return wwin;
1458 WWindow*
1459 wManageInternalWindow(WScreen *scr, Window window, Window owner,
1460 char *title, int x, int y, int width, int height)
1462 WWindow *wwin;
1463 int foo;
1465 wwin = wWindowCreate();
1467 WMAddNotificationObserver(appearanceObserver, wwin,
1468 WNWindowAppearanceSettingsChanged, wwin);
1470 wwin->flags.internal_window = 1;
1472 WSETUFLAG(wwin, omnipresent, 1);
1473 WSETUFLAG(wwin, no_shadeable, 1);
1474 WSETUFLAG(wwin, no_resizable, 1);
1475 WSETUFLAG(wwin, no_miniaturizable, 1);
1477 wwin->focus_mode = WFM_PASSIVE;
1479 wwin->client_win = window;
1480 wwin->screen_ptr = scr;
1482 wwin->transient_for = owner;
1484 wwin->client.x = x;
1485 wwin->client.y = y;
1486 wwin->client.width = width;
1487 wwin->client.height = height;
1489 wwin->frame_x = wwin->client.x;
1490 wwin->frame_y = wwin->client.y;
1493 foo = WFF_RIGHT_BUTTON|WFF_BORDER;
1494 foo |= WFF_TITLEBAR;
1495 #ifdef XKB_BUTTON_HINT
1496 foo |= WFF_LANGUAGE_BUTTON;
1497 #endif
1499 wwin->frame = wFrameWindowCreate(scr, WMFloatingLevel,
1500 wwin->frame_x, wwin->frame_y,
1501 width, height,
1502 &wPreferences.window_title_clearance, foo,
1503 scr->window_title_texture,
1504 scr->resizebar_texture,
1505 scr->window_title_pixel,
1506 &scr->window_title_gc,
1507 &scr->title_font);
1509 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
1511 wwin->frame->flags.is_client_window_frame = 1;
1512 wwin->frame->flags.justification = wPreferences.title_justification;
1514 wFrameWindowChangeTitle(wwin->frame, title);
1516 /* setup button images */
1517 wWindowUpdateButtonImages(wwin);
1519 /* hide buttons */
1520 wFrameWindowHideButton(wwin->frame, WFF_RIGHT_BUTTON);
1522 wwin->frame->child = wwin;
1524 wwin->frame->workspace = wwin->screen_ptr->current_workspace;
1526 #ifdef XKB_BUTTON_HINT
1527 if (wPreferences.modelock)
1528 wwin->frame->on_click_language = windowLanguageClick;
1529 #endif
1531 wwin->frame->on_click_right = windowCloseClick;
1533 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1534 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1536 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1538 wwin->client.y += wwin->frame->top_width;
1539 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1540 0, wwin->frame->top_width);
1542 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y,
1543 wwin->client.width, wwin->client.height);
1545 /* setup the frame descriptor */
1546 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1547 wwin->frame->core->descriptor.parent = wwin;
1548 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1551 XLowerWindow(dpy, window);
1552 XMapSubwindows(dpy, wwin->frame->core->window);
1554 /* setup stacking descriptor */
1555 if (
1556 #ifdef removed
1557 wPreferences.on_top_transients &&
1558 #endif
1559 wwin->transient_for!=None
1560 && wwin->transient_for!=scr->root_win) {
1561 WWindow *tmp;
1562 tmp = wWindowFor(wwin->transient_for);
1563 if (tmp)
1564 wwin->frame->core->stacking->child_of = tmp->frame->core;
1565 } else {
1566 wwin->frame->core->stacking->child_of = NULL;
1570 if (!scr->focused_window) {
1571 /* first window on the list */
1572 wwin->next = NULL;
1573 wwin->prev = NULL;
1574 scr->focused_window = wwin;
1575 } else {
1576 WWindow *tmp;
1578 /* add window at beginning of focus window list */
1579 tmp = scr->focused_window;
1580 while (tmp->prev)
1581 tmp = tmp->prev;
1582 tmp->prev = wwin;
1583 wwin->next = tmp;
1584 wwin->prev = NULL;
1587 if (wwin->flags.is_gnustep == 0)
1588 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1590 /* if (wPreferences.auto_focus)*/
1591 wSetFocusTo(scr, wwin);
1593 wWindowResetMouseGrabs(wwin);
1595 wWindowSetKeyGrabs(wwin);
1597 return wwin;
1602 *----------------------------------------------------------------------
1603 * wUnmanageWindow--
1604 * Removes the frame window from a window and destroys all data
1605 * related to it. The window will be reparented back to the root window
1606 * if restore is True.
1608 * Side effects:
1609 * Everything related to the window is destroyed and the window
1610 * is removed from the window lists. Focus is set to the previous on the
1611 * window list.
1612 *----------------------------------------------------------------------
1614 void
1615 wUnmanageWindow(WWindow *wwin, Bool restore, Bool destroyed)
1617 WCoreWindow *frame = wwin->frame->core;
1618 WWindow *owner = NULL;
1619 WWindow *newFocusedWindow = NULL;
1620 int wasFocused;
1621 WScreen *scr = wwin->screen_ptr;
1624 /* First close attribute editor window if open */
1625 if (wwin->flags.inspector_open) {
1626 wCloseInspectorForWindow(wwin);
1629 /* Close window menu if it's open for this window */
1630 if (wwin->flags.menu_open_for_me) {
1631 CloseWindowMenu(scr);
1634 if (!destroyed) {
1635 if (!wwin->flags.internal_window)
1636 XRemoveFromSaveSet(dpy, wwin->client_win);
1638 XSelectInput(dpy, wwin->client_win, NoEventMask);
1640 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
1641 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->client_win);
1644 XUnmapWindow(dpy, frame->window);
1646 XUnmapWindow(dpy, wwin->client_win);
1648 /* deselect window */
1649 wSelectWindow(wwin, False);
1651 /* remove all pending events on window */
1652 /* I think this only matters for autoraise */
1653 if (wPreferences.raise_delay)
1654 WMDeleteTimerWithClientData(wwin->frame->core);
1656 XFlush(dpy);
1658 /* reparent the window back to the root */
1659 if (restore)
1660 wClientRestore(wwin);
1662 if (wwin->transient_for!=scr->root_win) {
1663 owner = wWindowFor(wwin->transient_for);
1664 if (owner) {
1665 if (!owner->flags.semi_focused) {
1666 owner = NULL;
1667 } else {
1668 owner->flags.semi_focused = 0;
1673 wasFocused = wwin->flags.focused;
1675 /* remove from window focus list */
1676 if (!wwin->prev && !wwin->next) {
1677 /* was the only window */
1678 scr->focused_window = NULL;
1679 newFocusedWindow = NULL;
1680 } else {
1681 WWindow *tmp;
1683 if (wwin->prev)
1684 wwin->prev->next = wwin->next;
1685 if (wwin->next)
1686 wwin->next->prev = wwin->prev;
1687 else {
1688 scr->focused_window = wwin->prev;
1689 scr->focused_window->next = NULL;
1692 if (wPreferences.focus_mode==WKF_CLICK) {
1694 /* if in click to focus mode and the window
1695 * was a transient, focus the owner window
1697 tmp = NULL;
1698 if (wPreferences.focus_mode==WKF_CLICK) {
1699 tmp = wWindowFor(wwin->transient_for);
1700 if (tmp && (!tmp->flags.mapped || WFLAGP(tmp, no_focusable))) {
1701 tmp = NULL;
1704 /* otherwise, focus the next one in the focus list */
1705 if (!tmp) {
1706 tmp = scr->focused_window;
1707 while (tmp) { /* look for one in the window list first */
1708 if (!WFLAGP(tmp, no_focusable) && !WFLAGP(tmp, skip_window_list)
1709 && (tmp->flags.mapped || tmp->flags.shaded))
1710 break;
1711 tmp = tmp->prev;
1713 if (!tmp) { /* if unsuccessful, choose any focusable window */
1714 tmp = scr->focused_window;
1715 while (tmp) {
1716 if (!WFLAGP(tmp, no_focusable)
1717 && (tmp->flags.mapped || tmp->flags.shaded))
1718 break;
1719 tmp = tmp->prev;
1724 newFocusedWindow = tmp;
1726 } else if (wPreferences.focus_mode==WKF_SLOPPY) {
1727 unsigned int mask;
1728 int foo;
1729 Window bar, win;
1731 /* This is to let the root window get the keyboard input
1732 * if Sloppy focus mode and no other window get focus.
1733 * This way keybindings will not freeze.
1735 tmp = NULL;
1736 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
1737 &foo, &foo, &foo, &foo, &mask))
1738 tmp = wWindowFor(win);
1739 if (tmp == wwin)
1740 tmp = NULL;
1741 newFocusedWindow = tmp;
1742 } else {
1743 newFocusedWindow = NULL;
1747 if (!wwin->flags.internal_window) {
1748 WMPostNotificationName(WMNUnmanaged, wwin, NULL);
1751 #ifdef DEBUG
1752 printf("destroying window %x frame %x\n", (unsigned)wwin->client_win,
1753 (unsigned)frame->window);
1754 #endif
1756 if (wasFocused) {
1757 if (newFocusedWindow != owner && owner) {
1758 if (wwin->flags.is_gnustep == 0)
1759 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1761 wSetFocusTo(scr, newFocusedWindow);
1763 wWindowDestroy(wwin);
1764 XFlush(dpy);
1768 void
1769 wWindowMap(WWindow *wwin)
1771 XMapWindow(dpy, wwin->frame->core->window);
1772 if (!wwin->flags.shaded) {
1773 /* window will be remapped when getting MapNotify */
1774 XSelectInput(dpy, wwin->client_win,
1775 wwin->event_mask & ~StructureNotifyMask);
1776 XMapWindow(dpy, wwin->client_win);
1777 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1779 wwin->flags.mapped = 1;
1784 void
1785 wWindowUnmap(WWindow *wwin)
1787 wwin->flags.mapped = 0;
1789 /* prevent window withdrawal when getting UnmapNotify */
1790 XSelectInput(dpy, wwin->client_win,
1791 wwin->event_mask & ~StructureNotifyMask);
1792 XUnmapWindow(dpy, wwin->client_win);
1793 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1795 XUnmapWindow(dpy, wwin->frame->core->window);
1800 void
1801 wWindowFocus(WWindow *wwin, WWindow *owin)
1803 WWindow *nowner;
1804 WWindow *oowner;
1806 #ifdef KEEP_XKB_LOCK_STATUS
1807 if (wPreferences.modelock) {
1808 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1810 #endif /* KEEP_XKB_LOCK_STATUS */
1812 wwin->flags.semi_focused = 0;
1814 if (wwin->flags.is_gnustep == 0)
1815 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1817 wwin->flags.focused = 1;
1819 wWindowResetMouseGrabs(wwin);
1821 WMPostNotificationName(WMNChangedFocus, wwin, (void*)True);
1823 if (owin == wwin || !owin)
1824 return;
1826 nowner = wWindowFor(wwin->transient_for);
1828 /* new window is a transient for the old window */
1829 if (nowner == owin) {
1830 owin->flags.semi_focused = 1;
1831 wWindowUnfocus(nowner);
1832 return;
1835 oowner = wWindowFor(owin->transient_for);
1837 /* new window is owner of old window */
1838 if (wwin == oowner) {
1839 wWindowUnfocus(owin);
1840 return;
1843 if (!nowner) {
1844 wWindowUnfocus(owin);
1845 return;
1848 /* new window has same owner of old window */
1849 if (oowner == nowner) {
1850 /* prevent unfocusing of owner */
1851 oowner->flags.semi_focused = 0;
1852 wWindowUnfocus(owin);
1853 oowner->flags.semi_focused = 1;
1855 return;
1858 /* nowner != NULL && oowner != nowner */
1859 nowner->flags.semi_focused = 1;
1860 wWindowUnfocus(nowner);
1861 wWindowUnfocus(owin);
1865 void
1866 wWindowUnfocus(WWindow *wwin)
1868 CloseWindowMenu(wwin->screen_ptr);
1870 if (wwin->flags.is_gnustep == 0)
1871 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused
1872 ? WS_PFOCUSED : WS_UNFOCUSED);
1874 if (wwin->transient_for!=None
1875 && wwin->transient_for!=wwin->screen_ptr->root_win) {
1876 WWindow *owner;
1877 owner = wWindowFor(wwin->transient_for);
1878 if (owner && owner->flags.semi_focused) {
1879 owner->flags.semi_focused = 0;
1880 if (owner->flags.mapped || owner->flags.shaded) {
1881 wWindowUnfocus(owner);
1882 wFrameWindowPaint(owner->frame);
1886 wwin->flags.focused = 0;
1888 wWindowResetMouseGrabs(wwin);
1890 WMPostNotificationName(WMNChangedFocus, wwin, (void*)False);
1894 void
1895 wWindowUpdateName(WWindow *wwin, char *newTitle)
1897 char *title;
1899 if (!wwin->frame)
1900 return;
1902 wwin->flags.wm_name_changed = 1;
1904 if (!newTitle) {
1905 /* the hint was removed */
1906 title = DEF_WINDOW_TITLE;
1907 } else {
1908 title = newTitle;
1911 if (wFrameWindowChangeTitle(wwin->frame, title)) {
1912 WMPostNotificationName(WMNChangedName, wwin, NULL);
1919 *----------------------------------------------------------------------
1921 * wWindowConstrainSize--
1922 * Constrains size for the client window, taking the maximal size,
1923 * window resize increments and other size hints into account.
1925 * Returns:
1926 * The closest size to what was given that the client window can
1927 * have.
1929 *----------------------------------------------------------------------
1931 void
1932 wWindowConstrainSize(WWindow *wwin, int *nwidth, int *nheight)
1934 int width = *nwidth;
1935 int height = *nheight;
1936 int winc = 1;
1937 int hinc = 1;
1938 int minW = 1, minH = 1;
1939 int maxW = wwin->screen_ptr->scr_width*2;
1940 int maxH = wwin->screen_ptr->scr_height*2;
1941 int minAX = -1, minAY = -1;
1942 int maxAX = -1, maxAY = -1;
1943 int baseW = 0;
1944 int baseH = 0;
1946 if (wwin->normal_hints) {
1947 winc = wwin->normal_hints->width_inc;
1948 hinc = wwin->normal_hints->height_inc;
1949 minW = wwin->normal_hints->min_width;
1950 minH = wwin->normal_hints->min_height;
1951 maxW = wwin->normal_hints->max_width;
1952 maxH = wwin->normal_hints->max_height;
1953 if (wwin->normal_hints->flags & PAspect) {
1954 minAX = wwin->normal_hints->min_aspect.x;
1955 minAY = wwin->normal_hints->min_aspect.y;
1956 maxAX = wwin->normal_hints->max_aspect.x;
1957 maxAY = wwin->normal_hints->max_aspect.y;
1960 baseW = wwin->normal_hints->base_width;
1961 baseH = wwin->normal_hints->base_height;
1964 if (width < minW)
1965 width = minW;
1966 if (height < minH)
1967 height = minH;
1969 if (width > maxW)
1970 width = maxW;
1971 if (height > maxH)
1972 height = maxH;
1974 /* aspect ratio code borrowed from olwm */
1975 if (minAX > 0) {
1976 /* adjust max aspect ratio */
1977 if (!(maxAX == 1 && maxAY == 1) && width * maxAY > height * maxAX) {
1978 if (maxAX > maxAY) {
1979 height = (width * maxAY) / maxAX;
1980 if (height > maxH) {
1981 height = maxH;
1982 width = (height * maxAX) / maxAY;
1984 } else {
1985 width = (height * maxAX) / maxAY;
1986 if (width > maxW) {
1987 width = maxW;
1988 height = (width * maxAY) / maxAX;
1993 /* adjust min aspect ratio */
1994 if (!(minAX == 1 && minAY == 1) && width * minAY < height * minAX) {
1995 if (minAX > minAY) {
1996 height = (width * minAY) / minAX;
1997 if (height < minH) {
1998 height = minH;
1999 width = (height * minAX) / minAY;
2001 } else {
2002 width = (height * minAX) / minAY;
2003 if (width < minW) {
2004 width = minW;
2005 height = (width * minAY) / minAX;
2011 if (baseW != 0) {
2012 width = (((width - baseW) / winc) * winc) + baseW;
2013 } else {
2014 width = (((width - minW) / winc) * winc) + minW;
2017 if (baseH != 0) {
2018 height = (((height - baseH) / hinc) * hinc) + baseH;
2019 } else {
2020 height = (((height - minH) / hinc) * hinc) + minH;
2023 /* broken stupid apps may cause preposterous values for these.. */
2024 if (width > 0)
2025 *nwidth = width;
2026 if (height > 0)
2027 *nheight = height;
2031 void
2032 wWindowCropSize(WWindow *wwin, int maxW, int maxH,
2033 int *width, int *height)
2035 int baseW = 0, baseH = 0;
2036 int winc = 1, hinc = 1;
2038 if (wwin->normal_hints) {
2039 baseW = wwin->normal_hints->base_width;
2040 baseH = wwin->normal_hints->base_height;
2042 winc = wwin->normal_hints->width_inc;
2043 hinc = wwin->normal_hints->height_inc;
2046 if (*width > maxW)
2047 *width = maxW - (maxW - baseW) % winc;
2049 if (*height > maxH)
2050 *height = maxH - (maxH - baseH) % hinc;
2054 void
2055 wWindowChangeWorkspace(WWindow *wwin, int workspace)
2057 WScreen *scr = wwin->screen_ptr;
2058 WApplication *wapp;
2059 int unmap = 0;
2061 if (workspace >= scr->workspace_count || workspace < 0
2062 || workspace == wwin->frame->workspace)
2063 return;
2065 if (workspace != scr->current_workspace) {
2066 /* Sent to other workspace. Unmap window */
2067 if ((wwin->flags.mapped
2068 || wwin->flags.shaded
2069 || (wwin->flags.miniaturized && !wPreferences.sticky_icons))
2070 && !IS_OMNIPRESENT(wwin) && !wwin->flags.changing_workspace) {
2072 wapp = wApplicationOf(wwin->main_window);
2073 if (wapp) {
2074 wapp->last_workspace = workspace;
2076 if (wwin->flags.miniaturized) {
2077 if (wwin->icon) {
2078 XUnmapWindow(dpy, wwin->icon->core->window);
2079 wwin->icon->mapped = 0;
2081 } else {
2082 unmap = 1;
2083 wSetFocusTo(scr, NULL);
2086 } else {
2087 /* brought to current workspace. Map window */
2088 if (wwin->flags.miniaturized && !wPreferences.sticky_icons) {
2089 if (wwin->icon) {
2090 XMapWindow(dpy, wwin->icon->core->window);
2091 wwin->icon->mapped = 1;
2093 } else if (!wwin->flags.mapped &&
2094 !(wwin->flags.miniaturized || wwin->flags.hidden)) {
2095 wWindowMap(wwin);
2098 if (!IS_OMNIPRESENT(wwin)) {
2099 int oldWorkspace = wwin->frame->workspace;
2101 wwin->frame->workspace = workspace;
2103 WMPostNotificationName(WMNChangedWorkspace, wwin, (void*)oldWorkspace);
2106 if (unmap) {
2107 wWindowUnmap(wwin);
2112 void
2113 wWindowSynthConfigureNotify(WWindow *wwin)
2115 XEvent sevent;
2117 sevent.type = ConfigureNotify;
2118 sevent.xconfigure.display = dpy;
2119 sevent.xconfigure.event = wwin->client_win;
2120 sevent.xconfigure.window = wwin->client_win;
2122 sevent.xconfigure.x = wwin->client.x;
2123 sevent.xconfigure.y = wwin->client.y;
2124 sevent.xconfigure.width = wwin->client.width;
2125 sevent.xconfigure.height = wwin->client.height;
2127 sevent.xconfigure.border_width = wwin->old_border_width;
2128 if (WFLAGP(wwin, no_titlebar))
2129 sevent.xconfigure.above = None;
2130 else
2131 sevent.xconfigure.above = wwin->frame->titlebar->window;
2133 sevent.xconfigure.override_redirect = False;
2134 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
2135 #ifdef KWM_HINTS
2136 wKWMSendEventMessage(wwin, WKWMChangedClient);
2137 #endif
2138 XFlush(dpy);
2143 *----------------------------------------------------------------------
2144 * wWindowConfigure--
2145 * Configures the frame, decorations and client window to the
2146 * specified geometry. The geometry is not checked for validity,
2147 * wWindowConstrainSize() must be used for that.
2148 * The size parameters are for the client window, but the position is
2149 * for the frame.
2150 * The client window receives a ConfigureNotify event, according
2151 * to what ICCCM says.
2153 * Returns:
2154 * None
2156 * Side effects:
2157 * Window size and position are changed and client window receives
2158 * a ConfigureNotify event.
2159 *----------------------------------------------------------------------
2161 void
2162 wWindowConfigure(wwin, req_x, req_y, req_width, req_height)
2163 WWindow *wwin;
2164 int req_x, req_y; /* new position of the frame */
2165 int req_width, req_height; /* new size of the client */
2167 int synth_notify = False;
2168 int resize;
2170 resize = (req_width!=wwin->client.width
2171 || req_height!=wwin->client.height);
2173 * if the window is being moved but not resized then
2174 * send a synthetic ConfigureNotify
2176 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y) && !resize) {
2177 synth_notify = True;
2180 if (WFLAGP(wwin, dont_move_off))
2181 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2182 req_width, req_height);
2183 if (resize) {
2184 if (req_width < MIN_WINDOW_SIZE)
2185 req_width = MIN_WINDOW_SIZE;
2186 if (req_height < MIN_WINDOW_SIZE)
2187 req_height = MIN_WINDOW_SIZE;
2189 /* If growing, resize inner part before frame,
2190 * if shrinking, resize frame before.
2191 * This will prevent the frame (that can have a different color)
2192 * to be exposed, causing flicker */
2193 if (req_height > wwin->frame->core->height
2194 || req_width > wwin->frame->core->width)
2195 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2197 if (wwin->flags.shaded) {
2198 wFrameWindowConfigure(wwin->frame, req_x, req_y,
2199 req_width, wwin->frame->core->height);
2200 wwin->old_geometry.height = req_height;
2201 } else {
2202 int h;
2204 h = req_height + wwin->frame->top_width
2205 + wwin->frame->bottom_width;
2207 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, h);
2210 if (!(req_height > wwin->frame->core->height
2211 || req_width > wwin->frame->core->width))
2212 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2214 wwin->client.x = req_x;
2215 wwin->client.y = req_y + wwin->frame->top_width;
2216 wwin->client.width = req_width;
2217 wwin->client.height = req_height;
2218 } else {
2219 wwin->client.x = req_x;
2220 wwin->client.y = req_y + wwin->frame->top_width;
2222 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2224 wwin->frame_x = req_x;
2225 wwin->frame_y = req_y;
2226 if (!WFLAGP(wwin, no_border)) {
2227 wwin->client.x += FRAME_BORDER_WIDTH;
2228 wwin->client.y += FRAME_BORDER_WIDTH;
2231 #ifdef SHAPE
2232 if (wShapeSupported && wwin->flags.shaped && resize) {
2233 wWindowSetShape(wwin);
2235 #endif
2237 if (synth_notify)
2238 wWindowSynthConfigureNotify(wwin);
2239 XFlush(dpy);
2243 void
2244 wWindowMove(wwin, req_x, req_y)
2245 WWindow *wwin;
2246 int req_x, req_y; /* new position of the frame */
2248 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2249 int synth_notify = False;
2251 /* Send a synthetic ConfigureNotify event for every window movement. */
2252 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y)) {
2253 synth_notify = True;
2255 #else
2256 /* A single synthetic ConfigureNotify event is sent at the end of
2257 * a completed (opaque) movement in moveres.c */
2258 #endif
2260 if (WFLAGP(wwin, dont_move_off))
2261 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2262 wwin->frame->core->width, wwin->frame->core->height);
2264 wwin->client.x = req_x;
2265 wwin->client.y = req_y + wwin->frame->top_width;
2266 if (!WFLAGP(wwin, no_border)) {
2267 wwin->client.x += FRAME_BORDER_WIDTH;
2268 wwin->client.y += FRAME_BORDER_WIDTH;
2271 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2273 wwin->frame_x = req_x;
2274 wwin->frame_y = req_y;
2276 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2277 if (synth_notify)
2278 wWindowSynthConfigureNotify(wwin);
2279 #endif
2283 void
2284 wWindowUpdateButtonImages(WWindow *wwin)
2286 WScreen *scr = wwin->screen_ptr;
2287 Pixmap pixmap, mask;
2288 WFrameWindow *fwin = wwin->frame;
2290 if (WFLAGP(wwin, no_titlebar))
2291 return;
2293 /* miniaturize button */
2295 if (!WFLAGP(wwin, no_miniaturize_button)) {
2296 if (wwin->wm_gnustep_attr
2297 && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
2298 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
2300 if (wwin->wm_gnustep_attr->flags&GSMiniaturizeMaskAttr) {
2301 mask = wwin->wm_gnustep_attr->miniaturize_mask;
2302 } else {
2303 mask = None;
2306 if (fwin->lbutton_image
2307 && (fwin->lbutton_image->image != pixmap
2308 || fwin->lbutton_image->mask != mask)) {
2309 wPixmapDestroy(fwin->lbutton_image);
2310 fwin->lbutton_image = NULL;
2313 if (!fwin->lbutton_image) {
2314 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
2315 fwin->lbutton_image->client_owned = 1;
2316 fwin->lbutton_image->client_owned_mask = 1;
2318 } else {
2319 if (fwin->lbutton_image && !fwin->lbutton_image->shared) {
2320 wPixmapDestroy(fwin->lbutton_image);
2322 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
2326 #ifdef XKB_BUTTON_HINT
2327 if (!WFLAGP(wwin, no_language_button)) {
2328 if (fwin->languagebutton_image &&
2329 !fwin->languagebutton_image->shared) {
2330 wPixmapDestroy(fwin->languagebutton_image);
2332 fwin->languagebutton_image =
2333 scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
2335 #endif
2337 /* close button */
2339 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2340 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2342 if (!WFLAGP(wwin, no_close_button)) {
2343 if (wwin->wm_gnustep_attr
2344 && wwin->wm_gnustep_attr->flags & GSClosePixmapAttr) {
2345 pixmap = wwin->wm_gnustep_attr->close_pixmap;
2347 if (wwin->wm_gnustep_attr->flags&GSCloseMaskAttr)
2348 mask = wwin->wm_gnustep_attr->close_mask;
2349 else
2350 mask = None;
2352 if (fwin->rbutton_image && (fwin->rbutton_image->image != pixmap
2353 || fwin->rbutton_image->mask != mask)) {
2354 wPixmapDestroy(fwin->rbutton_image);
2355 fwin->rbutton_image = NULL;
2358 if (!fwin->rbutton_image) {
2359 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
2360 fwin->rbutton_image->client_owned = 1;
2361 fwin->rbutton_image->client_owned_mask = 1;
2364 } else if (WFLAGP(wwin, kill_close)) {
2366 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2367 wPixmapDestroy(fwin->rbutton_image);
2369 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
2371 } else if (MGFLAGP(wwin, broken_close)) {
2373 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2374 wPixmapDestroy(fwin->rbutton_image);
2376 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
2378 } else {
2380 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2381 wPixmapDestroy(fwin->rbutton_image);
2383 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
2387 /* force buttons to be redrawn */
2388 fwin->flags.need_texture_change = 1;
2389 wFrameWindowPaint(fwin);
2394 *---------------------------------------------------------------------------
2395 * wWindowConfigureBorders--
2396 * Update window border configuration according to attribute flags.
2398 *---------------------------------------------------------------------------
2400 void
2401 wWindowConfigureBorders(WWindow *wwin)
2403 if (wwin->frame) {
2404 int flags;
2405 int newy, oldh;
2407 flags = WFF_LEFT_BUTTON|WFF_RIGHT_BUTTON;
2408 #ifdef XKB_BUTTON_HINT
2409 flags |= WFF_LANGUAGE_BUTTON;
2410 #endif
2411 if (!WFLAGP(wwin, no_titlebar))
2412 flags |= WFF_TITLEBAR;
2413 if (!WFLAGP(wwin, no_resizebar))
2414 flags |= WFF_RESIZEBAR;
2415 if (!WFLAGP(wwin, no_border))
2416 flags |= WFF_BORDER;
2417 if (wwin->flags.shaded)
2418 flags |= WFF_IS_SHADED;
2420 oldh = wwin->frame->top_width;
2421 wFrameWindowUpdateBorders(wwin->frame, flags);
2422 if (oldh != wwin->frame->top_width) {
2423 newy = wwin->frame_y + oldh - wwin->frame->top_width;
2425 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2426 wWindowConfigure(wwin, wwin->frame_x, newy,
2427 wwin->client.width, wwin->client.height);
2430 flags = 0;
2431 if (!WFLAGP(wwin, no_miniaturize_button)
2432 && wwin->frame->flags.hide_left_button)
2433 flags |= WFF_LEFT_BUTTON;
2435 #ifdef XKB_BUTTON_HINT
2436 if (!WFLAGP(wwin, no_language_button)
2437 && wwin->frame->flags.hide_language_button)
2438 flags |= WFF_LANGUAGE_BUTTON;
2439 #endif
2441 if (!WFLAGP(wwin, no_close_button)
2442 && wwin->frame->flags.hide_right_button)
2443 flags |= WFF_RIGHT_BUTTON;
2445 if (flags!=0) {
2446 wWindowUpdateButtonImages(wwin);
2447 wFrameWindowShowButton(wwin->frame, flags);
2450 flags = 0;
2451 if (WFLAGP(wwin, no_miniaturize_button)
2452 && !wwin->frame->flags.hide_left_button)
2453 flags |= WFF_LEFT_BUTTON;
2455 #ifdef XKB_BUTTON_HINT
2456 if (WFLAGP(wwin, no_language_button)
2457 && !wwin->frame->flags.hide_language_button)
2458 flags |= WFF_LANGUAGE_BUTTON;
2459 #endif
2461 if (WFLAGP(wwin, no_close_button)
2462 && !wwin->frame->flags.hide_right_button)
2463 flags |= WFF_RIGHT_BUTTON;
2465 if (flags!=0)
2466 wFrameWindowHideButton(wwin->frame, flags);
2468 #ifdef SHAPE
2469 if (wShapeSupported && wwin->flags.shaped) {
2470 wWindowSetShape(wwin);
2472 #endif
2477 void
2478 wWindowSaveState(WWindow *wwin)
2480 CARD32 data[10];
2481 int i;
2483 memset(data, 0, sizeof(CARD32)*10);
2484 data[0] = wwin->frame->workspace;
2485 data[1] = wwin->flags.miniaturized;
2486 data[2] = wwin->flags.shaded;
2487 data[3] = wwin->flags.hidden;
2488 data[4] = wwin->flags.maximized;
2489 if (wwin->flags.maximized == 0) {
2490 data[5] = wwin->frame_x;
2491 data[6] = wwin->frame_y;
2492 data[7] = wwin->frame->core->width;
2493 data[8] = wwin->frame->core->height;
2494 } else {
2495 data[5] = wwin->old_geometry.x;
2496 data[6] = wwin->old_geometry.y;
2497 data[7] = wwin->old_geometry.width;
2498 data[8] = wwin->old_geometry.height;
2501 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
2502 if (wwin->screen_ptr->shortcutWindows[i] &&
2503 WMCountInArray(wwin->screen_ptr->shortcutWindows[i], wwin))
2504 data[9] |= 1<<i;
2506 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
2507 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
2508 (unsigned char *)data, 10);
2512 static int
2513 getSavedState(Window window, WSavedState **state)
2515 Atom type_ret;
2516 int fmt_ret;
2517 unsigned long nitems_ret;
2518 unsigned long bytes_after_ret;
2519 CARD32 *data;
2521 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
2522 True, _XA_WINDOWMAKER_STATE,
2523 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
2524 (unsigned char **)&data)!=Success || !data)
2525 return 0;
2527 *state = wmalloc(sizeof(WSavedState));
2529 (*state)->workspace = data[0];
2530 (*state)->miniaturized = data[1];
2531 (*state)->shaded = data[2];
2532 (*state)->hidden = data[3];
2533 (*state)->maximized = data[4];
2534 (*state)->x = data[5];
2535 (*state)->y = data[6];
2536 (*state)->w = data[7];
2537 (*state)->h = data[8];
2538 (*state)->window_shortcuts = data[9];
2540 XFree(data);
2542 if (*state && type_ret==_XA_WINDOWMAKER_STATE)
2543 return 1;
2544 else
2545 return 0;
2549 #ifdef SHAPE
2550 void
2551 wWindowClearShape(WWindow *wwin)
2553 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
2554 0, wwin->frame->top_width, None, ShapeSet);
2555 XFlush(dpy);
2558 void
2559 wWindowSetShape(WWindow *wwin)
2561 XRectangle rect[2];
2562 int count;
2563 #ifdef OPTIMIZE_SHAPE
2564 XRectangle *rects;
2565 XRectangle *urec;
2566 int ordering;
2568 /* only shape is the client's */
2569 if (WFLAGP(wwin, no_titlebar) && WFLAGP(wwin, no_resizebar)) {
2570 goto alt_code;
2573 /* Get array of rectangles describing the shape mask */
2574 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding,
2575 &count, &ordering);
2576 if (!rects) {
2577 goto alt_code;
2580 urec = malloc(sizeof(XRectangle)*(count+2));
2581 if (!urec) {
2582 XFree(rects);
2583 goto alt_code;
2586 /* insert our decoration rectangles in the rect list */
2587 memcpy(urec, rects, sizeof(XRectangle)*count);
2588 XFree(rects);
2590 if (!WFLAGP(wwin, no_titlebar)) {
2591 urec[count].x = -1;
2592 urec[count].y = -1 - wwin->frame->top_width;
2593 urec[count].width = wwin->frame->core->width + 2;
2594 urec[count].height = wwin->frame->top_width + 1;
2595 count++;
2597 if (!WFLAGP(wwin, no_resizebar)) {
2598 urec[count].x = -1;
2599 urec[count].y = wwin->frame->core->height
2600 - wwin->frame->bottom_width - wwin->frame->top_width;
2601 urec[count].width = wwin->frame->core->width + 2;
2602 urec[count].height = wwin->frame->bottom_width + 1;
2603 count++;
2606 /* shape our frame window */
2607 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2608 0, wwin->frame->top_width, urec, count,
2609 ShapeSet, Unsorted);
2610 XFlush(dpy);
2611 wfree(urec);
2612 return;
2614 alt_code:
2615 #endif /* OPTIMIZE_SHAPE */
2616 count = 0;
2617 if (!WFLAGP(wwin, no_titlebar)) {
2618 rect[count].x = -1;
2619 rect[count].y = -1;
2620 rect[count].width = wwin->frame->core->width + 2;
2621 rect[count].height = wwin->frame->top_width + 1;
2622 count++;
2624 if (!WFLAGP(wwin, no_resizebar)) {
2625 rect[count].x = -1;
2626 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
2627 rect[count].width = wwin->frame->core->width + 2;
2628 rect[count].height = wwin->frame->bottom_width + 1;
2629 count++;
2631 if (count > 0) {
2632 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2633 0, 0, rect, count, ShapeSet, Unsorted);
2635 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
2636 0, wwin->frame->top_width, wwin->client_win,
2637 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
2638 XFlush(dpy);
2640 #endif /* SHAPE */
2642 /* ====================================================================== */
2644 static FocusMode
2645 getFocusMode(WWindow *wwin)
2647 FocusMode mode;
2649 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
2650 if (wwin->wm_hints->input == True) {
2651 if (wwin->protocols.TAKE_FOCUS)
2652 mode = WFM_LOCALLY_ACTIVE;
2653 else
2654 mode = WFM_PASSIVE;
2655 } else {
2656 if (wwin->protocols.TAKE_FOCUS)
2657 mode = WFM_GLOBALLY_ACTIVE;
2658 else
2659 mode = WFM_NO_INPUT;
2661 } else {
2662 mode = WFM_PASSIVE;
2664 return mode;
2668 void
2669 wWindowSetKeyGrabs(WWindow *wwin)
2671 int i;
2672 WShortKey *key;
2674 for (i=0; i<WKBD_LAST; i++) {
2675 key = &wKeyBindings[i];
2677 if (key->keycode==0)
2678 continue;
2679 if (key->modifier!=AnyModifier) {
2680 XGrabKey(dpy, key->keycode, key->modifier|LockMask,
2681 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2682 #ifdef NUMLOCK_HACK
2683 /* Also grab all modifier combinations possible that include,
2684 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2685 * work even if the NumLock/ScrollLock key is on.
2687 wHackedGrabKey(key->keycode, key->modifier,
2688 wwin->frame->core->window, True, GrabModeAsync,
2689 GrabModeAsync);
2690 #endif
2692 XGrabKey(dpy, key->keycode, key->modifier,
2693 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2696 #ifndef LITE
2697 wRootMenuBindShortcuts(wwin->frame->core->window);
2698 #endif
2703 void
2704 wWindowResetMouseGrabs(WWindow *wwin)
2706 /* Mouse grabs can't be done on the client window because of
2707 * ICCCM and because clients that try to do the same will crash.
2709 * But there is a problem wich makes tbar buttons of unfocused
2710 * windows not usable as the click goes to the frame window instead
2711 * of the button itself. Must figure a way to fix that.
2714 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2716 if (!WFLAGP(wwin, no_bind_mouse)) {
2717 /* grabs for Meta+drag */
2718 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2719 True, ButtonPressMask, GrabModeSync,
2720 GrabModeAsync, None, None);
2723 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable)
2724 && !wwin->flags.is_gnustep) {
2725 /* the passive grabs to focus the window */
2726 /* if (wPreferences.focus_mode == WKF_CLICK) */
2727 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2728 True, ButtonPressMask, GrabModeSync, GrabModeAsync,
2729 None, None);
2731 XFlush(dpy);
2735 void
2736 wWindowUpdateGNUstepAttr(WWindow *wwin, GNUstepWMAttributes *attr)
2738 if (attr->flags & GSExtraFlagsAttr) {
2739 if (MGFLAGP(wwin, broken_close) !=
2740 (attr->extra_flags & GSDocumentEditedFlag)) {
2741 wwin->client_flags.broken_close = !MGFLAGP(wwin, broken_close);
2742 wWindowUpdateButtonImages(wwin);
2748 WMagicNumber
2749 wWindowAddSavedState(char *instance, char *class, char *command,
2750 pid_t pid, WSavedState *state)
2752 WWindowState *wstate;
2754 wstate = malloc(sizeof(WWindowState));
2755 if (!wstate)
2756 return 0;
2758 memset(wstate, 0, sizeof(WWindowState));
2759 wstate->pid = pid;
2760 if (instance)
2761 wstate->instance = wstrdup(instance);
2762 if (class)
2763 wstate->class = wstrdup(class);
2764 if (command)
2765 wstate->command = wstrdup(command);
2766 wstate->state = state;
2768 wstate->next = windowState;
2769 windowState = wstate;
2771 #ifdef DEBUG
2772 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2773 class, command);
2774 #endif
2776 return wstate;
2780 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2783 WMagicNumber
2784 wWindowGetSavedState(Window win)
2786 char *instance, *class, *command=NULL;
2787 WWindowState *wstate = windowState;
2788 char **argv;
2789 int argc;
2791 if (!wstate)
2792 return NULL;
2794 if (XGetCommand(dpy, win, &argv, &argc)) {
2795 if (argc > 0)
2796 command = wtokenjoin(argv, argc);
2797 XFreeStringList(argv);
2799 if (!command)
2800 return NULL;
2802 if (PropGetWMClass(win, &class, &instance)) {
2803 while (wstate) {
2804 if (SAME(instance, wstate->instance) &&
2805 SAME(class, wstate->class) &&
2806 SAME(command, wstate->command)) {
2807 break;
2809 wstate = wstate->next;
2811 } else {
2812 wstate = NULL;
2815 #ifdef DEBUG
2816 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2817 class, command);
2818 #endif
2820 if (command) wfree(command);
2821 if (instance) XFree(instance);
2822 if (class) XFree(class);
2824 return wstate;
2828 void
2829 wWindowDeleteSavedState(WMagicNumber id)
2831 WWindowState *tmp, *wstate=(WWindowState*)id;
2833 if (!wstate || !windowState)
2834 return;
2836 tmp = windowState;
2837 if (tmp==wstate) {
2838 windowState = wstate->next;
2839 #ifdef DEBUG
2840 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2841 wstate, wstate->instance, wstate->class, wstate->command);
2842 #endif
2843 if (wstate->instance) wfree(wstate->instance);
2844 if (wstate->class) wfree(wstate->class);
2845 if (wstate->command) wfree(wstate->command);
2846 wfree(wstate->state);
2847 wfree(wstate);
2848 } else {
2849 while (tmp->next) {
2850 if (tmp->next==wstate) {
2851 tmp->next=wstate->next;
2852 #ifdef DEBUG
2853 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2854 wstate, wstate->instance, wstate->class, wstate->command);
2855 #endif
2856 if (wstate->instance) wfree(wstate->instance);
2857 if (wstate->class) wfree(wstate->class);
2858 if (wstate->command) wfree(wstate->command);
2859 wfree(wstate->state);
2860 wfree(wstate);
2861 break;
2863 tmp = tmp->next;
2869 void
2870 wWindowDeleteSavedStatesForPID(pid_t pid)
2872 WWindowState *tmp, *wstate;
2874 if (!windowState)
2875 return;
2877 tmp = windowState;
2878 if (tmp->pid == pid) {
2879 wstate = windowState;
2880 windowState = tmp->next;
2881 #ifdef DEBUG
2882 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2883 wstate, wstate->instance, wstate->class, wstate->command);
2884 #endif
2885 if (wstate->instance) wfree(wstate->instance);
2886 if (wstate->class) wfree(wstate->class);
2887 if (wstate->command) wfree(wstate->command);
2888 wfree(wstate->state);
2889 wfree(wstate);
2890 } else {
2891 while (tmp->next) {
2892 if (tmp->next->pid==pid) {
2893 wstate = tmp->next;
2894 tmp->next = wstate->next;
2895 #ifdef DEBUG
2896 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2897 wstate, wstate->instance, wstate->class, wstate->command);
2898 #endif
2899 if (wstate->instance) wfree(wstate->instance);
2900 if (wstate->class) wfree(wstate->class);
2901 if (wstate->command) wfree(wstate->command);
2902 wfree(wstate->state);
2903 wfree(wstate);
2904 break;
2906 tmp = tmp->next;
2912 void
2913 wWindowSetOmnipresent(WWindow *wwin, Bool flag)
2915 wwin->flags.omnipresent = flag;
2917 WMPostNotificationName(WMNChangedState, wwin, "omnipresent");
2921 /* ====================================================================== */
2923 static void
2924 resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2926 WWindow *wwin = data;
2928 #ifndef NUMLOCK_HACK
2929 if ((event->xbutton.state & ValidModMask)
2930 != (event->xbutton.state & ~LockMask)) {
2931 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2932 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2934 #endif
2936 event->xbutton.state &= ValidModMask;
2938 CloseWindowMenu(wwin->screen_ptr);
2940 if (wPreferences.focus_mode==WKF_CLICK
2941 && !(event->xbutton.state&ControlMask)
2942 && !WFLAGP(wwin, no_focusable)) {
2943 wSetFocusTo(wwin->screen_ptr, wwin);
2946 if (event->xbutton.button == Button1)
2947 wRaiseFrame(wwin->frame->core);
2949 if (event->xbutton.window != wwin->frame->resizebar->window) {
2950 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
2951 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2952 GrabModeAsync, GrabModeAsync, None,
2953 None, CurrentTime)!=GrabSuccess) {
2954 #ifdef DEBUG0
2955 wwarning("pointer grab failed for window move");
2956 #endif
2957 return;
2961 if (event->xbutton.state & MOD_MASK) {
2962 /* move the window */
2963 wMouseMoveWindow(wwin, event);
2964 XUngrabPointer(dpy, CurrentTime);
2965 } else {
2966 wMouseResizeWindow(wwin, event);
2967 XUngrabPointer(dpy, CurrentTime);
2973 static void
2974 titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
2976 WWindow *wwin = data;
2978 event->xbutton.state &= ValidModMask;
2980 if (event->xbutton.button==Button1) {
2981 if (event->xbutton.state == 0) {
2982 if (!WFLAGP(wwin, no_shadeable)) {
2983 /* shade window */
2984 if (wwin->flags.shaded)
2985 wUnshadeWindow(wwin);
2986 else
2987 wShadeWindow(wwin);
2989 } else {
2990 int dir = 0;
2992 if (event->xbutton.state & ControlMask)
2993 dir |= MAX_VERTICAL;
2995 if (event->xbutton.state & ShiftMask) {
2996 dir |= MAX_HORIZONTAL;
2997 if (!(event->xbutton.state & ControlMask))
2998 wSelectWindow(wwin, !wwin->flags.selected);
3001 /* maximize window */
3002 if (dir!=0 && !WFLAGP(wwin, no_resizable)) {
3003 int ndir = dir ^ wwin->flags.maximized;
3004 if (wwin->flags.maximized != 0)
3005 wUnmaximizeWindow(wwin);
3006 if (ndir != 0)
3007 wMaximizeWindow(wwin, ndir);
3010 } else if (event->xbutton.button==Button3) {
3011 if (event->xbutton.state & MOD_MASK) {
3012 wHideOtherApplications(wwin);
3014 } else if (event->xbutton.button==Button2) {
3015 wSelectWindow(wwin, !wwin->flags.selected);
3016 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelUp) {
3017 wShadeWindow(wwin);
3018 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelDown) {
3019 wUnshadeWindow(wwin);
3024 static void
3025 frameMouseDown(WObjDescriptor *desc, XEvent *event)
3027 WWindow *wwin = desc->parent;
3029 event->xbutton.state &= ValidModMask;
3031 CloseWindowMenu(wwin->screen_ptr);
3033 if (/*wPreferences.focus_mode==WKF_CLICK
3034 &&*/ !(event->xbutton.state&ControlMask)
3035 && !WFLAGP(wwin, no_focusable)) {
3036 wSetFocusTo(wwin->screen_ptr, wwin);
3038 if (event->xbutton.button == Button1) {
3039 wRaiseFrame(wwin->frame->core);
3042 if (event->xbutton.state & MOD_MASK) {
3043 /* move the window */
3044 if (XGrabPointer(dpy, wwin->client_win, False,
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;
3053 if (event->xbutton.button == Button3 && !WFLAGP(wwin, no_resizable))
3054 wMouseResizeWindow(wwin, event);
3055 else
3056 wMouseMoveWindow(wwin, event);
3057 XUngrabPointer(dpy, CurrentTime);
3062 static void
3063 titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
3065 WWindow *wwin = (WWindow*)data;
3067 #ifndef NUMLOCK_HACK
3068 if ((event->xbutton.state & ValidModMask)
3069 != (event->xbutton.state & ~LockMask)) {
3070 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
3071 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3073 #endif
3074 event->xbutton.state &= ValidModMask;
3076 CloseWindowMenu(wwin->screen_ptr);
3078 if (wPreferences.focus_mode==WKF_CLICK
3079 && !(event->xbutton.state&ControlMask)
3080 && !WFLAGP(wwin, no_focusable)) {
3081 wSetFocusTo(wwin->screen_ptr, wwin);
3084 if (event->xbutton.button == Button1
3085 || event->xbutton.button == Button2) {
3087 if (event->xbutton.button == Button1) {
3088 if (event->xbutton.state & MOD_MASK) {
3089 wLowerFrame(wwin->frame->core);
3090 } else {
3091 wRaiseFrame(wwin->frame->core);
3094 if ((event->xbutton.state & ShiftMask)
3095 && !(event->xbutton.state & ControlMask)) {
3096 wSelectWindow(wwin, !wwin->flags.selected);
3097 return;
3099 if (event->xbutton.window != wwin->frame->titlebar->window
3100 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
3101 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
3102 GrabModeAsync, GrabModeAsync, None,
3103 None, CurrentTime)!=GrabSuccess) {
3104 #ifdef DEBUG0
3105 wwarning("pointer grab failed for window move");
3106 #endif
3107 return;
3110 /* move the window */
3111 wMouseMoveWindow(wwin, event);
3113 XUngrabPointer(dpy, CurrentTime);
3114 } else if (event->xbutton.button == Button3 && event->xbutton.state==0
3115 && !wwin->flags.internal_window
3116 && !WCHECK_STATE(WSTATE_MODAL)) {
3117 WObjDescriptor *desc;
3119 if (event->xbutton.window != wwin->frame->titlebar->window
3120 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
3121 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
3122 GrabModeAsync, GrabModeAsync, None,
3123 None, CurrentTime)!=GrabSuccess) {
3124 #ifdef DEBUG0
3125 wwarning("pointer grab failed for window move");
3126 #endif
3127 return;
3130 OpenWindowMenu(wwin, event->xbutton.x_root,
3131 wwin->frame_y+wwin->frame->top_width, False);
3133 /* allow drag select */
3134 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
3135 event->xany.send_event = True;
3136 (*desc->handle_mousedown)(desc, event);
3138 XUngrabPointer(dpy, CurrentTime);
3144 static void
3145 windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
3147 WWindow *wwin = data;
3149 event->xbutton.state &= ValidModMask;
3151 CloseWindowMenu(wwin->screen_ptr);
3153 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3154 return;
3156 /* if control-click, kill the client */
3157 if (event->xbutton.state & ControlMask) {
3158 wClientKill(wwin);
3159 } else {
3160 #ifdef OLWM_HINTS
3161 if (wwin->flags.olwm_push_pin_out) {
3163 wwin->flags.olwm_push_pin_out = 0;
3165 wOLWMChangePushpinState(wwin, True);
3167 wFrameWindowUpdatePushButton(wwin->frame, False);
3169 return;
3171 #endif
3172 if (wwin->protocols.DELETE_WINDOW && event->xbutton.state==0) {
3173 /* send delete message */
3174 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3180 static void
3181 windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
3183 WWindow *wwin = data;
3185 CloseWindowMenu(wwin->screen_ptr);
3187 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3188 return;
3190 /* send delete message */
3191 if (wwin->protocols.DELETE_WINDOW) {
3192 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3193 } else {
3194 wClientKill(wwin);
3199 #ifdef XKB_BUTTON_HINT
3200 static void
3201 windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event)
3203 WWindow *wwin = data;
3204 WFrameWindow *fwin = wwin->frame;
3205 WScreen *scr = fwin->screen_ptr;
3206 XkbStateRec staterec;
3207 int tl;
3209 if (event->xbutton.button != Button1 && event->xbutton.button != Button3)
3210 return;
3211 tl = wwin->frame->languagemode;
3212 wwin->frame->languagemode = wwin->frame->last_languagemode;
3213 wwin->frame->last_languagemode = tl;
3214 wSetFocusTo(scr, wwin);
3215 wwin->frame->languagebutton_image =
3216 wwin->frame->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 +
3217 wwin->frame->languagemode];
3218 wFrameWindowUpdateLanguageButton(wwin->frame);
3219 if (event->xbutton.button == Button3)
3220 return;
3221 wRaiseFrame(fwin->core);
3223 #endif
3226 static void
3227 windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
3229 WWindow *wwin = data;
3231 event->xbutton.state &= ValidModMask;
3233 CloseWindowMenu(wwin->screen_ptr);
3235 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3236 return;
3238 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state==0) {
3239 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
3240 LastTimestamp);
3241 } else {
3242 WApplication *wapp;
3243 if ((event->xbutton.state & ControlMask) ||
3244 (event->xbutton.button == Button3)) {
3246 wapp = wApplicationOf(wwin->main_window);
3247 if (wapp && !WFLAGP(wwin, no_appicon))
3248 wHideApplication(wapp);
3249 } else if (event->xbutton.state==0) {
3250 wIconifyWindow(wwin);