Bug fixes for 0.20.3 pre-release 2
[wmaker-crm.git] / src / window.c
blob863274a6d8f5d99ac45b4c0b4332398ac878c635
1 /* window.c - client window managing class
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>
38 #include "WindowMaker.h"
39 #include "GNUstep.h"
40 #ifdef MWM_HINTS
41 # include "motif.h"
42 #endif
43 #include "wcore.h"
44 #include "framewin.h"
45 #include "texture.h"
46 #include "window.h"
47 #include "winspector.h"
48 #include "icon.h"
49 #include "properties.h"
50 #include "actions.h"
51 #include "client.h"
52 #include "funcs.h"
53 #include "keybind.h"
54 #include "stacking.h"
55 #include "defaults.h"
56 #include "workspace.h"
58 /****** Global Variables ******/
60 extern WShortKey wKeyBindings[WKBD_LAST];
62 #ifdef SHAPE
63 extern Bool wShapeSupported;
64 #endif
66 /* contexts */
67 extern XContext wWinContext;
69 /* cursors */
70 extern Cursor wCursor[WCUR_LAST];
72 /* protocol atoms */
73 extern Atom _XA_WM_DELETE_WINDOW;
74 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
76 extern Atom _XA_WINDOWMAKER_STATE;
78 extern WPreferences wPreferences;
80 #define MOD_MASK wPreferences.modifier_mask
82 extern Time LastTimestamp;
84 /* superfluous... */
85 extern void DoWindowBirth(WWindow*);
88 /***** Local Stuff *****/
91 static WWindowState *windowState=NULL;
95 /* local functions */
96 static FocusMode getFocusMode(WWindow *wwin);
98 static int getSavedState(Window window, WSavedState **state);
100 static void setupGNUstepHints(WWindowAttributes *attribs,
101 GNUstepWMAttributes *gs_hints);
103 #ifdef MWM_HINTS
104 static void setupMWMHints(WWindowAttributes *attribs, MWMHints *mwm_hints);
105 #endif
107 /* event handlers */
110 /* frame window (during window grabs) */
111 static void frameMouseDown(WObjDescriptor *desc, XEvent *event);
113 /* close button */
114 static void windowCloseClick(WCoreWindow *sender, void *data, XEvent *event);
115 static void windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event);
117 /* iconify button */
118 static void windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event);
121 static void titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
122 static void titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event);
124 static void resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
131 WWindow*
132 wWindowFor(Window window)
134 WObjDescriptor *desc;
136 if (window==None)
137 return NULL;
139 if (XFindContext(dpy, window, wWinContext, (XPointer*)&desc)==XCNOENT)
140 return NULL;
142 if (desc->parent_type==WCLASS_WINDOW)
143 return desc->parent;
144 else if (desc->parent_type==WCLASS_FRAME) {
145 WFrameWindow *frame = (WFrameWindow*)desc->parent;
146 if (frame->flags.is_client_window_frame)
147 return frame->child;
149 return NULL;
153 WWindow*
154 wWindowCreate()
156 WWindow *wwin;
158 wwin = wmalloc(sizeof(WWindow));
159 wretain(wwin);
161 memset(wwin, 0, sizeof(WWindow));
163 wwin->client_descriptor.handle_mousedown = frameMouseDown;
164 wwin->client_descriptor.parent = wwin;
165 wwin->client_descriptor.self = wwin;
166 wwin->client_descriptor.parent_type = WCLASS_WINDOW;
167 return wwin;
171 void
172 wWindowDestroy(WWindow *wwin)
174 int i;
176 wwin->flags.destroyed = 1;
178 for (i = 0; i < 4; i++) {
179 if (wwin->screen_ptr->shortcutWindow[i] == wwin) {
180 wwin->screen_ptr->shortcutWindow[i] = NULL;
184 if (wwin->normal_hints)
185 free(wwin->normal_hints);
187 if (wwin->wm_hints)
188 XFree(wwin->wm_hints);
190 if (wwin->wm_instance)
191 XFree(wwin->wm_instance);
193 if (wwin->wm_class)
194 XFree(wwin->wm_class);
196 if (wwin->wm_gnustep_attr)
197 free(wwin->wm_gnustep_attr);
199 if (wwin->cmap_windows)
200 XFree(wwin->cmap_windows);
202 XDeleteContext(dpy, wwin->client_win, wWinContext);
204 if (wwin->frame)
205 wFrameWindowDestroy(wwin->frame);
207 if (wwin->icon) {
208 RemoveFromStackList(wwin->icon->core);
209 wIconDestroy(wwin->icon);
210 if (wPreferences.auto_arrange_icons)
211 wArrangeIcons(wwin->screen_ptr, True);
213 wrelease(wwin);
219 static void
220 setupGNUstepHints(WWindowAttributes *attribs, GNUstepWMAttributes *gs_hints)
222 if (gs_hints->flags & GSWindowStyleAttr) {
223 attribs->no_titlebar =
224 ((gs_hints->window_style & WMTitledWindowMask)?0:1);
226 attribs->no_close_button = attribs->no_closable =
227 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
229 attribs->no_miniaturize_button = attribs->no_miniaturizable =
230 ((gs_hints->window_style & WMMiniaturizableWindowMask)?0:1);
232 attribs->no_resizebar = attribs->no_resizable =
233 ((gs_hints->window_style & WMResizableWindowMask)?0:1);
234 } else {
235 /* setup the defaults */
236 attribs->no_titlebar = 0;
237 attribs->no_closable = 0;
238 attribs->no_miniaturizable = 0;
239 attribs->no_resizable = 0;
240 attribs->no_close_button = 0;
241 attribs->no_miniaturize_button = 0;
242 attribs->no_resizebar = 0;
245 if (gs_hints->extra_flags & GSNoApplicationIconFlag) {
246 attribs->no_appicon = 1;
251 #ifdef MWM_HINTS
252 static void
253 setupMWMHints(WWindowAttributes *attribs, MWMHints *mwm_hints)
257 * We will ignore all decoration hints that have an equivalent as
258 * functions, because wmaker does not distinguish decoration hints
261 if (mwm_hints->flags & MWM_HINTS_DECORATIONS) {
262 # ifdef DEBUG
263 fprintf(stderr,"has decor hints [ ");
264 # endif
265 attribs->no_titlebar = 1;
266 attribs->no_close_button = 1;
267 attribs->no_miniaturize_button = 1;
268 attribs->no_resizebar = 1;
270 if (mwm_hints->decorations & MWM_DECOR_ALL) {
271 # ifdef DEBUG
272 fprintf(stderr,"ALL ");
273 # endif
274 attribs->no_titlebar = 0;
275 attribs->no_close_button = 0;
276 attribs->no_closable = 0;
277 attribs->no_miniaturize_button = 0;
278 attribs->no_miniaturizable = 0;
279 attribs->no_resizebar = 0;
280 attribs->no_resizable = 0;
283 if (mwm_hints->decorations & MWM_DECOR_BORDER) {
284 # ifdef DEBUG
285 fprintf(stderr,"(BORDER) ");
286 # endif
290 if (mwm_hints->decorations & MWM_DECOR_RESIZEH) {
291 # ifdef DEBUG
292 fprintf(stderr,"RESIZEH ");
293 # endif
294 attribs->no_resizebar = 0;
297 if (mwm_hints->decorations & MWM_DECOR_TITLE) {
298 # ifdef DEBUG
299 fprintf(stderr,"TITLE+close ");
300 # endif
301 attribs->no_titlebar = 0;
302 attribs->no_close_button = 0;
303 attribs->no_closable = 0;
306 if (mwm_hints->decorations & MWM_DECOR_MENU) {
307 # ifdef DEBUG
308 fprintf(stderr,"(MENU) ");
309 # endif
313 if (mwm_hints->decorations & MWM_DECOR_MINIMIZE) {
314 # ifdef DEBUG
315 fprintf(stderr,"MINIMIZE ");
316 # endif
317 attribs->no_miniaturize_button = 0;
318 attribs->no_miniaturizable = 0;
321 if (mwm_hints->decorations & MWM_DECOR_MAXIMIZE) {
322 # ifdef DEBUG
323 fprintf(stderr,"(MAXIMIZE) ");
324 # endif
327 # ifdef DEBUG
328 fprintf(stderr,"]\n");
329 # endif
333 if (mwm_hints->flags & MWM_HINTS_FUNCTIONS) {
334 # ifdef DEBUG
335 fprintf(stderr,"has function hints [ ");
336 # endif
337 attribs->no_closable = 1;
338 attribs->no_miniaturizable = 1;
339 attribs->no_resizable = 1;
341 if (mwm_hints->functions & MWM_FUNC_ALL) {
342 # ifdef DEBUG
343 fprintf(stderr,"ALL ");
344 # endif
345 attribs->no_closable = 0;
346 attribs->no_miniaturizable = 0;
347 attribs->no_resizable = 0;
349 if (mwm_hints->functions & MWM_FUNC_RESIZE) {
350 # ifdef DEBUG
351 fprintf(stderr,"RESIZE ");
352 # endif
353 attribs->no_resizable = 0;
356 if (mwm_hints->functions & MWM_FUNC_MOVE) {
357 # ifdef DEBUG
358 fprintf(stderr,"(MOVE) ");
359 # endif
362 if (mwm_hints->functions & MWM_FUNC_MINIMIZE) {
363 # ifdef DEBUG
364 fprintf(stderr,"MINIMIZE ");
365 # endif
366 attribs->no_miniaturizable = 0;
368 if (mwm_hints->functions & MWM_FUNC_MAXIMIZE) {
369 # ifdef DEBUG
370 fprintf(stderr,"MAXIMIZE ");
371 /* a window must be resizable to be maximizable */
372 attribs->no_resizable = 0;
373 # endif
375 if (mwm_hints->functions & MWM_FUNC_CLOSE) {
376 # ifdef DEBUG
377 fprintf(stderr,"CLOSE ");
378 # endif
379 attribs->no_closable = 0;
381 # ifdef DEBUG
382 fprintf(stderr,"]\n");
383 # endif
386 #endif /* MWM_HINTS */
389 void
390 wWindowCheckAttributeSanity(WWindow *wwin, WWindowAttributes *wflags)
392 if (wflags->no_appicon)
393 wflags->emulate_appicon = 0;
395 if (wwin->main_window!=None) {
396 WApplication *wapp = wApplicationOf(wwin->main_window);
397 if (wapp && !wapp->flags.emulated)
398 wflags->emulate_appicon = 0;
401 if (wwin->transient_for!=None
402 && wwin->transient_for!=wwin->screen_ptr->root_win)
403 wflags->emulate_appicon = 0;
408 Bool
409 wWindowCanReceiveFocus(WWindow *wwin)
411 if (!wwin->flags.mapped && !wwin->flags.shaded)
412 return False;
413 if (wwin->window_flags.no_focusable || wwin->flags.miniaturized)
414 return False;
415 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
416 return False;
418 return True;
423 *----------------------------------------------------------------
424 * wManageWindow--
425 * reparents the window and allocates a descriptor for it.
426 * Window manager hints and other hints are fetched to configure
427 * the window decoration attributes and others. User preferences
428 * for the window are used if available, to configure window
429 * decorations and some behaviour.
431 * Returns:
432 * the new window descriptor
434 * Side effects:
435 * The window is reparented and appropriate notification
436 * is done to the client. Input mask for the window is setup.
437 * The window descriptor is also associated with various window
438 * contexts and inserted in the head of the window list.
439 * Event handler contexts are associated for some objects
440 * (buttons, titlebar and resizebar)
442 * TODO:
443 * Check if the window_flags setting is correct.
444 *----------------------------------------------------------------
446 WWindow*
447 wManageWindow(WScreen *scr, Window window)
449 WWindow *wwin;
450 int x, y;
451 unsigned width, height;
452 XWindowAttributes wattribs;
453 XSetWindowAttributes attribs;
454 int iconic = 0;
455 WWindowState *win_state;
456 #ifdef MWM_HINTS
457 MWMHints *motif_hints = NULL;
458 #endif
459 int window_level;
460 int foo;
461 int workspace = -1;
462 char *title;
464 /* mutex. */
465 XGrabServer(dpy);
466 XSync(dpy, 0);
467 /* make sure the window is still there */
468 if (!XGetWindowAttributes(dpy, window, &wattribs)) {
469 XUngrabServer(dpy);
470 return NULL;
472 wwin = wWindowCreate();
474 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
476 #ifdef DEBUG
477 printf("managing window %x\n", (unsigned)window);
478 #endif
480 #ifdef SHAPE
481 if (wShapeSupported) {
482 int junk;
483 unsigned int ujunk;
484 int b_shaped;
486 XShapeSelectInput(dpy, window, ShapeNotifyMask);
487 XShapeQueryExtents(dpy, window, &b_shaped, &junk, &junk, &ujunk,
488 &ujunk, &junk, &junk, &junk, &ujunk, &ujunk);
489 wwin->flags.shaped = b_shaped;
491 #endif
494 *--------------------------------------------------
496 * Get hints and other information in properties
498 *--------------------------------------------------
500 wwin->wm_hints = XGetWMHints(dpy, window);
501 PropGetWMClass(window, &wwin->wm_class, &wwin->wm_instance);
503 /* setup descriptor */
504 wwin->client_win = window;
505 wwin->screen_ptr = scr;
507 wwin->old_border_width = wattribs.border_width;
509 attribs.event_mask = CLIENT_EVENTS;
510 attribs.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask;
511 attribs.save_under = False;
512 XChangeWindowAttributes(dpy, window, CWEventMask|CWDontPropagate
513 |CWSaveUnder, &attribs);
514 XSetWindowBorderWidth(dpy, window, 0);
516 /* fill in property/hint data */
517 if (!wFetchName(dpy, window, &title)) {
518 title = NULL;
520 /* get hints from GNUstep app */
521 if (!PropGetGNUstepWMAttr(window, &wwin->wm_gnustep_attr)) {
522 wwin->wm_gnustep_attr=NULL;
525 #ifdef MWM_HINTS
526 if (!PropGetMotifWMHints(window, &motif_hints))
527 motif_hints = NULL;
528 #endif /* MWM_HINTS */
530 if (!PropGetClientLeader(window, &wwin->client_leader)) {
531 wwin->client_leader = None;
532 } else {
533 wwin->main_window = wwin->client_leader;
536 if (wwin->wm_hints)
537 XFree(wwin->wm_hints);
539 wwin->wm_hints = XGetWMHints(dpy, window);
541 if (wwin->wm_hints) {
542 if ((wwin->wm_hints->flags&StateHint)
543 && (wwin->wm_hints->initial_state == IconicState)) {
544 iconic = 1;
545 /* don't do iconify animation */
546 wwin->flags.skip_next_animation = 1;
549 if (wwin->wm_hints->flags & WindowGroupHint) {
550 wwin->group_id = wwin->wm_hints->window_group;
551 /* window_group has priority over CLIENT_LEADER */
552 wwin->main_window = wwin->group_id;
553 } else {
554 wwin->group_id = None;
557 if (wwin->wm_hints->flags & UrgencyHint)
558 wwin->flags.urgent = 1;
559 } else {
560 wwin->group_id = None;
563 PropGetProtocols(window, &wwin->protocols);
565 if (!XGetTransientForHint(dpy, window, &wwin->transient_for)) {
566 wwin->transient_for = None;
567 } else {
568 if (wwin->transient_for==None || wwin->transient_for==window) {
569 wwin->transient_for = scr->root_win;
570 } else {
571 WWindow *owner;
572 owner = wWindowFor(wwin->transient_for);
573 if (owner && owner->main_window!=None) {
574 wwin->main_window = owner->main_window;
575 } /*else {
576 wwin->main_window = None;
579 /* don't let transients start miniaturized if their owners
580 * are not */
581 if (owner && !owner->flags.miniaturized && iconic) {
582 iconic = 0;
583 if (wwin->wm_hints)
584 wwin->wm_hints->initial_state = NormalState;
589 /* guess the focus mode */
590 wwin->focus_mode = getFocusMode(wwin);
592 /* get geometry stuff */
593 wClientGetNormalHints(wwin, &wattribs, True, &x, &y, &width, &height);
595 /* get colormap windows */
596 GetColormapWindows(wwin);
600 *--------------------------------------------------
602 * Setup the decoration/window attributes and
603 * geometry
605 *--------------------------------------------------
607 /* sets global default stuff */
608 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
609 &wwin->window_flags, True);
611 * Decoration setting is done in this precedence (lower to higher)
612 * - use default in the resource database
613 * - guess some settings
614 * - use GNUstep/external window attributes
615 * - set hints specified for the app in the resource DB
617 wwin->window_flags.broken_close = 0;
619 if (wwin->protocols.DELETE_WINDOW)
620 wwin->window_flags.kill_close = 0;
621 else
622 wwin->window_flags.kill_close = 1;
624 /* transients can't be iconified or maximized */
625 if (wwin->transient_for) {
626 wwin->window_flags.no_miniaturizable = 1;
627 wwin->window_flags.no_miniaturize_button = 1;
628 #ifdef DEBUG
629 printf("%x is transient for %x\n", (unsigned)window,
630 (unsigned)wwin->transient_for);
631 #endif
634 /* if the window can't be resized, remove the resizebar */
635 if (wwin->normal_hints->flags & (PMinSize|PMaxSize)
636 && (wwin->normal_hints->min_width==wwin->normal_hints->max_width)
637 && (wwin->normal_hints->min_height==wwin->normal_hints->max_height)) {
638 wwin->window_flags.no_resizable = 1;
639 wwin->window_flags.no_resizebar = 1;
642 /* set GNUstep window attributes */
643 if (wwin->wm_gnustep_attr) {
644 setupGNUstepHints(&wwin->window_flags, wwin->wm_gnustep_attr);
645 if (wwin->wm_gnustep_attr->flags & GSWindowLevelAttr) {
646 window_level = wwin->wm_gnustep_attr->window_level;
647 } else {
648 /* setup defaults */
649 window_level = WMNormalWindowLevel;
651 } else {
652 #ifdef MWM_HINTS
653 if (motif_hints) {
654 setupMWMHints(&wwin->window_flags, motif_hints);
656 #endif /* MWM_HINTS */
657 if (wwin->window_flags.floating)
658 window_level = WMFloatingWindowLevel;
659 else
660 window_level = WMNormalWindowLevel;
662 #ifdef MWM_HINTS
663 if (motif_hints)
664 free(motif_hints);
665 #endif
668 * Set attributes specified only for that window/class.
669 * This might do duplicate work with the 1st wDefaultFillAttributes().
670 * TODO: Do something about that.
672 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
673 &wwin->window_flags, False);
677 * Sanity checks for attributes that depend on other attributes
679 wWindowCheckAttributeSanity(wwin, &wwin->window_flags);
681 wwin->window_flags.no_shadeable = wwin->window_flags.no_titlebar;
684 * Make broken apps behave as a nice app.
686 if (wwin->window_flags.emulate_appicon) {
687 wwin->main_window = wwin->client_win;
691 *------------------------------------------------------------
693 * Setup the initial state of the window
695 *------------------------------------------------------------
697 if (wwin->window_flags.start_miniaturized
698 && !wwin->window_flags.no_miniaturizable) {
699 wwin->flags.miniaturized = 1;
700 iconic = 1;
703 /* if there is a saved state, restore it */
704 win_state = NULL;
705 if (wwin->main_window!=None/* && wwin->main_window!=window*/) {
706 win_state = (WWindowState*)wWindowGetSavedState(wwin->main_window);
707 } else {
708 win_state = (WWindowState*)wWindowGetSavedState(window);
710 if (win_state && !(wwin->wm_hints && wwin->wm_hints->flags&StateHint &&
711 wwin->wm_hints->initial_state==WithdrawnState)) {
712 if (win_state->state->hidden>0)
713 wwin->flags.hidden = win_state->state->hidden;
714 if (win_state->state->shaded>0 && !wwin->window_flags.no_shadeable)
715 wwin->flags.shaded = win_state->state->shaded;
716 if (win_state->state->miniaturized>0 &&
717 !wwin->window_flags.no_miniaturizable) {
718 wwin->flags.miniaturized = win_state->state->miniaturized;
719 iconic = 1;
721 if (!wwin->window_flags.omnipresent) {
722 int w = wDefaultGetStartWorkspace(scr, wwin->wm_instance,
723 wwin->wm_class);
724 if (w < 0 || w >= scr->workspace_count) {
725 workspace = win_state->state->workspace;
726 if (workspace>=scr->workspace_count)
727 workspace = scr->current_workspace;
728 } else {
729 workspace = w;
731 } else {
732 workspace = scr->current_workspace;
736 /* if we're restarting, restore saved state. This will overwrite previous */
738 WSavedState *wstate;
740 if (getSavedState(window, &wstate)) {
741 wwin->flags.shaded = wstate->shaded;
742 wwin->flags.hidden = wstate->hidden;
743 wwin->flags.miniaturized = 0;
744 workspace = wstate->workspace;
745 free(wstate);
750 /* set workspace on which the window starts */
751 if (workspace >= 0) {
752 if (workspace > scr->workspace_count-1) {
753 wWorkspaceMake(scr, workspace - scr->workspace_count + 1);
754 workspace = scr->workspace_count - 1;
756 } else {
757 int w;
759 w = wDefaultGetStartWorkspace(scr, wwin->wm_instance, wwin->wm_class);
760 if (w>=0 && w<scr->workspace_count && !wwin->window_flags.omnipresent) {
761 workspace = w;
762 } else {
763 workspace = scr->current_workspace;
767 /* setup window geometry */
768 if (win_state && win_state->state->use_geometry) {
769 width = win_state->state->w;
770 height = win_state->state->h;
772 wWindowConstrainSize(wwin, &width, &height);
774 /* do not ask for window placement if the window is
775 * transient, during startup, if the initial workspace is another one
776 * or if the window wants to
777 * start iconic.
778 * If geometry was saved, restore it. */
779 if (win_state && win_state->state->use_geometry) {
780 x = win_state->state->x;
781 y = win_state->state->y;
782 } else if (wwin->transient_for==None && !scr->flags.startup &&
783 workspace==scr->current_workspace && !iconic &&
784 !(wwin->normal_hints->flags & (USPosition|PPosition))) {
785 PlaceWindow(wwin, &x, &y, width, height);
788 if (wwin->window_flags.dont_move_off)
789 wScreenBringInside(scr, &x, &y, width, height);
792 *--------------------------------------------------
794 * Create frame, borders and do reparenting
796 *--------------------------------------------------
799 foo = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
800 if (!wwin->window_flags.no_titlebar)
801 foo |= WFF_TITLEBAR;
802 if (!wwin->window_flags.no_resizebar)
803 foo |= WFF_RESIZEBAR;
805 wwin->frame = wFrameWindowCreate(scr, window_level,
806 x, y, width, height, foo,
807 scr->window_title_texture,
808 (WTexture**)scr->resizebar_texture,
809 scr->window_title_pixel,
810 &scr->window_title_gc,
811 &scr->title_font);
813 wwin->frame->flags.is_client_window_frame = 1;
814 wwin->frame->flags.justification = wPreferences.title_justification;
816 /* setup button images */
817 wWindowUpdateButtonImages(wwin);
819 /* hide unused buttons */
820 foo = 0;
821 if (wwin->window_flags.no_close_button)
822 foo |= WFF_RIGHT_BUTTON;
823 if (wwin->window_flags.no_miniaturize_button)
824 foo |= WFF_LEFT_BUTTON;
825 if (foo!=0)
826 wFrameWindowHideButton(wwin->frame, foo);
829 wwin->frame->child = wwin;
831 wFrameWindowChangeTitle(wwin->frame, title ? title : DEF_WINDOW_TITLE);
832 if (title)
833 XFree(title);
835 wwin->frame->workspace = workspace;
837 wwin->frame->on_click_left = windowIconifyClick;
839 wwin->frame->on_click_right = windowCloseClick;
840 wwin->frame->on_dblclick_right = windowCloseDblClick;
842 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
843 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
845 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
847 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
848 0, wwin->frame->top_width);
850 #if 0
852 int gx, gy;
854 wClientGetGravityOffsets(wwin, &gx, &gy);
855 /* set the position of the frame on screen */
856 x += gx * FRAME_BORDER_WIDTH;
857 y += gy * FRAME_BORDER_WIDTH;
858 /* if gravity is to the south, account for the border sizes */
859 if (gy > 0)
860 y -= wwin->frame->top_width + wwin->frame->bottom_width;
862 #endif
864 * wWindowConfigure() will init the client window's size
865 * (wwin->client.{width,height}) and all other geometry
866 * related variables (frame_x,frame_y)
868 wWindowConfigure(wwin, x, y, width, height);
871 *--------------------------------------------------
873 * Setup descriptors and save window to internal
874 * lists
876 *--------------------------------------------------
879 if (wwin->main_window!=None) {
880 WApplication *app;
881 WWindow *leader;
883 /* Leader windows do not necessary set themselves as leaders.
884 * If this is the case, point the leader of this window to
885 * itself */
886 leader = wWindowFor(wwin->main_window);
887 if (leader && leader->main_window==None) {
888 leader->main_window = leader->client_win;
891 app = wApplicationCreate(scr, wwin->main_window);
892 if (app) {
893 app->last_workspace = workspace;
896 * Do application specific stuff, like setting application
897 * wide attributes.
900 if (wwin->flags.hidden) {
901 /* if the window was set to hidden because it was hidden
902 * in a previous incarnation and that state was restored */
903 app->flags.hidden = 1;
906 if (app->flags.hidden) {
907 wwin->flags.hidden = 1;
912 /* setup the frame descriptor */
913 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
914 wwin->frame->core->descriptor.parent = wwin;
915 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
917 /* don't let windows go away if we die */
918 XAddToSaveSet(dpy, window);
920 XLowerWindow(dpy, window);
922 /* if window is in this workspace and should be mapped, then map it */
923 if (!iconic && (workspace == scr->current_workspace
924 || wwin->window_flags.omnipresent)
925 && !wwin->flags.hidden
926 && !(wwin->wm_hints && (wwin->wm_hints->flags & StateHint)
927 && wwin->wm_hints->initial_state == WithdrawnState)) {
928 /* The following "if" is to avoid crashing of clients that expect
929 * WM_STATE set before they get mapped. Else WM_STATE is set later,
930 * after the return from this function.
932 if (wwin->wm_hints && (wwin->wm_hints->flags & StateHint)) {
933 wClientSetState(wwin, wwin->wm_hints->initial_state, None);
934 } else {
935 wClientSetState(wwin, NormalState, None);
937 if (wPreferences.superfluous && !wPreferences.no_animations
938 && !scr->flags.startup && wwin->transient_for==None
940 * The brain damaged idiotic non-click to focus modes will
941 * have trouble with this because:
943 * 1. window is created and mapped by the client
944 * 2. window is mapped by wmaker in small size
945 * 3. window is animated to grow to normal size
946 * 4. this function returns to normal event loop
947 * 5. eventually, the EnterNotify event that would trigger
948 * the window focusing (if the mouse is over that window)
949 * will be processed by wmaker.
950 * But since this event will be rather delayed
951 * (step 3 has a large delay) the time when the event ocurred
952 * and when it is processed, the client that owns that window
953 * will reject the XSetInputFocus() for it.
955 && (wPreferences.focus_mode==WKF_CLICK
956 || wPreferences.auto_focus)) {
957 DoWindowBirth(wwin);
959 XMapSubwindows(dpy, wwin->frame->core->window);
960 wWindowMap(wwin);
961 } else {
962 XMapSubwindows(dpy, wwin->frame->core->window);
965 /* setup stacking descriptor */
966 if (wPreferences.on_top_transients && wwin->transient_for!=None
967 && wwin->transient_for!=scr->root_win) {
968 WWindow *tmp;
969 tmp = wWindowFor(wwin->transient_for);
970 if (tmp)
971 wwin->frame->core->stacking->child_of = tmp->frame->core;
972 } else {
973 wwin->frame->core->stacking->child_of = NULL;
977 if (!scr->focused_window) {
978 /* first window on the list */
979 wwin->next = NULL;
980 wwin->prev = NULL;
981 scr->focused_window = wwin;
982 } else {
983 WWindow *tmp;
985 /* add window at beginning of focus window list */
986 tmp = scr->focused_window;
987 while (tmp->prev)
988 tmp = tmp->prev;
989 tmp->prev = wwin;
990 wwin->next = tmp;
991 wwin->prev = NULL;
995 XUngrabServer(dpy);
998 *--------------------------------------------------
1000 * Final preparations before window is ready to go
1002 *--------------------------------------------------
1005 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1008 if (!iconic && workspace == scr->current_workspace) {
1009 WWindow *tmp = wWindowFor(wwin->transient_for);
1011 if ((tmp && tmp->flags.focused) || wPreferences.auto_focus)
1012 wSetFocusTo(scr, wwin);
1013 } else {
1014 wwin->flags.ignore_next_unmap = 1;
1016 wWindowResetMouseGrabs(wwin);
1018 if (!wwin->window_flags.no_bind_keys) {
1019 wWindowSetKeyGrabs(wwin);
1023 * Prevent window withdrawal when getting the
1024 * unmap notifies generated during reparenting
1026 wwin->flags.mapped=0;
1028 XSync(dpy, 0);
1030 wColormapInstallForWindow(wwin->screen_ptr, scr->cmap_window);
1032 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_ADD);
1034 *--------------------------------------------------
1035 * Cleanup temporary stuff
1036 *--------------------------------------------------
1039 if (win_state)
1040 wWindowDeleteSavedState(win_state);
1042 return wwin;
1049 WWindow*
1050 wManageInternalWindow(WScreen *scr, Window window, Window owner,
1051 char *title, int x, int y, int width, int height)
1053 WWindow *wwin;
1054 int foo;
1056 wwin = wWindowCreate();
1058 wwin->flags.internal_window = 1;
1059 wwin->window_flags.omnipresent = 1;
1060 wwin->window_flags.no_shadeable = 1;
1061 wwin->window_flags.no_resizable = 1;
1062 wwin->window_flags.no_miniaturizable = 1;
1064 wwin->focus_mode = WFM_PASSIVE;
1066 wwin->client_win = window;
1067 wwin->screen_ptr = scr;
1069 wwin->transient_for = owner;
1071 wwin->client.x = x;
1072 wwin->client.y = y;
1073 wwin->client.width = width;
1074 wwin->client.height = height;
1076 wwin->frame_x = wwin->client.x;
1077 wwin->frame_y = wwin->client.y;
1080 foo = WFF_RIGHT_BUTTON;
1081 foo |= WFF_TITLEBAR;
1083 wwin->frame = wFrameWindowCreate(scr, WMFloatingWindowLevel,
1084 wwin->frame_x, wwin->frame_y,
1085 width, height, foo,
1086 scr->window_title_texture,
1087 (WTexture**)scr->resizebar_texture,
1088 scr->window_title_pixel,
1089 &scr->window_title_gc,
1090 &scr->title_font);
1092 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
1094 wwin->frame->flags.is_client_window_frame = 1;
1095 wwin->frame->flags.justification = wPreferences.title_justification;
1097 wFrameWindowChangeTitle(wwin->frame, title);
1099 /* setup button images */
1100 wWindowUpdateButtonImages(wwin);
1102 /* hide buttons */
1103 wFrameWindowHideButton(wwin->frame, WFF_RIGHT_BUTTON);
1105 wwin->frame->child = wwin;
1107 wwin->frame->workspace = wwin->screen_ptr->current_workspace;
1109 wwin->frame->on_click_right = windowCloseClick;
1111 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1112 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1114 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1116 wwin->client.y += wwin->frame->top_width;
1117 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1118 0, wwin->frame->top_width);
1120 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y,
1121 wwin->client.width, wwin->client.height);
1123 /* setup the frame descriptor */
1124 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1125 wwin->frame->core->descriptor.parent = wwin;
1126 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1129 XLowerWindow(dpy, window);
1130 XMapSubwindows(dpy, wwin->frame->core->window);
1132 /* setup stacking descriptor */
1133 if (wPreferences.on_top_transients && wwin->transient_for!=None
1134 && wwin->transient_for!=scr->root_win) {
1135 WWindow *tmp;
1136 tmp = wWindowFor(wwin->transient_for);
1137 if (tmp)
1138 wwin->frame->core->stacking->child_of = tmp->frame->core;
1139 } else {
1140 wwin->frame->core->stacking->child_of = NULL;
1144 if (!scr->focused_window) {
1145 /* first window on the list */
1146 wwin->next = NULL;
1147 wwin->prev = NULL;
1148 scr->focused_window = wwin;
1149 } else {
1150 WWindow *tmp;
1152 /* add window at beginning of focus window list */
1153 tmp = scr->focused_window;
1154 while (tmp->prev)
1155 tmp = tmp->prev;
1156 tmp->prev = wwin;
1157 wwin->next = tmp;
1158 wwin->prev = NULL;
1161 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1163 /* if (wPreferences.auto_focus)*/
1164 wSetFocusTo(scr, wwin);
1166 wWindowResetMouseGrabs(wwin);
1168 wWindowSetKeyGrabs(wwin);
1170 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_ADD);
1172 return wwin;
1177 *----------------------------------------------------------------------
1178 * wUnmanageWindow--
1179 * Removes the frame window from a window and destroys all data
1180 * related to it. The window will be reparented back to the root window
1181 * if restore is True.
1183 * Side effects:
1184 * Everything related to the window is destroyed and the window
1185 * is removed from the window lists. Focus is set to the previous on the
1186 * window list.
1187 *----------------------------------------------------------------------
1189 void
1190 wUnmanageWindow(WWindow *wwin, int restore)
1192 WCoreWindow *frame = wwin->frame->core;
1193 WWindow *owner;
1194 WWindow *newFocusedWindow;
1195 int wasNotFocused;
1196 WScreen *scr = wwin->screen_ptr;
1198 /* First close attribute editor window if open */
1199 if (wwin->flags.inspector_open) {
1200 WWindow *pwin = wwin->inspector->frame; /* the inspector window */
1201 (*pwin->frame->on_click_right)(NULL, pwin, NULL);
1204 /* Close window menu if it's open for this window */
1205 if (wwin->flags.menu_open_for_me) {
1206 CloseWindowMenu(scr);
1208 if (!wwin->flags.internal_window)
1209 XRemoveFromSaveSet(dpy, wwin->client_win);
1210 XSelectInput(dpy, wwin->client_win, NoEventMask);
1212 XUnmapWindow(dpy, frame->window);
1214 /* deselect window */
1215 wSelectWindow(wwin, False);
1217 /* remove all pending events on window */
1218 /* I think this only matters for autoraise */
1219 if (wPreferences.raise_delay)
1220 WMDeleteTimerWithClientData(wwin->frame->core);
1222 XFlush(dpy);
1224 UpdateSwitchMenu(scr, wwin, ACTION_REMOVE);
1226 /* reparent the window back to the root */
1227 if (restore)
1228 wClientRestore(wwin);
1230 if (wwin->transient_for!=scr->root_win) {
1231 owner = wWindowFor(wwin->transient_for);
1232 if (owner) {
1233 owner->flags.semi_focused = 0;
1234 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1238 wasNotFocused = !wwin->flags.focused;
1240 /* remove from window focus list */
1241 if (!wwin->prev && !wwin->next) {
1242 /* was the only window */
1243 scr->focused_window = NULL;
1244 newFocusedWindow = NULL;
1245 } else {
1246 WWindow *tmp;
1248 if (wwin->prev)
1249 wwin->prev->next = wwin->next;
1250 if (wwin->next)
1251 wwin->next->prev = wwin->prev;
1252 else {
1253 scr->focused_window = wwin->prev;
1254 scr->focused_window->next = NULL;
1257 /* if in click to focus mode and the window
1258 * was a transient, focus the owner window
1260 tmp = NULL;
1261 if (wPreferences.focus_mode==WKF_CLICK) {
1262 tmp = wWindowFor(wwin->transient_for);
1263 if (tmp && (!tmp->flags.mapped || tmp->window_flags.no_focusable)) {
1264 tmp = NULL;
1267 /* otherwise, focus the next one in the focus list */
1268 if (!tmp) {
1269 tmp = scr->focused_window;
1270 while (tmp) {
1271 if (!tmp->window_flags.no_focusable
1272 && (tmp->flags.mapped || tmp->flags.shaded))
1273 break;
1274 tmp = tmp->prev;
1277 if (wPreferences.focus_mode==WKF_CLICK) {
1278 newFocusedWindow = tmp;
1279 } else if (wPreferences.focus_mode==WKF_SLOPPY
1280 || wPreferences.focus_mode==WKF_POINTER) {
1281 unsigned int mask;
1282 int foo;
1283 Window bar, win;
1285 /* This is to let the root window get the keyboard input
1286 * if Sloppy focus mode and no other window get focus.
1287 * This way keybindings will not freeze.
1289 tmp = NULL;
1290 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
1291 &foo, &foo, &foo, &foo, &mask))
1292 tmp = wWindowFor(win);
1293 if (tmp == wwin)
1294 tmp = NULL;
1295 newFocusedWindow = tmp;
1296 } else {
1297 newFocusedWindow = NULL;
1300 #ifdef DEBUG
1301 printf("destroying window %x frame %x\n", (unsigned)wwin->client_win,
1302 (unsigned)frame->window);
1303 #endif
1304 if (!wasNotFocused)
1305 wSetFocusTo(scr, newFocusedWindow);
1306 wWindowDestroy(wwin);
1307 XFlush(dpy);
1311 void
1312 wWindowFocus(WWindow *wwin)
1314 #ifdef KEEP_XKB_LOCK_STATUS
1315 if (wPreferences.modelock) {
1316 if (!wwin->flags.focused) {
1317 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->languagemode);
1320 #endif /* KEEP_XKB_LOCK_STATUS */
1322 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1324 wwin->flags.focused=1;
1326 wWindowResetMouseGrabs(wwin);
1328 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1332 void
1333 wWindowMap(WWindow *wwin)
1335 XMapWindow(dpy, wwin->frame->core->window);
1336 wwin->flags.mapped = 1;
1341 void
1342 wWindowUnfocus(WWindow *wwin)
1344 #ifdef KEEP_XKB_LOCK_STATUS
1345 static XkbStateRec staterec;
1346 if (wPreferences.modelock) {
1347 if (wwin->flags.focused) {
1348 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1349 wwin->languagemode=staterec.compat_state&32?1:0;
1350 XkbLockGroup(dpy,XkbUseCoreKbd,0); /* reset to workspace */
1353 #endif /* KEEP_XKB_LOCK_STATUS */
1355 CloseWindowMenu(wwin->screen_ptr);
1357 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused
1358 ? WS_PFOCUSED : WS_UNFOCUSED);
1360 if (wwin->transient_for!=None
1361 && wwin->transient_for!=wwin->screen_ptr->root_win) {
1362 WWindow *owner;
1363 owner = wWindowFor(wwin->transient_for);
1364 if (owner && owner->flags.semi_focused) {
1365 owner->flags.semi_focused = 0;
1366 if (owner->flags.mapped || owner->flags.shaded) {
1367 wWindowUnfocus(owner);
1368 wFrameWindowPaint(owner->frame);
1372 wwin->flags.focused=0;
1373 wWindowResetMouseGrabs(wwin);
1375 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1381 *----------------------------------------------------------------------
1383 * wWindowConstrainSize--
1384 * Constrains size for the client window, taking the maximal size,
1385 * window resize increments and other size hints into account.
1387 * Returns:
1388 * The closest size to what was given that the client window can
1389 * have.
1391 *----------------------------------------------------------------------
1393 void
1394 wWindowConstrainSize(WWindow *wwin, int *nwidth, int *nheight)
1396 XSizeHints *sizeh = wwin->normal_hints;
1397 int width = *nwidth;
1398 int height = *nheight;
1399 int winc = sizeh->width_inc;
1400 int hinc = sizeh->height_inc;
1402 if (width < sizeh->min_width)
1403 width = sizeh->min_width;
1404 if (height < sizeh->min_height)
1405 height = sizeh->min_height;
1407 if (width > sizeh->max_width)
1408 width = sizeh->max_width;
1409 if (height > sizeh->max_height)
1410 height = sizeh->max_height;
1412 /* aspect ratio code borrowed from olwm */
1413 if (sizeh->flags & PAspect) {
1414 /* adjust max aspect ratio */
1415 if (!(sizeh->max_aspect.x==1 && sizeh->max_aspect.y==1)
1416 && width * sizeh->max_aspect.y > height * sizeh->max_aspect.x) {
1417 if (sizeh->max_aspect.x > sizeh->max_aspect.y) {
1418 height = (width * sizeh->max_aspect.y) / sizeh->max_aspect.x;
1419 if (height > sizeh->max_height) {
1420 height = sizeh->max_height;
1421 width = (height*sizeh->max_aspect.x) / sizeh->max_aspect.y;
1423 } else {
1424 width = (height * sizeh->max_aspect.x) / sizeh->max_aspect.y;
1425 if (width > sizeh->max_width) {
1426 width = sizeh->max_width;
1427 height = (width*sizeh->max_aspect.y) / sizeh->max_aspect.x;
1432 /* adjust min aspect ratio */
1433 if (!(sizeh->min_aspect.x==1 && sizeh->min_aspect.y==1)
1434 && width * sizeh->min_aspect.y < height * sizeh->min_aspect.x) {
1435 if (sizeh->min_aspect.x > sizeh->min_aspect.y) {
1436 height = (width * sizeh->min_aspect.y) / sizeh->min_aspect.x;
1437 if (height < sizeh->min_height) {
1438 height = sizeh->min_height;
1439 width = (height*sizeh->min_aspect.x) / sizeh->min_aspect.y;
1441 } else {
1442 width = (height * sizeh->min_aspect.x) / sizeh->min_aspect.y;
1443 if (width > sizeh->min_width) {
1444 width = sizeh->min_width;
1445 height = (width*sizeh->min_aspect.y) / sizeh->min_aspect.x;
1451 if (sizeh->base_width != 0) {
1452 width = (((width - sizeh->base_width) / winc) * winc)
1453 + sizeh->base_width;
1454 } else {
1455 width = (((width - sizeh->min_width) / winc) * winc)
1456 + sizeh->min_width;
1459 if (sizeh->base_width != 0) {
1460 height = (((height - sizeh->base_height) / hinc) * hinc)
1461 + sizeh->base_height;
1462 } else {
1463 height = (((height - sizeh->min_height) / hinc) * hinc)
1464 + sizeh->min_height;
1467 *nwidth = width;
1468 *nheight = height;
1472 void
1473 wWindowChangeWorkspace(WWindow *wwin, int workspace)
1475 WScreen *scr = wwin->screen_ptr;
1476 WApplication *wapp;
1478 if (workspace >= scr->workspace_count || workspace < 0
1479 || workspace == wwin->frame->workspace)
1480 return;
1482 if (workspace != scr->current_workspace) {
1483 /* Sent to other workspace. Unmap window */
1484 if ((wwin->flags.mapped||wwin->flags.shaded)
1485 && !wwin->window_flags.omnipresent
1486 && !wwin->flags.changing_workspace) {
1488 wapp = wApplicationOf(wwin->main_window);
1489 if (wapp) {
1490 wapp->last_workspace = workspace;
1492 XUnmapWindow(dpy, wwin->frame->core->window);
1493 wwin->flags.mapped = 0;
1494 wSetFocusTo(scr, NULL);
1496 } else {
1497 /* brought to current workspace. Map window */
1498 if (!wwin->flags.mapped &&
1499 !(wwin->flags.miniaturized || wwin->flags.hidden)) {
1500 wWindowMap(wwin);
1503 if (!wwin->window_flags.omnipresent) {
1504 wwin->frame->workspace = workspace;
1505 UpdateSwitchMenu(scr, wwin, ACTION_CHANGE_WORKSPACE);
1510 void
1511 wWindowSynthConfigureNotify(WWindow *wwin)
1513 XEvent sevent;
1515 sevent.type = ConfigureNotify;
1516 sevent.xconfigure.display = dpy;
1517 sevent.xconfigure.event = wwin->client_win;
1518 sevent.xconfigure.window = wwin->client_win;
1520 sevent.xconfigure.x = wwin->client.x;
1521 sevent.xconfigure.y = wwin->client.y;
1522 sevent.xconfigure.width = wwin->client.width;
1523 sevent.xconfigure.height = wwin->client.height;
1525 sevent.xconfigure.border_width = wwin->old_border_width;
1526 if (wwin->window_flags.no_titlebar)
1527 sevent.xconfigure.above = None;
1528 else
1529 sevent.xconfigure.above = wwin->frame->titlebar->window;
1531 sevent.xconfigure.override_redirect = False;
1532 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
1533 XFlush(dpy);
1538 *----------------------------------------------------------------------
1539 * wWindowConfigure--
1540 * Configures the frame, decorations and client window to the
1541 * specified geometry. The geometry is not checked for validity,
1542 * wWindowConstrainSize() must be used for that.
1543 * The size parameters are for the client window, but the position is
1544 * for the frame.
1545 * The client window receives a ConfigureNotify event, according
1546 * to what ICCCM says.
1548 * Returns:
1549 * None
1551 * Side effects:
1552 * Window size and position are changed and client window receives
1553 * a ConfigureNotify event.
1554 *----------------------------------------------------------------------
1556 void
1557 wWindowConfigure(wwin, req_x, req_y, req_width, req_height)
1558 WWindow *wwin;
1559 int req_x, req_y; /* new position of the frame */
1560 int req_width, req_height; /* new size of the client */
1562 int synth_notify = False;
1563 int resize;
1565 resize = (req_width!=wwin->client.width
1566 || req_height!=wwin->client.height);
1568 * if the window is being moved but not resized then
1569 * send a synthetic ConfigureNotify
1571 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y) && !resize) {
1572 synth_notify = True;
1575 if (wwin->window_flags.dont_move_off)
1576 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
1577 req_width, req_height);
1578 if (resize) {
1579 if (req_width < MIN_WINDOW_SIZE)
1580 req_width = MIN_WINDOW_SIZE;
1581 if (req_height < MIN_WINDOW_SIZE)
1582 req_height = MIN_WINDOW_SIZE;
1584 /* If growing, resize inner part before frame,
1585 * if shrinking, resize frame before.
1586 * This will prevent the frame (that can have a different color)
1587 * to be exposed, causing flicker */
1588 if (req_height > wwin->frame->core->height
1589 || req_width > wwin->frame->core->width)
1590 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
1592 if (wwin->flags.shaded) {
1593 wFrameWindowResize(wwin->frame, req_width, wwin->frame->core->height);
1594 wwin->old_geometry.height = req_height;
1595 } else {
1596 wFrameWindowResizeInternal(wwin->frame, req_width, req_height);
1599 if (!(req_height > wwin->frame->core->height
1600 || req_width > wwin->frame->core->width))
1601 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
1603 wwin->client.x = req_x;
1604 wwin->client.y = req_y + wwin->frame->top_width;
1605 wwin->client.width = req_width;
1606 wwin->client.height = req_height;
1608 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
1609 } else {
1610 wwin->client.x = req_x;
1611 wwin->client.y = req_y + wwin->frame->top_width;
1613 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
1615 wwin->frame_x = req_x;
1616 wwin->frame_y = req_y;
1618 #ifdef SHAPE
1619 if (wShapeSupported && wwin->flags.shaped && resize) {
1620 wWindowSetShape(wwin);
1622 #endif
1624 if (synth_notify)
1625 wWindowSynthConfigureNotify(wwin);
1626 XFlush(dpy);
1630 void
1631 wWindowMove(wwin, req_x, req_y)
1632 WWindow *wwin;
1633 int req_x, req_y; /* new position of the frame */
1635 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1636 int synth_notify = False;
1638 /* Send a synthetic ConfigureNotify event for every window movement. */
1639 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y)) {
1640 synth_notify = True;
1642 #else
1643 /* A single synthetic ConfigureNotify event is sent at the end of
1644 * a completed (opaque) movement in moveres.c */
1645 #endif
1647 if (wwin->window_flags.dont_move_off)
1648 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
1649 wwin->frame->core->width, wwin->frame->core->height);
1651 wwin->client.x = req_x;
1652 wwin->client.y = req_y + wwin->frame->top_width;
1654 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
1656 wwin->frame_x = req_x;
1657 wwin->frame_y = req_y;
1659 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1660 if (synth_notify)
1661 wWindowSynthConfigureNotify(wwin);
1662 #endif
1666 void
1667 wWindowUpdateButtonImages(WWindow *wwin)
1669 WScreen *scr = wwin->screen_ptr;
1670 Pixmap pixmap, mask;
1671 WFrameWindow *fwin = wwin->frame;
1673 if (wwin->window_flags.no_titlebar)
1674 return;
1676 /* miniaturize button */
1678 if (!wwin->window_flags.no_miniaturize_button) {
1679 if (wwin->wm_gnustep_attr
1680 && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
1681 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
1683 if (wwin->wm_gnustep_attr->flags&GSMiniaturizeMaskAttr) {
1684 mask = wwin->wm_gnustep_attr->miniaturize_mask;
1685 } else {
1686 mask = None;
1689 if (fwin->lbutton_image
1690 && (fwin->lbutton_image->image != pixmap
1691 || fwin->lbutton_image->mask != mask)) {
1692 wPixmapDestroy(fwin->lbutton_image);
1693 fwin->lbutton_image = NULL;
1696 if (!fwin->lbutton_image) {
1697 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
1698 fwin->lbutton_image->client_owned = 1;
1699 fwin->lbutton_image->client_owned_mask = 1;
1701 } else {
1702 if (fwin->lbutton_image && !fwin->lbutton_image->shared) {
1703 wPixmapDestroy(fwin->lbutton_image);
1705 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
1709 /* close button */
1711 if (!wwin->window_flags.no_close_button) {
1712 if (wwin->wm_gnustep_attr
1713 && wwin->wm_gnustep_attr->flags&GSClosePixmapAttr) {
1714 pixmap = wwin->wm_gnustep_attr->close_pixmap;
1716 if (wwin->wm_gnustep_attr->flags&GSCloseMaskAttr) {
1717 mask = wwin->wm_gnustep_attr->close_mask;
1718 } else {
1719 mask = None;
1722 if (fwin->rbutton_image
1723 && (fwin->rbutton_image->image != pixmap
1724 || fwin->rbutton_image->mask != mask)) {
1725 wPixmapDestroy(fwin->rbutton_image);
1726 fwin->rbutton_image = NULL;
1729 if (!fwin->rbutton_image) {
1730 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
1731 fwin->rbutton_image->client_owned = 1;
1732 fwin->rbutton_image->client_owned_mask = 1;
1734 } else if (wwin->window_flags.kill_close) {
1735 if (fwin->rbutton_image && !fwin->rbutton_image->shared) {
1736 wPixmapDestroy(fwin->rbutton_image);
1738 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
1739 } else if (wwin->window_flags.broken_close) {
1740 if (fwin->rbutton_image && !fwin->rbutton_image->shared) {
1741 wPixmapDestroy(fwin->rbutton_image);
1743 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
1744 } else {
1745 if (fwin->rbutton_image && !fwin->rbutton_image->shared) {
1746 wPixmapDestroy(fwin->rbutton_image);
1748 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
1752 /* force buttons to be redrawn */
1753 fwin->flags.need_texture_change = 1;
1754 wFrameWindowPaint(fwin);
1759 *---------------------------------------------------------------------------
1760 * wWindowConfigureBorders--
1761 * Update window border configuration according to window_flags
1763 *---------------------------------------------------------------------------
1765 void
1766 wWindowConfigureBorders(WWindow *wwin)
1768 if (wwin->frame) {
1769 int flags;
1770 int newy, oldh;
1772 flags = WFF_LEFT_BUTTON|WFF_RIGHT_BUTTON;
1773 if (!wwin->window_flags.no_titlebar)
1774 flags |= WFF_TITLEBAR;
1775 if (!wwin->window_flags.no_resizebar)
1776 flags |= WFF_RESIZEBAR;
1778 oldh = wwin->frame->top_width;
1779 wFrameWindowUpdateBorders(wwin->frame, flags);
1780 if (oldh != wwin->frame->top_width) {
1781 newy = wwin->frame_y + oldh - wwin->frame->top_width;
1783 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1784 wWindowConfigure(wwin, wwin->frame_x, newy,
1785 wwin->client.width, wwin->client.height);
1788 flags = 0;
1789 if (!wwin->window_flags.no_miniaturize_button
1790 && wwin->frame->flags.hide_left_button)
1791 flags |= WFF_LEFT_BUTTON;
1793 if (!wwin->window_flags.no_close_button
1794 && wwin->frame->flags.hide_right_button)
1795 flags |= WFF_RIGHT_BUTTON;
1797 if (flags!=0) {
1798 wWindowUpdateButtonImages(wwin);
1799 wFrameWindowShowButton(wwin->frame, flags);
1802 flags = 0;
1803 if (wwin->window_flags.no_miniaturize_button
1804 && !wwin->frame->flags.hide_left_button)
1805 flags |= WFF_LEFT_BUTTON;
1807 if (wwin->window_flags.no_close_button
1808 && !wwin->frame->flags.hide_right_button)
1809 flags |= WFF_RIGHT_BUTTON;
1811 if (flags!=0)
1812 wFrameWindowHideButton(wwin->frame, flags);
1814 #ifdef SHAPE
1815 if (wShapeSupported && wwin->flags.shaped) {
1816 wWindowSetShape(wwin);
1818 #endif
1823 void
1824 wWindowSaveState(WWindow *wwin)
1826 CARD32 data[9];
1828 memset(data, 0, sizeof(CARD32)*9);
1829 data[0] = wwin->frame->workspace;
1830 data[2] = wwin->flags.shaded;
1831 data[3] = wwin->flags.hidden;
1833 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
1834 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
1835 (unsigned char *)data, 9);
1839 static int
1840 getSavedState(Window window, WSavedState **state)
1842 Atom type_ret;
1843 int fmt_ret;
1844 unsigned long nitems_ret;
1845 unsigned long bytes_after_ret;
1846 CARD32 *data;
1848 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 9,
1849 True, _XA_WINDOWMAKER_STATE,
1850 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
1851 (unsigned char **)&data)!=Success || !data)
1852 return 0;
1854 *state = malloc(sizeof(WSavedState));
1856 if (*state) {
1857 (*state)->workspace = data[0];
1858 (*state)->miniaturized = data[1];
1859 (*state)->shaded = data[2];
1860 (*state)->hidden = data[3];
1861 (*state)->use_geometry = data[4];
1862 (*state)->x = data[5];
1863 (*state)->y = data[6];
1864 (*state)->w = data[7];
1865 (*state)->h = data[8];
1867 XFree(data);
1869 if (*state && type_ret==_XA_WINDOWMAKER_STATE)
1870 return 1;
1871 else
1872 return 0;
1876 #ifdef SHAPE
1877 void
1878 wWindowClearShape(WWindow *wwin)
1880 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
1881 0, wwin->frame->top_width, None, ShapeSet);
1882 XFlush(dpy);
1885 void
1886 wWindowSetShape(WWindow *wwin)
1888 XRectangle rect[2];
1889 int count;
1890 #ifdef OPTIMIZE_SHAPE
1891 XRectangle *rects;
1892 XRectangle *urec;
1893 int ordering;
1895 /* only shape is the client's */
1896 if (wwin->window_flags.no_titlebar && wwin->window_flags.no_resizebar) {
1897 goto alt_code;
1900 /* Get array of rectangles describing the shape mask */
1901 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding,
1902 &count, &ordering);
1903 if (!rects) {
1904 goto alt_code;
1907 urec = malloc(sizeof(XRectangle)*(count+2));
1908 if (!urec) {
1909 XFree(rects);
1910 goto alt_code;
1913 /* insert our decoration rectangles in the rect list */
1914 memcpy(urec, rects, sizeof(XRectangle)*count);
1915 XFree(rects);
1917 if (!wwin->window_flags.no_titlebar) {
1918 urec[count].x = -1;
1919 urec[count].y = -1 - wwin->frame->top_width;
1920 urec[count].width = wwin->frame->core->width + 2;
1921 urec[count].height = wwin->frame->top_width + 1;
1922 count++;
1924 if (!wwin->window_flags.no_resizebar) {
1925 urec[count].x = -1;
1926 urec[count].y = wwin->frame->core->height
1927 - wwin->frame->bottom_width - wwin->frame->top_width;
1928 urec[count].width = wwin->frame->core->width + 2;
1929 urec[count].height = wwin->frame->bottom_width + 1;
1930 count++;
1933 /* shape our frame window */
1934 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
1935 0, wwin->frame->top_width, urec, count,
1936 ShapeSet, Unsorted);
1937 XFlush(dpy);
1938 free(urec);
1939 return;
1941 alt_code:
1942 #endif /* OPTIMIZE_SHAPE */
1943 count = 0;
1944 if (!wwin->window_flags.no_titlebar) {
1945 rect[count].x = -1;
1946 rect[count].y = -1;
1947 rect[count].width = wwin->frame->core->width + 2;
1948 rect[count].height = wwin->frame->top_width + 1;
1949 count++;
1951 if (!wwin->window_flags.no_resizebar) {
1952 rect[count].x = -1;
1953 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
1954 rect[count].width = wwin->frame->core->width + 2;
1955 rect[count].height = wwin->frame->bottom_width + 1;
1956 count++;
1958 if (count > 0) {
1959 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
1960 0, 0, rect, count, ShapeSet, Unsorted);
1962 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
1963 0, wwin->frame->top_width, wwin->client_win,
1964 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
1965 XFlush(dpy);
1967 #endif /* SHAPE */
1969 /* ====================================================================== */
1971 static FocusMode
1972 getFocusMode(WWindow *wwin)
1974 FocusMode mode;
1976 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
1977 if (wwin->wm_hints->input == True) {
1978 if (wwin->protocols.TAKE_FOCUS)
1979 mode = WFM_LOCALLY_ACTIVE;
1980 else
1981 mode = WFM_PASSIVE;
1982 } else {
1983 if (wwin->protocols.TAKE_FOCUS)
1984 mode = WFM_GLOBALLY_ACTIVE;
1985 else
1986 mode = WFM_NO_INPUT;
1988 } else {
1989 mode = WFM_PASSIVE;
1991 return mode;
1995 void
1996 wWindowSetKeyGrabs(WWindow *wwin)
1998 int i;
1999 WShortKey *key;
2001 for (i=0; i<WKBD_LAST; i++) {
2002 key = &wKeyBindings[i];
2004 if (key->keycode==0)
2005 continue;
2006 if (key->modifier!=AnyModifier) {
2007 XGrabKey(dpy, key->keycode, key->modifier|LockMask,
2008 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2009 #ifdef NUMLOCK_HACK
2010 /* Also grab all modifier combinations possible that include,
2011 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2012 * work even if the NumLock/ScrollLock key is on.
2014 wHackedGrabKey(key->keycode, key->modifier,
2015 wwin->frame->core->window, True, GrabModeAsync,
2016 GrabModeAsync);
2017 #endif
2019 XGrabKey(dpy, key->keycode, key->modifier,
2020 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2023 wRootMenuBindShortcuts(wwin->frame->core->window);
2028 void
2029 wWindowResetMouseGrabs(WWindow *wwin)
2031 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2033 if (!wwin->window_flags.no_bind_mouse) {
2034 /* grabs for Meta+drag */
2035 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2036 True, ButtonPressMask, GrabModeSync,
2037 GrabModeAsync, None, wCursor[WCUR_ARROW]);
2040 if (!wwin->flags.focused) {
2041 /* the passive grabs to focus the window */
2042 if (wPreferences.focus_mode == WKF_CLICK)
2043 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2044 True, ButtonPressMask, GrabModeSync, GrabModeAsync,
2045 None, None);
2047 XFlush(dpy);
2051 void
2052 wWindowUpdateGNUstepAttr(WWindow *wwin, GNUstepWMAttributes *attr)
2055 if (attr->flags & GSExtraFlagsAttr) {
2056 if (wwin->window_flags.broken_close !=
2057 (attr->extra_flags & GSDocumentEditedFlag)) {
2058 wwin->window_flags.broken_close = !wwin->window_flags.broken_close;
2060 wWindowUpdateButtonImages(wwin);
2067 WMagicNumber
2068 wWindowAddSavedState(char *instance, char *class, char *command,
2069 pid_t pid, WSavedState *state)
2071 WWindowState *wstate;
2073 wstate = malloc(sizeof(WWindowState));
2074 if (!wstate)
2075 return 0;
2077 memset(wstate, 0, sizeof(WWindowState));
2078 wstate->pid = pid;
2079 if (instance)
2080 wstate->instance = wstrdup(instance);
2081 if (class)
2082 wstate->class = wstrdup(class);
2083 if (command)
2084 wstate->command = wstrdup(command);
2085 wstate->state = state;
2087 wstate->next = windowState;
2088 windowState = wstate;
2090 #ifdef DEBUG
2091 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2092 class, command);
2093 #endif
2095 return wstate;
2099 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2102 WMagicNumber
2103 wWindowGetSavedState(Window win)
2105 char *instance, *class, *command=NULL;
2106 WWindowState *wstate = windowState;
2107 char **argv;
2108 int argc;
2110 if (!wstate)
2111 return NULL;
2113 if (XGetCommand(dpy, win, &argv, &argc)) {
2114 if (argc > 0)
2115 command = FlattenStringList(argv, argc);
2116 XFreeStringList(argv);
2118 if (!command)
2119 return NULL;
2121 if (PropGetWMClass(win, &class, &instance)) {
2122 while (wstate) {
2123 if (SAME(instance, wstate->instance) &&
2124 SAME(class, wstate->class) &&
2125 SAME(command, wstate->command)) {
2126 break;
2128 wstate = wstate->next;
2130 } else {
2131 wstate = NULL;
2134 #ifdef DEBUG
2135 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2136 class, command);
2137 #endif
2139 if (command) free(command);
2140 if (instance) XFree(instance);
2141 if (class) XFree(class);
2143 return wstate;
2147 void
2148 wWindowDeleteSavedState(WMagicNumber id)
2150 WWindowState *tmp, *wstate=(WWindowState*)id;
2152 if (!wstate || !windowState)
2153 return;
2155 tmp = windowState;
2156 if (tmp==wstate) {
2157 windowState = wstate->next;
2158 #ifdef DEBUG
2159 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2160 wstate, wstate->instance, wstate->class, wstate->command);
2161 #endif
2162 if (wstate->instance) free(wstate->instance);
2163 if (wstate->class) free(wstate->class);
2164 if (wstate->command) free(wstate->command);
2165 free(wstate->state);
2166 free(wstate);
2167 } else {
2168 while (tmp->next) {
2169 if (tmp->next==wstate) {
2170 tmp->next=wstate->next;
2171 #ifdef DEBUG
2172 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2173 wstate, wstate->instance, wstate->class, wstate->command);
2174 #endif
2175 if (wstate->instance) free(wstate->instance);
2176 if (wstate->class) free(wstate->class);
2177 if (wstate->command) free(wstate->command);
2178 free(wstate->state);
2179 free(wstate);
2180 break;
2182 tmp = tmp->next;
2188 void
2189 wWindowDeleteSavedStatesForPID(pid_t pid)
2191 WWindowState *tmp, *wstate;
2193 if (!windowState)
2194 return;
2196 tmp = windowState;
2197 if (tmp->pid == pid) {
2198 wstate = windowState;
2199 windowState = tmp->next;
2200 #ifdef DEBUG
2201 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2202 wstate, wstate->instance, wstate->class, wstate->command);
2203 #endif
2204 if (wstate->instance) free(wstate->instance);
2205 if (wstate->class) free(wstate->class);
2206 if (wstate->command) free(wstate->command);
2207 free(wstate->state);
2208 free(wstate);
2209 } else {
2210 while (tmp->next) {
2211 if (tmp->next->pid==pid) {
2212 wstate = tmp->next;
2213 tmp->next = wstate->next;
2214 #ifdef DEBUG
2215 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2216 wstate, wstate->instance, wstate->class, wstate->command);
2217 #endif
2218 if (wstate->instance) free(wstate->instance);
2219 if (wstate->class) free(wstate->class);
2220 if (wstate->command) free(wstate->command);
2221 free(wstate->state);
2222 free(wstate);
2223 break;
2225 tmp = tmp->next;
2231 /* ====================================================================== */
2233 static void
2234 resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2236 WWindow *wwin = data;
2238 #ifndef NUMLOCK_HACK
2239 if ((event->xbutton.state & ValidModMask)
2240 != (event->xbutton.state & ~LockMask)) {
2241 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2242 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2244 #endif
2246 event->xbutton.state &= ValidModMask;
2248 CloseWindowMenu(wwin->screen_ptr);
2250 if (wPreferences.focus_mode==WKF_CLICK
2251 && !(event->xbutton.state&ControlMask)) {
2252 wSetFocusTo(wwin->screen_ptr, wwin);
2255 if (event->xbutton.button == Button1)
2256 wRaiseFrame(wwin->frame->core);
2258 if (event->xbutton.state & MOD_MASK) {
2259 /* move the window */
2260 #if 0
2261 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
2262 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2263 GrabModeAsync, GrabModeAsync, None,
2264 None, CurrentTime)!=GrabSuccess) {
2265 #ifdef DEBUG0
2266 wwarning("pointer grab failed for window move");
2267 #endif
2268 return;
2270 #endif
2271 wMouseMoveWindow(wwin, event);
2272 XUngrabPointer(dpy, CurrentTime);
2273 } else {
2274 #if 0
2275 /* resize the window */
2276 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
2277 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2278 GrabModeAsync, GrabModeAsync, None,
2279 None, CurrentTime)!=GrabSuccess) {
2280 #ifdef DEBUG0
2281 wwarning("pointer grab failed for window resize");
2282 #endif
2283 return;
2285 #endif
2286 wMouseResizeWindow(wwin, event);
2287 XUngrabPointer(dpy, CurrentTime);
2293 static void
2294 titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
2296 WWindow *wwin = data;
2298 event->xbutton.state &= ValidModMask;
2300 if (event->xbutton.button==Button1) {
2301 if (event->xbutton.state == 0) {
2302 if (!wwin->window_flags.no_shadeable) {
2303 /* shade window */
2304 if (wwin->flags.shaded)
2305 wUnshadeWindow(wwin);
2306 else
2307 wShadeWindow(wwin);
2309 } else {
2310 int dir = 0;
2312 if (event->xbutton.state & ControlMask)
2313 dir |= MAX_VERTICAL;
2315 if (event->xbutton.state & ShiftMask) {
2316 dir |= MAX_HORIZONTAL;
2317 if (!(event->xbutton.state & ControlMask))
2318 wSelectWindow(wwin, !wwin->flags.selected);
2321 /* maximize window */
2322 if (dir !=0 && !wwin->window_flags.no_resizable) {
2323 if (wwin->flags.maximized)
2324 wUnmaximizeWindow(wwin);
2325 else
2326 wMaximizeWindow(wwin, dir);
2329 } else if (event->xbutton.button==Button3) {
2330 if (event->xbutton.state & MOD_MASK) {
2331 wHideOtherApplications(wwin);
2333 } else if (event->xbutton.button==Button2) {
2334 wSelectWindow(wwin, !wwin->flags.selected);
2339 static void
2340 frameMouseDown(WObjDescriptor *desc, XEvent *event)
2342 WWindow *wwin = desc->parent;
2344 event->xbutton.state &= ValidModMask;
2346 CloseWindowMenu(wwin->screen_ptr);
2348 if (wPreferences.focus_mode==WKF_CLICK
2349 && !(event->xbutton.state&ControlMask)) {
2350 wSetFocusTo(wwin->screen_ptr, wwin);
2352 if (event->xbutton.button == Button1) {
2353 wRaiseFrame(wwin->frame->core);
2356 if (event->xbutton.state & MOD_MASK) {
2357 /* move the window */
2358 if (XGrabPointer(dpy, wwin->client_win, False,
2359 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2360 GrabModeAsync, GrabModeAsync, None,
2361 None, CurrentTime)!=GrabSuccess) {
2362 #ifdef DEBUG0
2363 wwarning("pointer grab failed for window move");
2364 #endif
2365 return;
2367 if (event->xbutton.button == Button3 && !wwin->window_flags.no_resizable)
2368 wMouseResizeWindow(wwin, event);
2369 else
2370 wMouseMoveWindow(wwin, event);
2371 XUngrabPointer(dpy, CurrentTime);
2376 static void
2377 titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2379 WWindow *wwin = (WWindow*)data;
2381 #ifndef NUMLOCK_HACK
2382 if ((event->xbutton.state & ValidModMask)
2383 != (event->xbutton.state & ~LockMask)) {
2384 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2385 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2387 #endif
2389 event->xbutton.state &= ValidModMask;
2392 CloseWindowMenu(wwin->screen_ptr);
2394 if (wPreferences.focus_mode==WKF_CLICK
2395 && !(event->xbutton.state&ControlMask)) {
2396 wSetFocusTo(wwin->screen_ptr, wwin);
2399 if (event->xbutton.button == Button1
2400 || event->xbutton.button == Button2) {
2402 if (event->xbutton.button == Button1) {
2403 if (event->xbutton.state & MOD_MASK) {
2404 wLowerFrame(wwin->frame->core);
2405 } else {
2406 wRaiseFrame(wwin->frame->core);
2409 if ((event->xbutton.state & ShiftMask)
2410 && !(event->xbutton.state & ControlMask)) {
2411 wSelectWindow(wwin, !wwin->flags.selected);
2412 return;
2414 /* move the window */
2415 wMouseMoveWindow(wwin, event);
2416 XUngrabPointer(dpy, CurrentTime);
2417 } else if (event->xbutton.button == Button3 && event->xbutton.state==0
2418 && !wwin->flags.internal_window) {
2419 WObjDescriptor *desc;
2421 OpenWindowMenu(wwin, event->xbutton.x_root,
2422 wwin->frame_y+wwin->frame->top_width, False);
2424 /* allow drag select */
2425 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
2426 event->xany.send_event = True;
2427 (*desc->handle_mousedown)(desc, event);
2433 static void
2434 windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
2436 WWindow *wwin = data;
2438 event->xbutton.state &= ValidModMask;
2440 CloseWindowMenu(wwin->screen_ptr);
2442 /* if control-click, kill the client */
2443 if (event->xbutton.state & ControlMask) {
2444 wClientKill(wwin);
2445 } else if (wwin->protocols.DELETE_WINDOW && event->xbutton.state==0) {
2446 /* send delete message */
2447 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
2452 static void
2453 windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
2455 WWindow *wwin = data;
2457 CloseWindowMenu(wwin->screen_ptr);
2459 /* send delete message */
2460 if (wwin->protocols.DELETE_WINDOW) {
2461 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
2462 } else {
2463 wClientKill(wwin);
2468 static void
2469 windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
2471 WWindow *wwin = data;
2473 event->xbutton.state &= ValidModMask;
2475 CloseWindowMenu(wwin->screen_ptr);
2477 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state==0) {
2478 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
2479 LastTimestamp);
2480 } else {
2481 WApplication *wapp;
2482 if ((event->xbutton.state & ControlMask) ||
2483 (event->xbutton.button == Button3)) {
2485 wapp = wApplicationOf(wwin->main_window);
2486 if (wapp && !wwin->window_flags.no_appicon)
2487 wHideApplication(wapp);
2488 } else if (event->xbutton.state==0) {
2489 wIconifyWindow(wwin);