- removed the collapse appicons thing
[wmaker-crm.git] / src / window.c
blob72a8fc341212b189dd1b1220f63ef368585be748
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) {
242 if (wwin->fake_group->retainCount > 0)
243 wwin->fake_group->retainCount--;
244 if (wwin->fake_group->retainCount==0 && wwin->fake_group->window!=None) {
245 XDestroyWindow(dpy, wwin->fake_group->window);
246 wwin->fake_group->window = 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->window = createFakeWindowGroupLeader(scr, wwin->main_window,
815 instance, class);
817 fPtr->retainCount++;
818 wwin->fake_group = fPtr;
819 wwin->group_id = fPtr->window;
820 wwin->main_window = wwin->group_id;
821 wfree(buffer);
822 } else {
823 fPtr = (WFakeGroupLeader*)wmalloc(sizeof(WFakeGroupLeader));
825 fPtr->identifier = buffer;
826 fPtr->window = createFakeWindowGroupLeader(scr, wwin->main_window,
827 instance, class);
828 fPtr->retainCount = 1;
830 WMAddToArray(scr->fakeGroupLeaders, fPtr);
832 wwin->fake_group = fPtr;
833 wwin->group_id = fPtr->window;
834 wwin->main_window = wwin->group_id;
836 if (instance)
837 XFree(instance);
838 if (class)
839 XFree(class);
844 *------------------------------------------------------------
846 * Setup the initial state of the window
848 *------------------------------------------------------------
851 if (WFLAGP(wwin, start_miniaturized) && !WFLAGP(wwin, no_miniaturizable)) {
852 wwin->flags.miniaturized = 1;
855 if (WFLAGP(wwin, start_maximized) && !WFLAGP(wwin, no_resizable)) {
856 wwin->flags.maximized = MAX_VERTICAL|MAX_HORIZONTAL;
860 Bool bla;
862 bla = False;
863 #ifdef GNOME_STUFF
864 bla = wGNOMECheckInitialClientState(wwin);
865 #endif
866 #ifdef KWM_HINTS
867 if (!bla)
868 wKWMCheckClientInitialState(wwin);
869 #endif
872 /* apply previous state if it exists and we're in startup */
873 if (scr->flags.startup && wm_state >= 0) {
875 if (wm_state == IconicState) {
877 wwin->flags.miniaturized = 1;
879 } else if (wm_state == WithdrawnState) {
881 withdraw = True;
885 /* if there is a saved state (from file), restore it */
886 win_state = NULL;
887 if (wwin->main_window!=None/* && wwin->main_window!=window*/) {
888 win_state = (WWindowState*)wWindowGetSavedState(wwin->main_window);
889 } else {
890 win_state = (WWindowState*)wWindowGetSavedState(window);
892 if (win_state && !withdraw) {
894 if (win_state->state->hidden>0)
895 wwin->flags.hidden = win_state->state->hidden;
897 if (win_state->state->shaded>0 && !WFLAGP(wwin, no_shadeable))
898 wwin->flags.shaded = win_state->state->shaded;
900 if (win_state->state->miniaturized>0 &&
901 !WFLAGP(wwin, no_miniaturizable)) {
902 wwin->flags.miniaturized = win_state->state->miniaturized;
905 if (!IS_OMNIPRESENT(wwin)) {
906 int w = wDefaultGetStartWorkspace(scr, wwin->wm_instance,
907 wwin->wm_class);
908 if (w < 0 || w >= scr->workspace_count) {
909 workspace = win_state->state->workspace;
910 if (workspace >= scr->workspace_count)
911 workspace = scr->current_workspace;
912 } else {
913 workspace = w;
915 } else {
916 workspace = scr->current_workspace;
920 /* if we're restarting, restore saved state (from hints).
921 * This will overwrite previous */
923 WSavedState *wstate;
925 if (getSavedState(window, &wstate)) {
926 wwin->flags.shaded = wstate->shaded;
927 wwin->flags.hidden = wstate->hidden;
928 wwin->flags.miniaturized = wstate->miniaturized;
929 wwin->flags.maximized = wstate->maximized;
930 if (wwin->flags.maximized) {
931 wwin->old_geometry.x = wstate->x;
932 wwin->old_geometry.y = wstate->y;
933 wwin->old_geometry.width = wstate->w;
934 wwin->old_geometry.height = wstate->h;
937 workspace = wstate->workspace;
938 } else {
939 wstate = NULL;
942 /* restore window shortcut */
943 if (wstate != NULL || win_state != NULL) {
944 unsigned mask = 0;
946 if (win_state != NULL)
947 mask = win_state->state->window_shortcuts;
949 if (wstate != NULL && mask == 0)
950 mask = wstate->window_shortcuts;
952 if (mask > 0) {
953 int i;
955 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
956 if (mask & (1<<i)) {
957 if (!scr->shortcutWindows[i])
958 scr->shortcutWindows[i] = WMCreateArray(4);
960 WMAddToArray(scr->shortcutWindows[i], wwin);
965 if (wstate != NULL) {
966 wfree(wstate);
970 /* don't let transients start miniaturized if their owners are not */
971 if (transientOwner && !transientOwner->flags.miniaturized
972 && wwin->flags.miniaturized && !withdraw) {
973 wwin->flags.miniaturized = 0;
974 if (wwin->wm_hints)
975 wwin->wm_hints->initial_state = NormalState;
978 /* set workspace on which the window starts */
979 if (workspace >= 0) {
980 if (workspace > scr->workspace_count-1) {
981 workspace = workspace % scr->workspace_count;
983 } else {
984 int w;
986 w = wDefaultGetStartWorkspace(scr, wwin->wm_instance, wwin->wm_class);
988 if (w >= 0 && w < scr->workspace_count && !(IS_OMNIPRESENT(wwin))) {
990 workspace = w;
992 } else {
993 if (wPreferences.open_transients_with_parent && transientOwner) {
995 workspace = transientOwner->frame->workspace;
997 } else {
999 workspace = scr->current_workspace;
1004 /* setup window geometry */
1005 if (win_state && win_state->state->w > 0) {
1006 width = win_state->state->w;
1007 height = win_state->state->h;
1009 wWindowConstrainSize(wwin, &width, &height);
1011 /* do not ask for window placement if the window is
1012 * transient, during startup, if the initial workspace is another one
1013 * or if the window wants to start iconic.
1014 * If geometry was saved, restore it. */
1016 Bool dontBring = False;
1018 if (win_state && win_state->state->w > 0) {
1019 x = win_state->state->x;
1020 y = win_state->state->y;
1021 } else if ((wwin->transient_for==None
1022 || wPreferences.window_placement!=WPM_MANUAL)
1023 && !scr->flags.startup
1024 && workspace == scr->current_workspace
1025 && !wwin->flags.miniaturized
1026 && !wwin->flags.maximized
1027 && !(wwin->normal_hints->flags & (USPosition|PPosition))) {
1029 if (transientOwner && transientOwner->flags.mapped) {
1030 int offs = WMAX(20, 2*transientOwner->frame->top_width);
1032 x = transientOwner->frame_x +
1033 abs((transientOwner->frame->core->width - width)/2) + offs;
1034 y = transientOwner->frame_y +
1035 abs((transientOwner->frame->core->height - height)/3) + offs;
1037 if (x < 0)
1038 x = 0;
1039 else if (x + width > scr->scr_width)
1040 x = scr->scr_width - width;
1042 if (y < 0)
1043 y = 0;
1044 else if (y + height > scr->scr_height)
1045 y = scr->scr_height - height;
1046 } else {
1047 PlaceWindow(wwin, &x, &y, width, height);
1049 if (wPreferences.window_placement == WPM_MANUAL)
1050 dontBring = True;
1053 if (WFLAGP(wwin, dont_move_off) && dontBring)
1054 wScreenBringInside(scr, &x, &y, width, height);
1057 if (wwin->flags.urgent) {
1058 if (!IS_OMNIPRESENT(wwin))
1059 wwin->flags.omnipresent ^= 1;
1063 *--------------------------------------------------
1065 * Create frame, borders and do reparenting
1067 *--------------------------------------------------
1069 foo = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
1070 #ifdef XKB_BUTTON_HINT
1071 if (wPreferences.modelock)
1072 foo |= WFF_LANGUAGE_BUTTON;
1073 #endif
1074 if (!WFLAGP(wwin, no_titlebar))
1075 foo |= WFF_TITLEBAR;
1076 if (!WFLAGP(wwin, no_resizebar))
1077 foo |= WFF_RESIZEBAR;
1078 if (!WFLAGP(wwin, no_border))
1079 foo |= WFF_BORDER;
1081 wwin->frame = wFrameWindowCreate(scr, window_level,
1082 x, y, width, height,
1083 &wPreferences.window_title_clearance, foo,
1084 scr->window_title_texture,
1085 scr->resizebar_texture,
1086 scr->window_title_pixel,
1087 &scr->window_title_gc,
1088 &scr->title_font);
1090 wwin->frame->flags.is_client_window_frame = 1;
1091 wwin->frame->flags.justification = wPreferences.title_justification;
1093 /* setup button images */
1094 wWindowUpdateButtonImages(wwin);
1096 /* hide unused buttons */
1097 foo = 0;
1098 if (WFLAGP(wwin, no_close_button))
1099 foo |= WFF_RIGHT_BUTTON;
1100 if (WFLAGP(wwin, no_miniaturize_button))
1101 foo |= WFF_LEFT_BUTTON;
1102 #ifdef XKB_BUTTON_HINT
1103 if (WFLAGP(wwin, no_language_button) || WFLAGP(wwin, no_focusable))
1104 foo |= WFF_LANGUAGE_BUTTON;
1105 #endif
1106 if (foo!=0)
1107 wFrameWindowHideButton(wwin->frame, foo);
1109 wwin->frame->child = wwin;
1111 #ifdef OLWM_HINTS
1112 /* emulate olwm push pin. Make the button look as pushed-in for
1113 * the pinned-out state. When the button is clicked, it will
1114 * revert to the normal position, which means the pin is pinned-in.
1116 if (wwin->flags.olwm_push_pin_out)
1117 wFrameWindowUpdatePushButton(wwin->frame, True);
1118 #endif /* OLWM_HINTS */
1121 wwin->frame->workspace = workspace;
1123 wwin->frame->on_click_left = windowIconifyClick;
1124 #ifdef XKB_BUTTON_HINT
1125 if (wPreferences.modelock)
1126 wwin->frame->on_click_language = windowLanguageClick;
1127 #endif
1129 wwin->frame->on_click_right = windowCloseClick;
1130 wwin->frame->on_dblclick_right = windowCloseDblClick;
1132 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1133 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1135 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1138 XSelectInput(dpy, wwin->client_win,
1139 wwin->event_mask & ~StructureNotifyMask);
1141 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1142 0, wwin->frame->top_width);
1144 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1148 int gx, gy;
1150 wClientGetGravityOffsets(wwin, &gx, &gy);
1152 /* if gravity is to the south, account for the border sizes */
1153 if (gy > 0)
1154 y -= wwin->frame->top_width + wwin->frame->bottom_width;
1158 * wWindowConfigure() will init the client window's size
1159 * (wwin->client.{width,height}) and all other geometry
1160 * related variables (frame_x,frame_y)
1162 wWindowConfigure(wwin, x, y, width, height);
1164 /* to make sure the window receives it's new position after reparenting */
1165 wWindowSynthConfigureNotify(wwin);
1168 *--------------------------------------------------
1170 * Setup descriptors and save window to internal
1171 * lists
1173 *--------------------------------------------------
1176 if (wwin->main_window!=None) {
1177 WApplication *app;
1178 WWindow *leader;
1180 /* Leader windows do not necessary set themselves as leaders.
1181 * If this is the case, point the leader of this window to
1182 * itself */
1183 leader = wWindowFor(wwin->main_window);
1184 if (leader && leader->main_window==None) {
1185 leader->main_window = leader->client_win;
1187 app = wApplicationCreate(scr, wwin->main_window);
1188 if (app) {
1189 app->last_workspace = workspace;
1191 app->main_window_desc->fake_group = wwin->fake_group;
1194 * Do application specific stuff, like setting application
1195 * wide attributes.
1198 if (wwin->flags.hidden) {
1199 /* if the window was set to hidden because it was hidden
1200 * in a previous incarnation and that state was restored */
1201 app->flags.hidden = 1;
1202 } else if (app->flags.hidden) {
1203 if (WFLAGP(app->main_window_desc, start_hidden)) {
1204 wwin->flags.hidden = 1;
1205 } else {
1206 wUnhideApplication(app, False, False);
1207 raise = True;
1213 /* setup the frame descriptor */
1214 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1215 wwin->frame->core->descriptor.parent = wwin;
1216 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1218 /* don't let windows go away if we die */
1219 XAddToSaveSet(dpy, window);
1221 XLowerWindow(dpy, window);
1223 /* if window is in this workspace and should be mapped, then map it */
1224 if (!wwin->flags.miniaturized
1225 && (workspace == scr->current_workspace || IS_OMNIPRESENT(wwin))
1226 && !wwin->flags.hidden && !withdraw) {
1228 /* The following "if" is to avoid crashing of clients that expect
1229 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1230 * after the return from this function.
1232 if (wwin->wm_hints && (wwin->wm_hints->flags & StateHint)) {
1233 wClientSetState(wwin, wwin->wm_hints->initial_state, None);
1234 } else {
1235 wClientSetState(wwin, NormalState, None);
1238 #if 0
1239 /* if not auto focus, then map the window under the currently
1240 * focused window */
1241 #define _WIDTH(w) (w)->frame->core->width
1242 #define _HEIGHT(w) (w)->frame->core->height
1243 if (!wPreferences.auto_focus && scr->focused_window
1244 && !scr->flags.startup && !transientOwner
1245 && ((wWindowObscuresWindow(wwin, scr->focused_window)
1246 && (_WIDTH(wwin) > (_WIDTH(scr->focused_window)*5)/3
1247 || _HEIGHT(wwin) > (_HEIGHT(scr->focused_window)*5)/3)
1248 && WINDOW_LEVEL(scr->focused_window) == WINDOW_LEVEL(wwin))
1249 || wwin->flags.maximized)) {
1250 MoveInStackListUnder(scr->focused_window->frame->core,
1251 wwin->frame->core);
1253 #undef _WIDTH
1254 #undef _HEIGHT
1256 #endif
1258 if (wPreferences.superfluous && !wPreferences.no_animations
1259 && !scr->flags.startup && wwin->transient_for==None
1261 * The brain damaged idiotic non-click to focus modes will
1262 * have trouble with this because:
1264 * 1. window is created and mapped by the client
1265 * 2. window is mapped by wmaker in small size
1266 * 3. window is animated to grow to normal size
1267 * 4. this function returns to normal event loop
1268 * 5. eventually, the EnterNotify event that would trigger
1269 * the window focusing (if the mouse is over that window)
1270 * will be processed by wmaker.
1271 * But since this event will be rather delayed
1272 * (step 3 has a large delay) the time when the event ocurred
1273 * and when it is processed, the client that owns that window
1274 * will reject the XSetInputFocus() for it.
1276 && (wPreferences.focus_mode==WKF_CLICK
1277 || wPreferences.auto_focus)) {
1278 DoWindowBirth(wwin);
1281 wWindowMap(wwin);
1284 /* setup stacking descriptor */
1285 if (transientOwner) {
1286 /* && wPreferences.on_top_transients */
1287 if (transientOwner) {
1288 wwin->frame->core->stacking->child_of =
1289 transientOwner->frame->core;
1291 } else {
1292 wwin->frame->core->stacking->child_of = NULL;
1296 if (!scr->focused_window) {
1297 /* first window on the list */
1298 wwin->next = NULL;
1299 wwin->prev = NULL;
1300 scr->focused_window = wwin;
1301 } else {
1302 WWindow *tmp;
1304 /* add window at beginning of focus window list */
1305 tmp = scr->focused_window;
1306 while (tmp->prev)
1307 tmp = tmp->prev;
1308 tmp->prev = wwin;
1309 wwin->next = tmp;
1310 wwin->prev = NULL;
1313 /* raise is set to true if we un-hid the app when this window was born.
1314 * we raise, else old windows of this app will be above this new one. */
1315 if (raise) {
1316 wRaiseFrame(wwin->frame->core);
1319 /* Update name must come after WApplication stuff is done */
1320 wWindowUpdateName(wwin, title);
1321 if (title)
1322 XFree(title);
1324 XUngrabServer(dpy);
1327 *--------------------------------------------------
1329 * Final preparations before window is ready to go
1331 *--------------------------------------------------
1334 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1337 if (!wwin->flags.miniaturized && workspace == scr->current_workspace
1338 && !wwin->flags.hidden) {
1339 if (((transientOwner && transientOwner->flags.focused)
1340 || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable))
1341 wSetFocusTo(scr, wwin);
1343 wWindowResetMouseGrabs(wwin);
1345 if (!WFLAGP(wwin, no_bind_keys)) {
1346 wWindowSetKeyGrabs(wwin);
1350 WMPostNotificationName(WMNManaged, wwin, NULL);
1353 wColormapInstallForWindow(scr, scr->cmap_window);
1356 #ifdef OLWM_HINTS
1357 if (wwin->client_flags.olwm_warp_to_pin && wwin->frame->titlebar != NULL
1358 && !WFLAGP(wwin, no_close_button) && !withdraw) {
1360 XWarpPointer(dpy, None, None, 0, 0, 0, 0,
1361 wwin->frame_x + width - wwin->frame->titlebar->height * 2,
1362 wwin->frame_y);
1364 #endif
1367 *------------------------------------------------------------
1368 * Setup Notification Observers
1369 *------------------------------------------------------------
1371 WMAddNotificationObserver(appearanceObserver, wwin,
1372 WNWindowAppearanceSettingsChanged, wwin);
1376 *--------------------------------------------------
1378 * Cleanup temporary stuff
1380 *--------------------------------------------------
1383 if (win_state)
1384 wWindowDeleteSavedState(win_state);
1386 /* If the window must be withdrawed, then do it now.
1387 * Must do some optimization, 'though */
1388 if (withdraw) {
1389 wwin->flags.mapped = 0;
1390 wClientSetState(wwin, WithdrawnState, None);
1391 wUnmanageWindow(wwin, True, False);
1392 wwin = NULL;
1395 return wwin;
1402 WWindow*
1403 wManageInternalWindow(WScreen *scr, Window window, Window owner,
1404 char *title, int x, int y, int width, int height)
1406 WWindow *wwin;
1407 int foo;
1409 wwin = wWindowCreate();
1411 WMAddNotificationObserver(appearanceObserver, wwin,
1412 WNWindowAppearanceSettingsChanged, wwin);
1414 wwin->flags.internal_window = 1;
1416 WSETUFLAG(wwin, omnipresent, 1);
1417 WSETUFLAG(wwin, no_shadeable, 1);
1418 WSETUFLAG(wwin, no_resizable, 1);
1419 WSETUFLAG(wwin, no_miniaturizable, 1);
1421 wwin->focus_mode = WFM_PASSIVE;
1423 wwin->client_win = window;
1424 wwin->screen_ptr = scr;
1426 wwin->transient_for = owner;
1428 wwin->client.x = x;
1429 wwin->client.y = y;
1430 wwin->client.width = width;
1431 wwin->client.height = height;
1433 wwin->frame_x = wwin->client.x;
1434 wwin->frame_y = wwin->client.y;
1437 foo = WFF_RIGHT_BUTTON|WFF_BORDER;
1438 foo |= WFF_TITLEBAR;
1439 #ifdef XKB_BUTTON_HINT
1440 foo |= WFF_LANGUAGE_BUTTON;
1441 #endif
1443 wwin->frame = wFrameWindowCreate(scr, WMFloatingLevel,
1444 wwin->frame_x, wwin->frame_y,
1445 width, height,
1446 &wPreferences.window_title_clearance, foo,
1447 scr->window_title_texture,
1448 scr->resizebar_texture,
1449 scr->window_title_pixel,
1450 &scr->window_title_gc,
1451 &scr->title_font);
1453 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
1455 wwin->frame->flags.is_client_window_frame = 1;
1456 wwin->frame->flags.justification = wPreferences.title_justification;
1458 wFrameWindowChangeTitle(wwin->frame, title);
1460 /* setup button images */
1461 wWindowUpdateButtonImages(wwin);
1463 /* hide buttons */
1464 wFrameWindowHideButton(wwin->frame, WFF_RIGHT_BUTTON);
1466 wwin->frame->child = wwin;
1468 wwin->frame->workspace = wwin->screen_ptr->current_workspace;
1470 #ifdef XKB_BUTTON_HINT
1471 if (wPreferences.modelock)
1472 wwin->frame->on_click_language = windowLanguageClick;
1473 #endif
1475 wwin->frame->on_click_right = windowCloseClick;
1477 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1478 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1480 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1482 wwin->client.y += wwin->frame->top_width;
1483 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1484 0, wwin->frame->top_width);
1486 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y,
1487 wwin->client.width, wwin->client.height);
1489 /* setup the frame descriptor */
1490 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1491 wwin->frame->core->descriptor.parent = wwin;
1492 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1495 XLowerWindow(dpy, window);
1496 XMapSubwindows(dpy, wwin->frame->core->window);
1498 /* setup stacking descriptor */
1499 if (
1500 #ifdef removed
1501 wPreferences.on_top_transients &&
1502 #endif
1503 wwin->transient_for!=None
1504 && wwin->transient_for!=scr->root_win) {
1505 WWindow *tmp;
1506 tmp = wWindowFor(wwin->transient_for);
1507 if (tmp)
1508 wwin->frame->core->stacking->child_of = tmp->frame->core;
1509 } else {
1510 wwin->frame->core->stacking->child_of = NULL;
1514 if (!scr->focused_window) {
1515 /* first window on the list */
1516 wwin->next = NULL;
1517 wwin->prev = NULL;
1518 scr->focused_window = wwin;
1519 } else {
1520 WWindow *tmp;
1522 /* add window at beginning of focus window list */
1523 tmp = scr->focused_window;
1524 while (tmp->prev)
1525 tmp = tmp->prev;
1526 tmp->prev = wwin;
1527 wwin->next = tmp;
1528 wwin->prev = NULL;
1531 if (wwin->flags.is_gnustep == 0)
1532 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1534 /* if (wPreferences.auto_focus)*/
1535 wSetFocusTo(scr, wwin);
1537 wWindowResetMouseGrabs(wwin);
1539 wWindowSetKeyGrabs(wwin);
1541 return wwin;
1546 *----------------------------------------------------------------------
1547 * wUnmanageWindow--
1548 * Removes the frame window from a window and destroys all data
1549 * related to it. The window will be reparented back to the root window
1550 * if restore is True.
1552 * Side effects:
1553 * Everything related to the window is destroyed and the window
1554 * is removed from the window lists. Focus is set to the previous on the
1555 * window list.
1556 *----------------------------------------------------------------------
1558 void
1559 wUnmanageWindow(WWindow *wwin, Bool restore, Bool destroyed)
1561 WCoreWindow *frame = wwin->frame->core;
1562 WWindow *owner = NULL;
1563 WWindow *newFocusedWindow = NULL;
1564 int wasFocused;
1565 WScreen *scr = wwin->screen_ptr;
1568 /* First close attribute editor window if open */
1569 if (wwin->flags.inspector_open) {
1570 wCloseInspectorForWindow(wwin);
1573 /* Close window menu if it's open for this window */
1574 if (wwin->flags.menu_open_for_me) {
1575 CloseWindowMenu(scr);
1578 if (!destroyed) {
1579 if (!wwin->flags.internal_window)
1580 XRemoveFromSaveSet(dpy, wwin->client_win);
1582 XSelectInput(dpy, wwin->client_win, NoEventMask);
1584 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
1585 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->client_win);
1588 XUnmapWindow(dpy, frame->window);
1590 XUnmapWindow(dpy, wwin->client_win);
1592 /* deselect window */
1593 wSelectWindow(wwin, False);
1595 /* remove all pending events on window */
1596 /* I think this only matters for autoraise */
1597 if (wPreferences.raise_delay)
1598 WMDeleteTimerWithClientData(wwin->frame->core);
1600 XFlush(dpy);
1602 /* reparent the window back to the root */
1603 if (restore)
1604 wClientRestore(wwin);
1606 if (wwin->transient_for!=scr->root_win) {
1607 owner = wWindowFor(wwin->transient_for);
1608 if (owner) {
1609 if (!owner->flags.semi_focused) {
1610 owner = NULL;
1611 } else {
1612 owner->flags.semi_focused = 0;
1617 wasFocused = wwin->flags.focused;
1619 /* remove from window focus list */
1620 if (!wwin->prev && !wwin->next) {
1621 /* was the only window */
1622 scr->focused_window = NULL;
1623 newFocusedWindow = NULL;
1624 } else {
1625 WWindow *tmp;
1627 if (wwin->prev)
1628 wwin->prev->next = wwin->next;
1629 if (wwin->next)
1630 wwin->next->prev = wwin->prev;
1631 else {
1632 scr->focused_window = wwin->prev;
1633 scr->focused_window->next = NULL;
1636 if (wPreferences.focus_mode==WKF_CLICK) {
1638 /* if in click to focus mode and the window
1639 * was a transient, focus the owner window
1641 tmp = NULL;
1642 if (wPreferences.focus_mode==WKF_CLICK) {
1643 tmp = wWindowFor(wwin->transient_for);
1644 if (tmp && (!tmp->flags.mapped || WFLAGP(tmp, no_focusable))) {
1645 tmp = NULL;
1648 /* otherwise, focus the next one in the focus list */
1649 if (!tmp) {
1650 tmp = scr->focused_window;
1651 while (tmp) { /* look for one in the window list first */
1652 if (!WFLAGP(tmp, no_focusable) && !WFLAGP(tmp, skip_window_list)
1653 && (tmp->flags.mapped || tmp->flags.shaded))
1654 break;
1655 tmp = tmp->prev;
1657 if (!tmp) { /* if unsuccessful, choose any focusable window */
1658 tmp = scr->focused_window;
1659 while (tmp) {
1660 if (!WFLAGP(tmp, no_focusable)
1661 && (tmp->flags.mapped || tmp->flags.shaded))
1662 break;
1663 tmp = tmp->prev;
1668 newFocusedWindow = tmp;
1670 } else if (wPreferences.focus_mode==WKF_SLOPPY) {
1671 unsigned int mask;
1672 int foo;
1673 Window bar, win;
1675 /* This is to let the root window get the keyboard input
1676 * if Sloppy focus mode and no other window get focus.
1677 * This way keybindings will not freeze.
1679 tmp = NULL;
1680 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
1681 &foo, &foo, &foo, &foo, &mask))
1682 tmp = wWindowFor(win);
1683 if (tmp == wwin)
1684 tmp = NULL;
1685 newFocusedWindow = tmp;
1686 } else {
1687 newFocusedWindow = NULL;
1691 if (!wwin->flags.internal_window) {
1692 WMPostNotificationName(WMNUnmanaged, wwin, NULL);
1695 #ifdef DEBUG
1696 printf("destroying window %x frame %x\n", (unsigned)wwin->client_win,
1697 (unsigned)frame->window);
1698 #endif
1700 if (wasFocused) {
1701 if (newFocusedWindow != owner && owner) {
1702 if (wwin->flags.is_gnustep == 0)
1703 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1705 wSetFocusTo(scr, newFocusedWindow);
1707 wWindowDestroy(wwin);
1708 XFlush(dpy);
1712 void
1713 wWindowMap(WWindow *wwin)
1715 XMapWindow(dpy, wwin->frame->core->window);
1716 if (!wwin->flags.shaded) {
1717 /* window will be remapped when getting MapNotify */
1718 XSelectInput(dpy, wwin->client_win,
1719 wwin->event_mask & ~StructureNotifyMask);
1720 XMapWindow(dpy, wwin->client_win);
1721 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1723 wwin->flags.mapped = 1;
1728 void
1729 wWindowUnmap(WWindow *wwin)
1731 wwin->flags.mapped = 0;
1733 /* prevent window withdrawal when getting UnmapNotify */
1734 XSelectInput(dpy, wwin->client_win,
1735 wwin->event_mask & ~StructureNotifyMask);
1736 XUnmapWindow(dpy, wwin->client_win);
1737 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1739 XUnmapWindow(dpy, wwin->frame->core->window);
1744 void
1745 wWindowFocus(WWindow *wwin, WWindow *owin)
1747 WWindow *nowner;
1748 WWindow *oowner;
1750 #ifdef KEEP_XKB_LOCK_STATUS
1751 if (wPreferences.modelock) {
1752 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1754 #endif /* KEEP_XKB_LOCK_STATUS */
1756 wwin->flags.semi_focused = 0;
1758 if (wwin->flags.is_gnustep == 0)
1759 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1761 wwin->flags.focused = 1;
1763 wWindowResetMouseGrabs(wwin);
1765 WMPostNotificationName(WMNChangedFocus, wwin, (void*)True);
1767 if (owin == wwin || !owin)
1768 return;
1770 nowner = wWindowFor(wwin->transient_for);
1772 /* new window is a transient for the old window */
1773 if (nowner == owin) {
1774 owin->flags.semi_focused = 1;
1775 wWindowUnfocus(nowner);
1776 return;
1779 oowner = wWindowFor(owin->transient_for);
1781 /* new window is owner of old window */
1782 if (wwin == oowner) {
1783 wWindowUnfocus(owin);
1784 return;
1787 if (!nowner) {
1788 wWindowUnfocus(owin);
1789 return;
1792 /* new window has same owner of old window */
1793 if (oowner == nowner) {
1794 /* prevent unfocusing of owner */
1795 oowner->flags.semi_focused = 0;
1796 wWindowUnfocus(owin);
1797 oowner->flags.semi_focused = 1;
1799 return;
1802 /* nowner != NULL && oowner != nowner */
1803 nowner->flags.semi_focused = 1;
1804 wWindowUnfocus(nowner);
1805 wWindowUnfocus(owin);
1809 void
1810 wWindowUnfocus(WWindow *wwin)
1812 CloseWindowMenu(wwin->screen_ptr);
1814 if (wwin->flags.is_gnustep == 0)
1815 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused
1816 ? WS_PFOCUSED : WS_UNFOCUSED);
1818 if (wwin->transient_for!=None
1819 && wwin->transient_for!=wwin->screen_ptr->root_win) {
1820 WWindow *owner;
1821 owner = wWindowFor(wwin->transient_for);
1822 if (owner && owner->flags.semi_focused) {
1823 owner->flags.semi_focused = 0;
1824 if (owner->flags.mapped || owner->flags.shaded) {
1825 wWindowUnfocus(owner);
1826 wFrameWindowPaint(owner->frame);
1830 wwin->flags.focused = 0;
1832 wWindowResetMouseGrabs(wwin);
1834 WMPostNotificationName(WMNChangedFocus, wwin, (void*)False);
1838 void
1839 wWindowUpdateName(WWindow *wwin, char *newTitle)
1841 char *title;
1843 if (!wwin->frame)
1844 return;
1846 wwin->flags.wm_name_changed = 1;
1848 if (!newTitle) {
1849 /* the hint was removed */
1850 title = DEF_WINDOW_TITLE;
1851 } else {
1852 title = newTitle;
1855 if (wFrameWindowChangeTitle(wwin->frame, title)) {
1856 WMPostNotificationName(WMNChangedName, wwin, NULL);
1863 *----------------------------------------------------------------------
1865 * wWindowConstrainSize--
1866 * Constrains size for the client window, taking the maximal size,
1867 * window resize increments and other size hints into account.
1869 * Returns:
1870 * The closest size to what was given that the client window can
1871 * have.
1873 *----------------------------------------------------------------------
1875 void
1876 wWindowConstrainSize(WWindow *wwin, int *nwidth, int *nheight)
1878 int width = *nwidth;
1879 int height = *nheight;
1880 int winc = 1;
1881 int hinc = 1;
1882 int minW = 1, minH = 1;
1883 int maxW = wwin->screen_ptr->scr_width*2;
1884 int maxH = wwin->screen_ptr->scr_height*2;
1885 int minAX = -1, minAY = -1;
1886 int maxAX = -1, maxAY = -1;
1887 int baseW = 0;
1888 int baseH = 0;
1890 if (wwin->normal_hints) {
1891 winc = wwin->normal_hints->width_inc;
1892 hinc = wwin->normal_hints->height_inc;
1893 minW = wwin->normal_hints->min_width;
1894 minH = wwin->normal_hints->min_height;
1895 maxW = wwin->normal_hints->max_width;
1896 maxH = wwin->normal_hints->max_height;
1897 if (wwin->normal_hints->flags & PAspect) {
1898 minAX = wwin->normal_hints->min_aspect.x;
1899 minAY = wwin->normal_hints->min_aspect.y;
1900 maxAX = wwin->normal_hints->max_aspect.x;
1901 maxAY = wwin->normal_hints->max_aspect.y;
1904 baseW = wwin->normal_hints->base_width;
1905 baseH = wwin->normal_hints->base_height;
1908 if (width < minW)
1909 width = minW;
1910 if (height < minH)
1911 height = minH;
1913 if (width > maxW)
1914 width = maxW;
1915 if (height > maxH)
1916 height = maxH;
1918 /* aspect ratio code borrowed from olwm */
1919 if (minAX > 0) {
1920 /* adjust max aspect ratio */
1921 if (!(maxAX == 1 && maxAY == 1) && width * maxAY > height * maxAX) {
1922 if (maxAX > maxAY) {
1923 height = (width * maxAY) / maxAX;
1924 if (height > maxH) {
1925 height = maxH;
1926 width = (height * maxAX) / maxAY;
1928 } else {
1929 width = (height * maxAX) / maxAY;
1930 if (width > maxW) {
1931 width = maxW;
1932 height = (width * maxAY) / maxAX;
1937 /* adjust min aspect ratio */
1938 if (!(minAX == 1 && minAY == 1) && width * minAY < height * minAX) {
1939 if (minAX > minAY) {
1940 height = (width * minAY) / minAX;
1941 if (height < minH) {
1942 height = minH;
1943 width = (height * minAX) / minAY;
1945 } else {
1946 width = (height * minAX) / minAY;
1947 if (width < minW) {
1948 width = minW;
1949 height = (width * minAY) / minAX;
1955 if (baseW != 0) {
1956 width = (((width - baseW) / winc) * winc) + baseW;
1957 } else {
1958 width = (((width - minW) / winc) * winc) + minW;
1961 if (baseH != 0) {
1962 height = (((height - baseH) / hinc) * hinc) + baseH;
1963 } else {
1964 height = (((height - minH) / hinc) * hinc) + minH;
1967 /* broken stupid apps may cause preposterous values for these.. */
1968 if (width > 0)
1969 *nwidth = width;
1970 if (height > 0)
1971 *nheight = height;
1975 void
1976 wWindowCropSize(WWindow *wwin, int maxW, int maxH,
1977 int *width, int *height)
1979 int baseW = 0, baseH = 0;
1980 int winc = 1, hinc = 1;
1982 if (wwin->normal_hints) {
1983 baseW = wwin->normal_hints->base_width;
1984 baseH = wwin->normal_hints->base_height;
1986 winc = wwin->normal_hints->width_inc;
1987 hinc = wwin->normal_hints->height_inc;
1990 if (*width > maxW)
1991 *width = maxW - (maxW - baseW) % winc;
1993 if (*height > maxH)
1994 *height = maxH - (maxH - baseH) % hinc;
1998 void
1999 wWindowChangeWorkspace(WWindow *wwin, int workspace)
2001 WScreen *scr = wwin->screen_ptr;
2002 WApplication *wapp;
2003 int unmap = 0;
2005 if (workspace >= scr->workspace_count || workspace < 0
2006 || workspace == wwin->frame->workspace)
2007 return;
2009 if (workspace != scr->current_workspace) {
2010 /* Sent to other workspace. Unmap window */
2011 if ((wwin->flags.mapped
2012 || wwin->flags.shaded
2013 || (wwin->flags.miniaturized && !wPreferences.sticky_icons))
2014 && !IS_OMNIPRESENT(wwin) && !wwin->flags.changing_workspace) {
2016 wapp = wApplicationOf(wwin->main_window);
2017 if (wapp) {
2018 wapp->last_workspace = workspace;
2020 if (wwin->flags.miniaturized) {
2021 if (wwin->icon) {
2022 XUnmapWindow(dpy, wwin->icon->core->window);
2023 wwin->icon->mapped = 0;
2025 } else {
2026 unmap = 1;
2027 wSetFocusTo(scr, NULL);
2030 } else {
2031 /* brought to current workspace. Map window */
2032 if (wwin->flags.miniaturized && !wPreferences.sticky_icons) {
2033 if (wwin->icon) {
2034 XMapWindow(dpy, wwin->icon->core->window);
2035 wwin->icon->mapped = 1;
2037 } else if (!wwin->flags.mapped &&
2038 !(wwin->flags.miniaturized || wwin->flags.hidden)) {
2039 wWindowMap(wwin);
2042 if (!IS_OMNIPRESENT(wwin)) {
2043 int oldWorkspace = wwin->frame->workspace;
2045 wwin->frame->workspace = workspace;
2047 WMPostNotificationName(WMNChangedWorkspace, wwin, (void*)oldWorkspace);
2050 if (unmap) {
2051 wWindowUnmap(wwin);
2056 void
2057 wWindowSynthConfigureNotify(WWindow *wwin)
2059 XEvent sevent;
2061 sevent.type = ConfigureNotify;
2062 sevent.xconfigure.display = dpy;
2063 sevent.xconfigure.event = wwin->client_win;
2064 sevent.xconfigure.window = wwin->client_win;
2066 sevent.xconfigure.x = wwin->client.x;
2067 sevent.xconfigure.y = wwin->client.y;
2068 sevent.xconfigure.width = wwin->client.width;
2069 sevent.xconfigure.height = wwin->client.height;
2071 sevent.xconfigure.border_width = wwin->old_border_width;
2072 if (WFLAGP(wwin, no_titlebar))
2073 sevent.xconfigure.above = None;
2074 else
2075 sevent.xconfigure.above = wwin->frame->titlebar->window;
2077 sevent.xconfigure.override_redirect = False;
2078 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
2079 #ifdef KWM_HINTS
2080 wKWMSendEventMessage(wwin, WKWMChangedClient);
2081 #endif
2082 XFlush(dpy);
2087 *----------------------------------------------------------------------
2088 * wWindowConfigure--
2089 * Configures the frame, decorations and client window to the
2090 * specified geometry. The geometry is not checked for validity,
2091 * wWindowConstrainSize() must be used for that.
2092 * The size parameters are for the client window, but the position is
2093 * for the frame.
2094 * The client window receives a ConfigureNotify event, according
2095 * to what ICCCM says.
2097 * Returns:
2098 * None
2100 * Side effects:
2101 * Window size and position are changed and client window receives
2102 * a ConfigureNotify event.
2103 *----------------------------------------------------------------------
2105 void
2106 wWindowConfigure(wwin, req_x, req_y, req_width, req_height)
2107 WWindow *wwin;
2108 int req_x, req_y; /* new position of the frame */
2109 int req_width, req_height; /* new size of the client */
2111 int synth_notify = False;
2112 int resize;
2114 resize = (req_width!=wwin->client.width
2115 || req_height!=wwin->client.height);
2117 * if the window is being moved but not resized then
2118 * send a synthetic ConfigureNotify
2120 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y) && !resize) {
2121 synth_notify = True;
2124 if (WFLAGP(wwin, dont_move_off))
2125 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2126 req_width, req_height);
2127 if (resize) {
2128 if (req_width < MIN_WINDOW_SIZE)
2129 req_width = MIN_WINDOW_SIZE;
2130 if (req_height < MIN_WINDOW_SIZE)
2131 req_height = MIN_WINDOW_SIZE;
2133 /* If growing, resize inner part before frame,
2134 * if shrinking, resize frame before.
2135 * This will prevent the frame (that can have a different color)
2136 * to be exposed, causing flicker */
2137 if (req_height > wwin->frame->core->height
2138 || req_width > wwin->frame->core->width)
2139 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2141 if (wwin->flags.shaded) {
2142 wFrameWindowConfigure(wwin->frame, req_x, req_y,
2143 req_width, wwin->frame->core->height);
2144 wwin->old_geometry.height = req_height;
2145 } else {
2146 int h;
2148 h = req_height + wwin->frame->top_width
2149 + wwin->frame->bottom_width;
2151 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, h);
2154 if (!(req_height > wwin->frame->core->height
2155 || req_width > wwin->frame->core->width))
2156 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2158 wwin->client.x = req_x;
2159 wwin->client.y = req_y + wwin->frame->top_width;
2160 wwin->client.width = req_width;
2161 wwin->client.height = req_height;
2162 } else {
2163 wwin->client.x = req_x;
2164 wwin->client.y = req_y + wwin->frame->top_width;
2166 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2168 wwin->frame_x = req_x;
2169 wwin->frame_y = req_y;
2170 if (!WFLAGP(wwin, no_border)) {
2171 wwin->client.x += FRAME_BORDER_WIDTH;
2172 wwin->client.y += FRAME_BORDER_WIDTH;
2175 #ifdef SHAPE
2176 if (wShapeSupported && wwin->flags.shaped && resize) {
2177 wWindowSetShape(wwin);
2179 #endif
2181 if (synth_notify)
2182 wWindowSynthConfigureNotify(wwin);
2183 XFlush(dpy);
2187 void
2188 wWindowMove(wwin, req_x, req_y)
2189 WWindow *wwin;
2190 int req_x, req_y; /* new position of the frame */
2192 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2193 int synth_notify = False;
2195 /* Send a synthetic ConfigureNotify event for every window movement. */
2196 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y)) {
2197 synth_notify = True;
2199 #else
2200 /* A single synthetic ConfigureNotify event is sent at the end of
2201 * a completed (opaque) movement in moveres.c */
2202 #endif
2204 if (WFLAGP(wwin, dont_move_off))
2205 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2206 wwin->frame->core->width, wwin->frame->core->height);
2208 wwin->client.x = req_x;
2209 wwin->client.y = req_y + wwin->frame->top_width;
2210 if (!WFLAGP(wwin, no_border)) {
2211 wwin->client.x += FRAME_BORDER_WIDTH;
2212 wwin->client.y += FRAME_BORDER_WIDTH;
2215 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2217 wwin->frame_x = req_x;
2218 wwin->frame_y = req_y;
2220 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2221 if (synth_notify)
2222 wWindowSynthConfigureNotify(wwin);
2223 #endif
2227 void
2228 wWindowUpdateButtonImages(WWindow *wwin)
2230 WScreen *scr = wwin->screen_ptr;
2231 Pixmap pixmap, mask;
2232 WFrameWindow *fwin = wwin->frame;
2234 if (WFLAGP(wwin, no_titlebar))
2235 return;
2237 /* miniaturize button */
2239 if (!WFLAGP(wwin, no_miniaturize_button)) {
2240 if (wwin->wm_gnustep_attr
2241 && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
2242 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
2244 if (wwin->wm_gnustep_attr->flags&GSMiniaturizeMaskAttr) {
2245 mask = wwin->wm_gnustep_attr->miniaturize_mask;
2246 } else {
2247 mask = None;
2250 if (fwin->lbutton_image
2251 && (fwin->lbutton_image->image != pixmap
2252 || fwin->lbutton_image->mask != mask)) {
2253 wPixmapDestroy(fwin->lbutton_image);
2254 fwin->lbutton_image = NULL;
2257 if (!fwin->lbutton_image) {
2258 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
2259 fwin->lbutton_image->client_owned = 1;
2260 fwin->lbutton_image->client_owned_mask = 1;
2262 } else {
2263 if (fwin->lbutton_image && !fwin->lbutton_image->shared) {
2264 wPixmapDestroy(fwin->lbutton_image);
2266 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
2270 #ifdef XKB_BUTTON_HINT
2271 if (!WFLAGP(wwin, no_language_button)) {
2272 if (fwin->languagebutton_image &&
2273 !fwin->languagebutton_image->shared) {
2274 wPixmapDestroy(fwin->languagebutton_image);
2276 fwin->languagebutton_image =
2277 scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
2279 #endif
2281 /* close button */
2283 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2284 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2286 if (!WFLAGP(wwin, no_close_button)) {
2287 if (wwin->wm_gnustep_attr
2288 && wwin->wm_gnustep_attr->flags & GSClosePixmapAttr) {
2289 pixmap = wwin->wm_gnustep_attr->close_pixmap;
2291 if (wwin->wm_gnustep_attr->flags&GSCloseMaskAttr)
2292 mask = wwin->wm_gnustep_attr->close_mask;
2293 else
2294 mask = None;
2296 if (fwin->rbutton_image && (fwin->rbutton_image->image != pixmap
2297 || fwin->rbutton_image->mask != mask)) {
2298 wPixmapDestroy(fwin->rbutton_image);
2299 fwin->rbutton_image = NULL;
2302 if (!fwin->rbutton_image) {
2303 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
2304 fwin->rbutton_image->client_owned = 1;
2305 fwin->rbutton_image->client_owned_mask = 1;
2308 } else if (WFLAGP(wwin, kill_close)) {
2310 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2311 wPixmapDestroy(fwin->rbutton_image);
2313 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
2315 } else if (MGFLAGP(wwin, broken_close)) {
2317 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2318 wPixmapDestroy(fwin->rbutton_image);
2320 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
2322 } else {
2324 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2325 wPixmapDestroy(fwin->rbutton_image);
2327 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
2331 /* force buttons to be redrawn */
2332 fwin->flags.need_texture_change = 1;
2333 wFrameWindowPaint(fwin);
2338 *---------------------------------------------------------------------------
2339 * wWindowConfigureBorders--
2340 * Update window border configuration according to attribute flags.
2342 *---------------------------------------------------------------------------
2344 void
2345 wWindowConfigureBorders(WWindow *wwin)
2347 if (wwin->frame) {
2348 int flags;
2349 int newy, oldh;
2351 flags = WFF_LEFT_BUTTON|WFF_RIGHT_BUTTON;
2352 #ifdef XKB_BUTTON_HINT
2353 flags |= WFF_LANGUAGE_BUTTON;
2354 #endif
2355 if (!WFLAGP(wwin, no_titlebar))
2356 flags |= WFF_TITLEBAR;
2357 if (!WFLAGP(wwin, no_resizebar))
2358 flags |= WFF_RESIZEBAR;
2359 if (!WFLAGP(wwin, no_border))
2360 flags |= WFF_BORDER;
2361 if (wwin->flags.shaded)
2362 flags |= WFF_IS_SHADED;
2364 oldh = wwin->frame->top_width;
2365 wFrameWindowUpdateBorders(wwin->frame, flags);
2366 if (oldh != wwin->frame->top_width) {
2367 newy = wwin->frame_y + oldh - wwin->frame->top_width;
2369 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2370 wWindowConfigure(wwin, wwin->frame_x, newy,
2371 wwin->client.width, wwin->client.height);
2374 flags = 0;
2375 if (!WFLAGP(wwin, no_miniaturize_button)
2376 && wwin->frame->flags.hide_left_button)
2377 flags |= WFF_LEFT_BUTTON;
2379 #ifdef XKB_BUTTON_HINT
2380 if (!WFLAGP(wwin, no_language_button)
2381 && wwin->frame->flags.hide_language_button)
2382 flags |= WFF_LANGUAGE_BUTTON;
2383 #endif
2385 if (!WFLAGP(wwin, no_close_button)
2386 && wwin->frame->flags.hide_right_button)
2387 flags |= WFF_RIGHT_BUTTON;
2389 if (flags!=0) {
2390 wWindowUpdateButtonImages(wwin);
2391 wFrameWindowShowButton(wwin->frame, flags);
2394 flags = 0;
2395 if (WFLAGP(wwin, no_miniaturize_button)
2396 && !wwin->frame->flags.hide_left_button)
2397 flags |= WFF_LEFT_BUTTON;
2399 #ifdef XKB_BUTTON_HINT
2400 if (WFLAGP(wwin, no_language_button)
2401 && !wwin->frame->flags.hide_language_button)
2402 flags |= WFF_LANGUAGE_BUTTON;
2403 #endif
2405 if (WFLAGP(wwin, no_close_button)
2406 && !wwin->frame->flags.hide_right_button)
2407 flags |= WFF_RIGHT_BUTTON;
2409 if (flags!=0)
2410 wFrameWindowHideButton(wwin->frame, flags);
2412 #ifdef SHAPE
2413 if (wShapeSupported && wwin->flags.shaped) {
2414 wWindowSetShape(wwin);
2416 #endif
2421 void
2422 wWindowSaveState(WWindow *wwin)
2424 CARD32 data[10];
2425 int i;
2427 memset(data, 0, sizeof(CARD32)*10);
2428 data[0] = wwin->frame->workspace;
2429 data[1] = wwin->flags.miniaturized;
2430 data[2] = wwin->flags.shaded;
2431 data[3] = wwin->flags.hidden;
2432 data[4] = wwin->flags.maximized;
2433 if (wwin->flags.maximized == 0) {
2434 data[5] = wwin->frame_x;
2435 data[6] = wwin->frame_y;
2436 data[7] = wwin->frame->core->width;
2437 data[8] = wwin->frame->core->height;
2438 } else {
2439 data[5] = wwin->old_geometry.x;
2440 data[6] = wwin->old_geometry.y;
2441 data[7] = wwin->old_geometry.width;
2442 data[8] = wwin->old_geometry.height;
2445 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
2446 if (wwin->screen_ptr->shortcutWindows[i] &&
2447 WMCountInArray(wwin->screen_ptr->shortcutWindows[i], wwin))
2448 data[9] |= 1<<i;
2450 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
2451 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
2452 (unsigned char *)data, 10);
2456 static int
2457 getSavedState(Window window, WSavedState **state)
2459 Atom type_ret;
2460 int fmt_ret;
2461 unsigned long nitems_ret;
2462 unsigned long bytes_after_ret;
2463 CARD32 *data;
2465 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
2466 True, _XA_WINDOWMAKER_STATE,
2467 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
2468 (unsigned char **)&data)!=Success || !data)
2469 return 0;
2471 *state = wmalloc(sizeof(WSavedState));
2473 (*state)->workspace = data[0];
2474 (*state)->miniaturized = data[1];
2475 (*state)->shaded = data[2];
2476 (*state)->hidden = data[3];
2477 (*state)->maximized = data[4];
2478 (*state)->x = data[5];
2479 (*state)->y = data[6];
2480 (*state)->w = data[7];
2481 (*state)->h = data[8];
2482 (*state)->window_shortcuts = data[9];
2484 XFree(data);
2486 if (*state && type_ret==_XA_WINDOWMAKER_STATE)
2487 return 1;
2488 else
2489 return 0;
2493 #ifdef SHAPE
2494 void
2495 wWindowClearShape(WWindow *wwin)
2497 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
2498 0, wwin->frame->top_width, None, ShapeSet);
2499 XFlush(dpy);
2502 void
2503 wWindowSetShape(WWindow *wwin)
2505 XRectangle rect[2];
2506 int count;
2507 #ifdef OPTIMIZE_SHAPE
2508 XRectangle *rects;
2509 XRectangle *urec;
2510 int ordering;
2512 /* only shape is the client's */
2513 if (WFLAGP(wwin, no_titlebar) && WFLAGP(wwin, no_resizebar)) {
2514 goto alt_code;
2517 /* Get array of rectangles describing the shape mask */
2518 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding,
2519 &count, &ordering);
2520 if (!rects) {
2521 goto alt_code;
2524 urec = malloc(sizeof(XRectangle)*(count+2));
2525 if (!urec) {
2526 XFree(rects);
2527 goto alt_code;
2530 /* insert our decoration rectangles in the rect list */
2531 memcpy(urec, rects, sizeof(XRectangle)*count);
2532 XFree(rects);
2534 if (!WFLAGP(wwin, no_titlebar)) {
2535 urec[count].x = -1;
2536 urec[count].y = -1 - wwin->frame->top_width;
2537 urec[count].width = wwin->frame->core->width + 2;
2538 urec[count].height = wwin->frame->top_width + 1;
2539 count++;
2541 if (!WFLAGP(wwin, no_resizebar)) {
2542 urec[count].x = -1;
2543 urec[count].y = wwin->frame->core->height
2544 - wwin->frame->bottom_width - wwin->frame->top_width;
2545 urec[count].width = wwin->frame->core->width + 2;
2546 urec[count].height = wwin->frame->bottom_width + 1;
2547 count++;
2550 /* shape our frame window */
2551 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2552 0, wwin->frame->top_width, urec, count,
2553 ShapeSet, Unsorted);
2554 XFlush(dpy);
2555 wfree(urec);
2556 return;
2558 alt_code:
2559 #endif /* OPTIMIZE_SHAPE */
2560 count = 0;
2561 if (!WFLAGP(wwin, no_titlebar)) {
2562 rect[count].x = -1;
2563 rect[count].y = -1;
2564 rect[count].width = wwin->frame->core->width + 2;
2565 rect[count].height = wwin->frame->top_width + 1;
2566 count++;
2568 if (!WFLAGP(wwin, no_resizebar)) {
2569 rect[count].x = -1;
2570 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
2571 rect[count].width = wwin->frame->core->width + 2;
2572 rect[count].height = wwin->frame->bottom_width + 1;
2573 count++;
2575 if (count > 0) {
2576 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2577 0, 0, rect, count, ShapeSet, Unsorted);
2579 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
2580 0, wwin->frame->top_width, wwin->client_win,
2581 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
2582 XFlush(dpy);
2584 #endif /* SHAPE */
2586 /* ====================================================================== */
2588 static FocusMode
2589 getFocusMode(WWindow *wwin)
2591 FocusMode mode;
2593 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
2594 if (wwin->wm_hints->input == True) {
2595 if (wwin->protocols.TAKE_FOCUS)
2596 mode = WFM_LOCALLY_ACTIVE;
2597 else
2598 mode = WFM_PASSIVE;
2599 } else {
2600 if (wwin->protocols.TAKE_FOCUS)
2601 mode = WFM_GLOBALLY_ACTIVE;
2602 else
2603 mode = WFM_NO_INPUT;
2605 } else {
2606 mode = WFM_PASSIVE;
2608 return mode;
2612 void
2613 wWindowSetKeyGrabs(WWindow *wwin)
2615 int i;
2616 WShortKey *key;
2618 for (i=0; i<WKBD_LAST; i++) {
2619 key = &wKeyBindings[i];
2621 if (key->keycode==0)
2622 continue;
2623 if (key->modifier!=AnyModifier) {
2624 XGrabKey(dpy, key->keycode, key->modifier|LockMask,
2625 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2626 #ifdef NUMLOCK_HACK
2627 /* Also grab all modifier combinations possible that include,
2628 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2629 * work even if the NumLock/ScrollLock key is on.
2631 wHackedGrabKey(key->keycode, key->modifier,
2632 wwin->frame->core->window, True, GrabModeAsync,
2633 GrabModeAsync);
2634 #endif
2636 XGrabKey(dpy, key->keycode, key->modifier,
2637 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2640 #ifndef LITE
2641 wRootMenuBindShortcuts(wwin->frame->core->window);
2642 #endif
2647 void
2648 wWindowResetMouseGrabs(WWindow *wwin)
2650 /* Mouse grabs can't be done on the client window because of
2651 * ICCCM and because clients that try to do the same will crash.
2653 * But there is a problem wich makes tbar buttons of unfocused
2654 * windows not usable as the click goes to the frame window instead
2655 * of the button itself. Must figure a way to fix that.
2658 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2660 if (!WFLAGP(wwin, no_bind_mouse)) {
2661 /* grabs for Meta+drag */
2662 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2663 True, ButtonPressMask, GrabModeSync,
2664 GrabModeAsync, None, None);
2667 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable)
2668 && !wwin->flags.is_gnustep) {
2669 /* the passive grabs to focus the window */
2670 /* if (wPreferences.focus_mode == WKF_CLICK) */
2671 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2672 True, ButtonPressMask, GrabModeSync, GrabModeAsync,
2673 None, None);
2675 XFlush(dpy);
2679 void
2680 wWindowUpdateGNUstepAttr(WWindow *wwin, GNUstepWMAttributes *attr)
2682 if (attr->flags & GSExtraFlagsAttr) {
2683 if (MGFLAGP(wwin, broken_close) !=
2684 (attr->extra_flags & GSDocumentEditedFlag)) {
2685 wwin->client_flags.broken_close = !MGFLAGP(wwin, broken_close);
2686 wWindowUpdateButtonImages(wwin);
2692 WMagicNumber
2693 wWindowAddSavedState(char *instance, char *class, char *command,
2694 pid_t pid, WSavedState *state)
2696 WWindowState *wstate;
2698 wstate = malloc(sizeof(WWindowState));
2699 if (!wstate)
2700 return 0;
2702 memset(wstate, 0, sizeof(WWindowState));
2703 wstate->pid = pid;
2704 if (instance)
2705 wstate->instance = wstrdup(instance);
2706 if (class)
2707 wstate->class = wstrdup(class);
2708 if (command)
2709 wstate->command = wstrdup(command);
2710 wstate->state = state;
2712 wstate->next = windowState;
2713 windowState = wstate;
2715 #ifdef DEBUG
2716 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2717 class, command);
2718 #endif
2720 return wstate;
2724 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2727 WMagicNumber
2728 wWindowGetSavedState(Window win)
2730 char *instance, *class, *command=NULL;
2731 WWindowState *wstate = windowState;
2732 char **argv;
2733 int argc;
2735 if (!wstate)
2736 return NULL;
2738 if (XGetCommand(dpy, win, &argv, &argc)) {
2739 if (argc > 0)
2740 command = wtokenjoin(argv, argc);
2741 XFreeStringList(argv);
2743 if (!command)
2744 return NULL;
2746 if (PropGetWMClass(win, &class, &instance)) {
2747 while (wstate) {
2748 if (SAME(instance, wstate->instance) &&
2749 SAME(class, wstate->class) &&
2750 SAME(command, wstate->command)) {
2751 break;
2753 wstate = wstate->next;
2755 } else {
2756 wstate = NULL;
2759 #ifdef DEBUG
2760 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2761 class, command);
2762 #endif
2764 if (command) wfree(command);
2765 if (instance) XFree(instance);
2766 if (class) XFree(class);
2768 return wstate;
2772 void
2773 wWindowDeleteSavedState(WMagicNumber id)
2775 WWindowState *tmp, *wstate=(WWindowState*)id;
2777 if (!wstate || !windowState)
2778 return;
2780 tmp = windowState;
2781 if (tmp==wstate) {
2782 windowState = wstate->next;
2783 #ifdef DEBUG
2784 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2785 wstate, wstate->instance, wstate->class, wstate->command);
2786 #endif
2787 if (wstate->instance) wfree(wstate->instance);
2788 if (wstate->class) wfree(wstate->class);
2789 if (wstate->command) wfree(wstate->command);
2790 wfree(wstate->state);
2791 wfree(wstate);
2792 } else {
2793 while (tmp->next) {
2794 if (tmp->next==wstate) {
2795 tmp->next=wstate->next;
2796 #ifdef DEBUG
2797 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2798 wstate, wstate->instance, wstate->class, wstate->command);
2799 #endif
2800 if (wstate->instance) wfree(wstate->instance);
2801 if (wstate->class) wfree(wstate->class);
2802 if (wstate->command) wfree(wstate->command);
2803 wfree(wstate->state);
2804 wfree(wstate);
2805 break;
2807 tmp = tmp->next;
2813 void
2814 wWindowDeleteSavedStatesForPID(pid_t pid)
2816 WWindowState *tmp, *wstate;
2818 if (!windowState)
2819 return;
2821 tmp = windowState;
2822 if (tmp->pid == pid) {
2823 wstate = windowState;
2824 windowState = tmp->next;
2825 #ifdef DEBUG
2826 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2827 wstate, wstate->instance, wstate->class, wstate->command);
2828 #endif
2829 if (wstate->instance) wfree(wstate->instance);
2830 if (wstate->class) wfree(wstate->class);
2831 if (wstate->command) wfree(wstate->command);
2832 wfree(wstate->state);
2833 wfree(wstate);
2834 } else {
2835 while (tmp->next) {
2836 if (tmp->next->pid==pid) {
2837 wstate = tmp->next;
2838 tmp->next = 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 break;
2850 tmp = tmp->next;
2856 void
2857 wWindowSetOmnipresent(WWindow *wwin, Bool flag)
2859 wwin->flags.omnipresent = flag;
2861 WMPostNotificationName(WMNChangedState, wwin, "omnipresent");
2865 /* ====================================================================== */
2867 static void
2868 resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2870 WWindow *wwin = data;
2872 #ifndef NUMLOCK_HACK
2873 if ((event->xbutton.state & ValidModMask)
2874 != (event->xbutton.state & ~LockMask)) {
2875 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2876 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2878 #endif
2880 event->xbutton.state &= ValidModMask;
2882 CloseWindowMenu(wwin->screen_ptr);
2884 if (wPreferences.focus_mode==WKF_CLICK
2885 && !(event->xbutton.state&ControlMask)
2886 && !WFLAGP(wwin, no_focusable)) {
2887 wSetFocusTo(wwin->screen_ptr, wwin);
2890 if (event->xbutton.button == Button1)
2891 wRaiseFrame(wwin->frame->core);
2893 if (event->xbutton.window != wwin->frame->resizebar->window) {
2894 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
2895 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2896 GrabModeAsync, GrabModeAsync, None,
2897 None, CurrentTime)!=GrabSuccess) {
2898 #ifdef DEBUG0
2899 wwarning("pointer grab failed for window move");
2900 #endif
2901 return;
2905 if (event->xbutton.state & MOD_MASK) {
2906 /* move the window */
2907 wMouseMoveWindow(wwin, event);
2908 XUngrabPointer(dpy, CurrentTime);
2909 } else {
2910 wMouseResizeWindow(wwin, event);
2911 XUngrabPointer(dpy, CurrentTime);
2917 static void
2918 titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
2920 WWindow *wwin = data;
2922 event->xbutton.state &= ValidModMask;
2924 if (event->xbutton.button==Button1) {
2925 if (event->xbutton.state == 0) {
2926 if (!WFLAGP(wwin, no_shadeable)) {
2927 /* shade window */
2928 if (wwin->flags.shaded)
2929 wUnshadeWindow(wwin);
2930 else
2931 wShadeWindow(wwin);
2933 } else {
2934 int dir = 0;
2936 if (event->xbutton.state & ControlMask)
2937 dir |= MAX_VERTICAL;
2939 if (event->xbutton.state & ShiftMask) {
2940 dir |= MAX_HORIZONTAL;
2941 if (!(event->xbutton.state & ControlMask))
2942 wSelectWindow(wwin, !wwin->flags.selected);
2945 /* maximize window */
2946 if (dir!=0 && !WFLAGP(wwin, no_resizable)) {
2947 int ndir = dir ^ wwin->flags.maximized;
2948 if (wwin->flags.maximized != 0)
2949 wUnmaximizeWindow(wwin);
2950 if (ndir != 0)
2951 wMaximizeWindow(wwin, ndir);
2954 } else if (event->xbutton.button==Button3) {
2955 if (event->xbutton.state & MOD_MASK) {
2956 wHideOtherApplications(wwin);
2958 } else if (event->xbutton.button==Button2) {
2959 wSelectWindow(wwin, !wwin->flags.selected);
2960 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelUp) {
2961 wShadeWindow(wwin);
2962 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelDown) {
2963 wUnshadeWindow(wwin);
2968 static void
2969 frameMouseDown(WObjDescriptor *desc, XEvent *event)
2971 WWindow *wwin = desc->parent;
2973 event->xbutton.state &= ValidModMask;
2975 CloseWindowMenu(wwin->screen_ptr);
2977 if (/*wPreferences.focus_mode==WKF_CLICK
2978 &&*/ !(event->xbutton.state&ControlMask)
2979 && !WFLAGP(wwin, no_focusable)) {
2980 wSetFocusTo(wwin->screen_ptr, wwin);
2982 if (event->xbutton.button == Button1) {
2983 wRaiseFrame(wwin->frame->core);
2986 if (event->xbutton.state & MOD_MASK) {
2987 /* move the window */
2988 if (XGrabPointer(dpy, wwin->client_win, False,
2989 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2990 GrabModeAsync, GrabModeAsync, None,
2991 None, CurrentTime)!=GrabSuccess) {
2992 #ifdef DEBUG0
2993 wwarning("pointer grab failed for window move");
2994 #endif
2995 return;
2997 if (event->xbutton.button == Button3 && !WFLAGP(wwin, no_resizable))
2998 wMouseResizeWindow(wwin, event);
2999 else
3000 wMouseMoveWindow(wwin, event);
3001 XUngrabPointer(dpy, CurrentTime);
3006 static void
3007 titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
3009 WWindow *wwin = (WWindow*)data;
3011 #ifndef NUMLOCK_HACK
3012 if ((event->xbutton.state & ValidModMask)
3013 != (event->xbutton.state & ~LockMask)) {
3014 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
3015 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3017 #endif
3018 event->xbutton.state &= ValidModMask;
3020 CloseWindowMenu(wwin->screen_ptr);
3022 if (wPreferences.focus_mode==WKF_CLICK
3023 && !(event->xbutton.state&ControlMask)
3024 && !WFLAGP(wwin, no_focusable)) {
3025 wSetFocusTo(wwin->screen_ptr, wwin);
3028 if (event->xbutton.button == Button1
3029 || event->xbutton.button == Button2) {
3031 if (event->xbutton.button == Button1) {
3032 if (event->xbutton.state & MOD_MASK) {
3033 wLowerFrame(wwin->frame->core);
3034 } else {
3035 wRaiseFrame(wwin->frame->core);
3038 if ((event->xbutton.state & ShiftMask)
3039 && !(event->xbutton.state & ControlMask)) {
3040 wSelectWindow(wwin, !wwin->flags.selected);
3041 return;
3043 if (event->xbutton.window != wwin->frame->titlebar->window
3044 && XGrabPointer(dpy, wwin->frame->titlebar->window, 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;
3054 /* move the window */
3055 wMouseMoveWindow(wwin, event);
3057 XUngrabPointer(dpy, CurrentTime);
3058 } else if (event->xbutton.button == Button3 && event->xbutton.state==0
3059 && !wwin->flags.internal_window
3060 && !WCHECK_STATE(WSTATE_MODAL)) {
3061 WObjDescriptor *desc;
3063 if (event->xbutton.window != wwin->frame->titlebar->window
3064 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
3065 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
3066 GrabModeAsync, GrabModeAsync, None,
3067 None, CurrentTime)!=GrabSuccess) {
3068 #ifdef DEBUG0
3069 wwarning("pointer grab failed for window move");
3070 #endif
3071 return;
3074 OpenWindowMenu(wwin, event->xbutton.x_root,
3075 wwin->frame_y+wwin->frame->top_width, False);
3077 /* allow drag select */
3078 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
3079 event->xany.send_event = True;
3080 (*desc->handle_mousedown)(desc, event);
3082 XUngrabPointer(dpy, CurrentTime);
3088 static void
3089 windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
3091 WWindow *wwin = data;
3093 event->xbutton.state &= ValidModMask;
3095 CloseWindowMenu(wwin->screen_ptr);
3097 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3098 return;
3100 /* if control-click, kill the client */
3101 if (event->xbutton.state & ControlMask) {
3102 wClientKill(wwin);
3103 } else {
3104 #ifdef OLWM_HINTS
3105 if (wwin->flags.olwm_push_pin_out) {
3107 wwin->flags.olwm_push_pin_out = 0;
3109 wOLWMChangePushpinState(wwin, True);
3111 wFrameWindowUpdatePushButton(wwin->frame, False);
3113 return;
3115 #endif
3116 if (wwin->protocols.DELETE_WINDOW && event->xbutton.state==0) {
3117 /* send delete message */
3118 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3124 static void
3125 windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
3127 WWindow *wwin = data;
3129 CloseWindowMenu(wwin->screen_ptr);
3131 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3132 return;
3134 /* send delete message */
3135 if (wwin->protocols.DELETE_WINDOW) {
3136 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3137 } else {
3138 wClientKill(wwin);
3143 #ifdef XKB_BUTTON_HINT
3144 static void
3145 windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event)
3147 WWindow *wwin = data;
3148 WFrameWindow *fwin = wwin->frame;
3149 WScreen *scr = fwin->screen_ptr;
3150 XkbStateRec staterec;
3151 int tl;
3153 if (event->xbutton.button != Button1 && event->xbutton.button != Button3)
3154 return;
3155 tl = wwin->frame->languagemode;
3156 wwin->frame->languagemode = wwin->frame->last_languagemode;
3157 wwin->frame->last_languagemode = tl;
3158 wSetFocusTo(scr, wwin);
3159 wwin->frame->languagebutton_image =
3160 wwin->frame->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 +
3161 wwin->frame->languagemode];
3162 wFrameWindowUpdateLanguageButton(wwin->frame);
3163 if (event->xbutton.button == Button3)
3164 return;
3165 wRaiseFrame(fwin->core);
3167 #endif
3170 static void
3171 windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
3173 WWindow *wwin = data;
3175 event->xbutton.state &= ValidModMask;
3177 CloseWindowMenu(wwin->screen_ptr);
3179 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3180 return;
3182 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state==0) {
3183 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
3184 LastTimestamp);
3185 } else {
3186 WApplication *wapp;
3187 if ((event->xbutton.state & ControlMask) ||
3188 (event->xbutton.button == Button3)) {
3190 wapp = wApplicationOf(wwin->main_window);
3191 if (wapp && !WFLAGP(wwin, no_appicon))
3192 wHideApplication(wapp);
3193 } else if (event->xbutton.state==0) {
3194 wIconifyWindow(wwin);