1 /* winmenu.c - command menu for windows
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include <X11/Xutil.h>
31 #include <X11/XKBlib.h>
33 #include "WindowMaker.h"
39 #include "application.h"
43 #include "workspace.h"
44 #include "winspector.h"
52 static WMenu
*makeWorkspaceMenu(WScreen
*scr
);
53 static WMenu
*makeOptionsMenu(WScreen
*scr
);
54 static WMenu
*makeMaximizeMenu(WScreen
*scr
);
57 * Define the Menu entry that will be present in the Window menu
59 * The order of this list defines the order in which they will appear;
60 * make sure to keep the structure below aligned with the list because
61 * the constant index is used in many places.
82 WMenu
*(*generate_submenu
)(WScreen
*scr
);
83 } window_menu_entries
[] = {
84 [MC_MAXIMIZE
] = { N_("Maximize"), NULL
},
85 [MC_OTHERMAX
] = { N_("Other maximization"), makeMaximizeMenu
},
86 [MC_MINIATURIZE
] = { N_("Miniaturize"), NULL
},
87 [MC_SHADE
] = { N_("Shade"), NULL
},
88 [MC_HIDE
] = { N_("Hide"), NULL
},
89 [MC_MOVERESIZE
] = { N_("Resize/Move"), NULL
},
90 [MC_SELECT
] = { N_("Select"), NULL
},
91 [MC_CHANGEWKSPC
] = { N_("Move To"), makeWorkspaceMenu
},
92 [MC_PROPERTIES
] = { N_("Attributes..."), NULL
},
93 [MC_OPTIONS
] = { N_("Options"), makeOptionsMenu
},
94 [MC_RELAUNCH
] = { N_("Launch"), NULL
},
95 [MC_CLOSE
] = { N_("Close"), NULL
},
96 [MC_KILL
] = { N_("Kill"), NULL
}
100 * Defines the menu entries for the Options sub-menu
102 * These options will be placed at the beginning of the menu, the rest will
103 * be populated with the Window Shortcut possibilities
112 static const char *const menu_options_entries
[] = {
113 [WO_KEEP_ON_TOP
] = N_("Keep on top"),
114 [WO_KEEP_AT_BOTTOM
] = N_("Keep at bottom"),
115 [WO_OMNIPRESENT
] = N_("Omnipresent")
119 * Defines the menu entries for the Other maximization sub-menu
121 static const struct {
123 unsigned int shortcut_idx
;
125 } menu_maximize_entries
[] = {
126 { N_("Maximize vertically"), WKBD_VMAXIMIZE
, MAX_VERTICAL
},
127 { N_("Maximize horizontally"), WKBD_HMAXIMIZE
, MAX_HORIZONTAL
},
128 { N_("Maximize left half"), WKBD_LHMAXIMIZE
, MAX_VERTICAL
| MAX_LEFTHALF
},
129 { N_("Maximize right half"), WKBD_RHMAXIMIZE
, MAX_VERTICAL
| MAX_RIGHTHALF
},
130 { N_("Maximize top half"), WKBD_THMAXIMIZE
, MAX_HORIZONTAL
| MAX_TOPHALF
},
131 { N_("Maximize bottom half"), WKBD_BHMAXIMIZE
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
},
132 { N_("Maximize left top corner"), WKBD_LTCMAXIMIZE
, MAX_LEFTHALF
| MAX_TOPHALF
},
133 { N_("Maximize right top corner"), WKBD_RTCMAXIMIZE
, MAX_RIGHTHALF
| MAX_TOPHALF
},
134 { N_("Maximize left bottom corner"), WKBD_LBCMAXIMIZE
, MAX_LEFTHALF
| MAX_BOTTOMHALF
},
135 { N_("Maximize right bottom corner"), WKBD_RBCMAXIMIZE
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
},
136 { N_("Maximus: tiled maximization"), WKBD_MAXIMUS
, MAX_MAXIMUS
}
139 static void updateOptionsMenu(WMenu
* menu
, WWindow
* wwin
);
141 static void execWindowOptionCommand(WMenu
* menu
, WMenuEntry
* entry
)
143 WWindow
*wwin
= (WWindow
*) entry
->clientdata
;
145 /* Parameter not used, but tell the compiler that it is ok */
148 switch (entry
->order
) {
150 if (wwin
->frame
->core
->stacking
->window_level
!= WMFloatingLevel
)
151 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
153 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
156 case WO_KEEP_AT_BOTTOM
:
157 if (wwin
->frame
->core
->stacking
->window_level
!= WMSunkenLevel
)
158 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
160 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
164 wWindowSetOmnipresent(wwin
, !wwin
->flags
.omnipresent
);
169 static void execMaximizeCommand(WMenu
* menu
, WMenuEntry
* entry
)
171 WWindow
*wwin
= (WWindow
*) entry
->clientdata
;
173 /* Parameter not used, but tell the compiler that it is ok */
176 handleMaximize(wwin
, menu_maximize_entries
[entry
->order
].maxim_direction
);
179 static void updateUnmaximizeShortcut(WMenuEntry
* entry
, int flags
)
183 switch (flags
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
)) {
185 key
= WKBD_HMAXIMIZE
;
189 key
= WKBD_VMAXIMIZE
;
192 case MAX_LEFTHALF
| MAX_VERTICAL
:
193 key
= WKBD_LHMAXIMIZE
;
196 case MAX_RIGHTHALF
| MAX_VERTICAL
:
197 key
= WKBD_RHMAXIMIZE
;
200 case MAX_TOPHALF
| MAX_HORIZONTAL
:
201 key
= WKBD_THMAXIMIZE
;
204 case MAX_BOTTOMHALF
| MAX_HORIZONTAL
:
205 key
= WKBD_BHMAXIMIZE
;
208 case MAX_LEFTHALF
| MAX_TOPHALF
:
209 key
= WKBD_LTCMAXIMIZE
;
212 case MAX_RIGHTHALF
| MAX_TOPHALF
:
213 key
= WKBD_RTCMAXIMIZE
;
216 case MAX_LEFTHALF
| MAX_BOTTOMHALF
:
217 key
= WKBD_LBCMAXIMIZE
;
220 case MAX_RIGHTHALF
| MAX_BOTTOMHALF
:
221 key
= WKBD_RBCMAXIMIZE
;
233 entry
->rtext
= GetShortcutKey(wKeyBindings
[key
]);
236 static void execMenuCommand(WMenu
* menu
, WMenuEntry
* entry
)
238 WWindow
*wwin
= (WWindow
*) entry
->clientdata
;
241 CloseWindowMenu(menu
->frame
->screen_ptr
);
243 switch (entry
->order
) {
245 /* send delete message */
246 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
247 w_global
.timestamp
.last_event
);
252 if (wPreferences
.dont_confirm_kill
253 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
255 ("This will kill the application.\nAny unsaved changes will be lost.\nPlease confirm."),
256 _("Yes"), _("No"), NULL
) == WAPRDefault
) {
257 if (!wwin
->flags
.destroyed
)
264 if (wwin
->flags
.miniaturized
) {
265 wDeiconifyWindow(wwin
);
267 if (wwin
->protocols
.MINIATURIZE_WINDOW
) {
268 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
,
269 w_global
.timestamp
.last_event
);
271 wIconifyWindow(wwin
);
277 if (wwin
->flags
.maximized
)
278 wUnmaximizeWindow(wwin
);
280 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
);
284 if (wwin
->flags
.shaded
)
285 wUnshadeWindow(wwin
);
291 if (!wwin
->flags
.miniaturized
)
292 wSelectWindow(wwin
, !wwin
->flags
.selected
);
294 wIconSelect(wwin
->icon
);
298 wKeyboardMoveResizeWindow(wwin
);
302 wShowInspectorForWindow(wwin
);
306 (void) RelaunchWindow(wwin
);
310 wapp
= wApplicationOf(wwin
->main_window
);
311 wHideApplication(wapp
);
316 static void switchWSCommand(WMenu
* menu
, WMenuEntry
* entry
)
318 WWindow
*wwin
= (WWindow
*) entry
->clientdata
;
320 /* Parameter not used, but tell the compiler that it is ok */
323 wSelectWindow(wwin
, False
);
324 wWindowChangeWorkspace(wwin
, entry
->order
);
327 static void makeShortcutCommand(WMenu
* menu
, WMenuEntry
* entry
)
329 WWindow
*wwin
= (WWindow
*) entry
->clientdata
;
330 WScreen
*scr
= wwin
->screen_ptr
;
331 int index
= entry
->order
- wlengthof(menu_options_entries
);
333 /* Parameter not used, but tell the compiler that it is ok */
336 if (scr
->shortcutWindows
[index
]) {
337 WMFreeArray(scr
->shortcutWindows
[index
]);
338 scr
->shortcutWindows
[index
] = NULL
;
341 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
342 scr
->shortcutWindows
[index
] = WMDuplicateArray(scr
->selected_windows
);
343 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
344 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
346 scr
->shortcutWindows
[index
] = WMCreateArray(4);
347 WMAddToArray(scr
->shortcutWindows
[index
], wwin
);
350 wSelectWindow(wwin
, !wwin
->flags
.selected
);
353 wSelectWindow(wwin
, !wwin
->flags
.selected
);
357 static void updateWorkspaceMenu(WMenu
* menu
)
359 WScreen
*scr
= menu
->frame
->screen_ptr
;
360 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
364 for (i
= 0; i
< scr
->workspace_count
; i
++) {
365 if (i
< menu
->entry_no
) {
367 entry
= menu
->entries
[i
];
368 if (strcmp(entry
->text
, scr
->workspaces
[i
]->name
) != 0) {
370 strncpy(title
, scr
->workspaces
[i
]->name
, MAX_WORKSPACENAME_WIDTH
);
371 title
[MAX_WORKSPACENAME_WIDTH
] = 0;
372 menu
->entries
[i
]->text
= wstrdup(title
);
373 menu
->entries
[i
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_MOVE_WORKSPACE1
+ i
]);
374 menu
->flags
.realized
= 0;
377 strncpy(title
, scr
->workspaces
[i
]->name
, MAX_WORKSPACENAME_WIDTH
);
378 title
[MAX_WORKSPACENAME_WIDTH
] = 0;
380 entry
= wMenuAddCallback(menu
, title
, switchWSCommand
, NULL
);
381 entry
->rtext
= GetShortcutKey(wKeyBindings
[WKBD_MOVE_WORKSPACE1
+ i
]);
383 menu
->flags
.realized
= 0;
386 /* workspace shortcut labels */
387 if (i
/ 10 == scr
->current_workspace
/ 10)
388 entry
->rtext
= GetShortcutKey(wKeyBindings
[WKBD_MOVE_WORKSPACE1
+ (i
% 10)]);
393 if (!menu
->flags
.realized
)
397 static void updateMakeShortcutMenu(WMenu
* menu
, WWindow
* wwin
)
399 WMenu
*smenu
= menu
->cascades
[menu
->entries
[MC_OPTIONS
]->cascade
];
408 buflen
= strlen(_("Set Shortcut")) + 16;
409 buffer
= wmalloc(buflen
);
411 for (i
= wlengthof(menu_options_entries
); i
< smenu
->entry_no
; i
++) {
412 int shortcutNo
= i
- wlengthof(menu_options_entries
);
413 WMenuEntry
*entry
= smenu
->entries
[i
];
414 WMArray
*shortSelWindows
= wwin
->screen_ptr
->shortcutWindows
[shortcutNo
];
416 snprintf(buffer
, buflen
, "%s %i", _("Set Shortcut"), shortcutNo
+ 1);
418 if (!shortSelWindows
) {
419 entry
->flags
.indicator_on
= 0;
421 entry
->flags
.indicator_on
= 1;
422 if (WMCountInArray(shortSelWindows
, wwin
))
423 entry
->flags
.indicator_type
= MI_DIAMOND
;
425 entry
->flags
.indicator_type
= MI_CHECK
;
428 if (strcmp(buffer
, entry
->text
) != 0) {
430 entry
->text
= wstrdup(buffer
);
431 smenu
->flags
.realized
= 0;
434 kcode
= wKeyBindings
[WKBD_WINDOW1
+ shortcutNo
].keycode
;
439 tmp
= GetShortcutKey(wKeyBindings
[WKBD_WINDOW1
+ shortcutNo
]);
441 if (entry
->rtext
!= NULL
) {
442 /* There was a shortcut, but there is no more */
445 smenu
->flags
.realized
= 0;
447 } else if (entry
->rtext
== NULL
) {
448 /* There was no shortcut, but there is one now */
450 smenu
->flags
.realized
= 0;
451 } else if (strcmp(tmp
, entry
->rtext
) != 0) {
452 /* There was a shortcut, but it has changed */
455 smenu
->flags
.realized
= 0;
457 /* There was a shortcut but it did not change */
460 wMenuSetEnabled(smenu
, i
, True
);
462 wMenuSetEnabled(smenu
, i
, False
);
466 smenu
->flags
.realized
= 0;
469 entry
->clientdata
= wwin
;
472 if (!smenu
->flags
.realized
)
476 static void updateOptionsMenu(WMenu
* menu
, WWindow
* wwin
)
478 WMenu
*smenu
= menu
->cascades
[menu
->entries
[MC_OPTIONS
]->cascade
];
480 /* keep on top check */
481 smenu
->entries
[WO_KEEP_ON_TOP
]->clientdata
= wwin
;
482 smenu
->entries
[WO_KEEP_ON_TOP
]->flags
.indicator_on
=
483 (wwin
->frame
->core
->stacking
->window_level
== WMFloatingLevel
) ? 1 : 0;
484 wMenuSetEnabled(smenu
, WO_KEEP_ON_TOP
, !wwin
->flags
.miniaturized
);
485 smenu
->entries
[WO_KEEP_ON_TOP
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_KEEP_ON_TOP
]);
487 /* keep at bottom check */
488 smenu
->entries
[WO_KEEP_AT_BOTTOM
]->clientdata
= wwin
;
489 smenu
->entries
[WO_KEEP_AT_BOTTOM
]->flags
.indicator_on
=
490 (wwin
->frame
->core
->stacking
->window_level
== WMSunkenLevel
) ? 1 : 0;
491 wMenuSetEnabled(smenu
, WO_KEEP_AT_BOTTOM
, !wwin
->flags
.miniaturized
);
492 smenu
->entries
[WO_KEEP_AT_BOTTOM
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_KEEP_AT_BOTTOM
]);
494 /* omnipresent check */
495 smenu
->entries
[WO_OMNIPRESENT
]->clientdata
= wwin
;
496 smenu
->entries
[WO_OMNIPRESENT
]->flags
.indicator_on
= IS_OMNIPRESENT(wwin
);
497 smenu
->entries
[WO_OMNIPRESENT
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_OMNIPRESENT
]);
499 smenu
->flags
.realized
= 0;
503 static void updateMaximizeMenu(WMenu
* menu
, WWindow
* wwin
)
505 WMenu
*smenu
= menu
->cascades
[menu
->entries
[MC_OTHERMAX
]->cascade
];
508 for (i
= 0; i
< smenu
->entry_no
; i
++) {
509 smenu
->entries
[i
]->clientdata
= wwin
;
510 smenu
->entries
[i
]->rtext
= GetShortcutKey(wKeyBindings
[menu_maximize_entries
[i
].shortcut_idx
]);
513 smenu
->flags
.realized
= 0;
517 static WMenu
*makeWorkspaceMenu(WScreen
* scr
)
521 menu
= wMenuCreate(scr
, NULL
, False
);
523 wwarning(_("could not create submenu for window menu"));
527 updateWorkspaceMenu(menu
);
530 * The Workspace Menu is made visible in the screen structure because
531 * it is updated when there is a change on workspaces. This was done
532 * to be efficient, avoiding re-generating completely the window menu
533 * and its sub-menus every time it is needed.
535 scr
->workspace_submenu
= menu
;
540 static WMenu
*makeOptionsMenu(WScreen
* scr
)
546 menu
= wMenuCreate(scr
, NULL
, False
);
548 wwarning(_("could not create submenu for window menu"));
552 for (i
= 0; i
< wlengthof(menu_options_entries
); i
++) {
553 entry
= wMenuAddCallback(menu
, _(menu_options_entries
[i
]), execWindowOptionCommand
, NULL
);
554 entry
->flags
.indicator
= 1;
555 entry
->flags
.indicator_type
= MI_CHECK
;
558 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
559 entry
= wMenuAddCallback(menu
, "", makeShortcutCommand
, NULL
);
560 entry
->flags
.indicator
= 1;
566 static WMenu
*makeMaximizeMenu(WScreen
* scr
)
571 menu
= wMenuCreate(scr
, NULL
, False
);
573 wwarning(_("could not create submenu for window menu"));
577 for (i
= 0; i
< wlengthof(menu_maximize_entries
); i
++)
578 wMenuAddCallback(menu
, _(menu_maximize_entries
[i
].label
), execMaximizeCommand
, NULL
);
583 static WMenu
*createWindowMenu(WScreen
* scr
)
588 menu
= wMenuCreate(scr
, NULL
, False
);
590 for (i
= 0; i
< wlengthof(window_menu_entries
); i
++) {
593 entry
= wMenuAddCallback(menu
, _(window_menu_entries
[i
].label
),
594 (window_menu_entries
[i
].generate_submenu
== NULL
)?execMenuCommand
:NULL
,
596 if (window_menu_entries
[i
].generate_submenu
!= NULL
) {
599 submenu
= window_menu_entries
[i
].generate_submenu(scr
);
600 wMenuEntrySetCascade(menu
, entry
, submenu
);
607 void CloseWindowMenu(WScreen
* scr
)
609 if (scr
->window_menu
) {
610 if (scr
->window_menu
->flags
.mapped
)
611 wMenuUnmap(scr
->window_menu
);
613 if (scr
->window_menu
->entries
[0]->clientdata
) {
614 WWindow
*wwin
= (WWindow
*) scr
->window_menu
->entries
[0]->clientdata
;
616 wwin
->flags
.menu_open_for_me
= 0;
618 scr
->window_menu
->entries
[0]->clientdata
= NULL
;
622 static void updateMenuForWindow(WMenu
* menu
, WWindow
* wwin
)
624 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
625 WScreen
*scr
= wwin
->screen_ptr
;
628 updateOptionsMenu(menu
, wwin
);
629 updateMaximizeMenu(menu
, wwin
);
631 updateMakeShortcutMenu(menu
, wwin
);
633 wMenuSetEnabled(menu
, MC_HIDE
, wapp
!= NULL
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
));
635 wMenuSetEnabled(menu
, MC_CLOSE
, (wwin
->protocols
.DELETE_WINDOW
&& !WFLAGP(wwin
, no_closable
)));
637 if (wwin
->flags
.miniaturized
) {
638 static char *text
= NULL
;
640 text
= _("Deminiaturize");
642 menu
->entries
[MC_MINIATURIZE
]->text
= text
;
644 static char *text
= NULL
;
646 text
= _("Miniaturize");
648 menu
->entries
[MC_MINIATURIZE
]->text
= text
;
651 wMenuSetEnabled(menu
, MC_MINIATURIZE
, !WFLAGP(wwin
, no_miniaturizable
));
653 if (wwin
->flags
.maximized
) {
654 static char *text
= NULL
;
656 text
= _("Unmaximize");
658 menu
->entries
[MC_MAXIMIZE
]->text
= text
;
659 updateUnmaximizeShortcut(menu
->entries
[MC_MAXIMIZE
], wwin
->flags
.maximized
);
661 static char *text
= NULL
;
663 text
= _("Maximize");
665 menu
->entries
[MC_MAXIMIZE
]->text
= text
;
666 menu
->entries
[MC_MAXIMIZE
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_MAXIMIZE
]);
668 wMenuSetEnabled(menu
, MC_MAXIMIZE
, IS_RESIZABLE(wwin
));
670 wMenuSetEnabled(menu
, MC_MOVERESIZE
, IS_RESIZABLE(wwin
)
671 && !wwin
->flags
.miniaturized
);
673 if (wwin
->flags
.shaded
) {
674 static char *text
= NULL
;
678 menu
->entries
[MC_SHADE
]->text
= text
;
680 static char *text
= NULL
;
684 menu
->entries
[MC_SHADE
]->text
= text
;
687 wMenuSetEnabled(menu
, MC_SHADE
, !WFLAGP(wwin
, no_shadeable
)
688 && !wwin
->flags
.miniaturized
);
690 if (wwin
->flags
.selected
) {
691 static char *text
= NULL
;
693 text
= _("Deselect");
695 menu
->entries
[MC_SELECT
]->text
= text
;
697 static char *text
= NULL
;
701 menu
->entries
[MC_SELECT
]->text
= text
;
704 wMenuSetEnabled(menu
, MC_CHANGEWKSPC
, !IS_OMNIPRESENT(wwin
));
706 if (!wwin
->flags
.inspector_open
) {
707 wMenuSetEnabled(menu
, MC_PROPERTIES
, True
);
709 wMenuSetEnabled(menu
, MC_PROPERTIES
, False
);
712 /* Update shortcut labels except for (Un)Maximize which is
713 * handled separately.
715 menu
->entries
[MC_MINIATURIZE
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_MINIATURIZE
]);
716 menu
->entries
[MC_SHADE
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_SHADE
]);
717 menu
->entries
[MC_HIDE
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_HIDE
]);
718 menu
->entries
[MC_MOVERESIZE
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_MOVERESIZE
]);
719 menu
->entries
[MC_SELECT
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_SELECT
]);
720 menu
->entries
[MC_RELAUNCH
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_RELAUNCH
]);
721 menu
->entries
[MC_CLOSE
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_CLOSE
]);
723 /* set the client data of the entries to the window */
724 for (i
= 0; i
< menu
->entry_no
; i
++) {
725 menu
->entries
[i
]->clientdata
= wwin
;
728 for (i
= 0; i
< scr
->workspace_submenu
->entry_no
; i
++) {
729 scr
->workspace_submenu
->entries
[i
]->clientdata
= wwin
;
730 if (i
== scr
->current_workspace
)
731 wMenuSetEnabled(scr
->workspace_submenu
, i
, False
);
733 wMenuSetEnabled(scr
->workspace_submenu
, i
, True
);
736 menu
->flags
.realized
= 0;
740 static WMenu
*open_window_menu_core(WWindow
*wwin
)
742 WScreen
*scr
= wwin
->screen_ptr
;
745 wwin
->flags
.menu_open_for_me
= 1;
747 if (!scr
->window_menu
) {
748 scr
->window_menu
= createWindowMenu(scr
);
750 /* hack to save some memory allocation/deallocation */
751 wfree(scr
->window_menu
->entries
[MC_MINIATURIZE
]->text
);
752 wfree(scr
->window_menu
->entries
[MC_MAXIMIZE
]->text
);
753 wfree(scr
->window_menu
->entries
[MC_SHADE
]->text
);
754 wfree(scr
->window_menu
->entries
[MC_SELECT
]->text
);
756 updateWorkspaceMenu(scr
->workspace_submenu
);
759 menu
= scr
->window_menu
;
760 if (menu
->flags
.mapped
) {
762 if (menu
->entries
[0]->clientdata
== wwin
)
766 updateMenuForWindow(menu
, wwin
);
771 static void prepare_menu_position(WMenu
*menu
, int *x
, int *y
)
775 rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
776 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
777 if (*x
< rect
.pos
.x
- menu
->frame
->core
->width
/ 2)
778 *x
= rect
.pos
.x
- menu
->frame
->core
->width
/ 2;
783 void OpenWindowMenu(WWindow
*wwin
, int x
, int y
, int keyboard
)
787 menu
= open_window_menu_core(wwin
);
791 /* Specific menu position */
792 x
-= menu
->frame
->core
->width
/ 2;
793 if (x
+ menu
->frame
->core
->width
> wwin
->frame_x
+ wwin
->frame
->core
->width
)
794 x
= wwin
->frame_x
+ wwin
->frame
->core
->width
- menu
->frame
->core
->width
;
795 if (x
< wwin
->frame_x
)
798 /* Common menu position */
799 prepare_menu_position(menu
, &x
, &y
);
801 if (!wwin
->flags
.internal_window
)
802 wMenuMapAt(menu
, x
, y
, keyboard
);
805 void OpenWindowMenu2(WWindow
*wwin
, int x
, int y
, int keyboard
)
809 WScreen
*scr
= wwin
->screen_ptr
;
811 menu
= open_window_menu_core(wwin
);
815 /* Specific menu position */
816 for (i
= 0; i
< scr
->workspace_submenu
->entry_no
; i
++) {
817 scr
->workspace_submenu
->entries
[i
]->clientdata
= wwin
;
818 wMenuSetEnabled(scr
->workspace_submenu
, i
, True
);
821 x
-= menu
->frame
->core
->width
/ 2;
823 /* Common menu position */
824 prepare_menu_position(menu
, &x
, &y
);
826 if (!wwin
->flags
.internal_window
)
827 wMenuMapAt(menu
, x
, y
, keyboard
);
830 void OpenMiniwindowMenu(WWindow
* wwin
, int x
, int y
)
834 menu
= open_window_menu_core(wwin
);
838 x
-= menu
->frame
->core
->width
/ 2;
840 wMenuMapAt(menu
, x
, y
, False
);
843 void DestroyWindowMenu(WScreen
*scr
)
845 if (scr
->window_menu
) {
846 scr
->window_menu
->entries
[MC_MINIATURIZE
]->text
= NULL
;
847 scr
->window_menu
->entries
[MC_MAXIMIZE
]->text
= NULL
;
848 scr
->window_menu
->entries
[MC_SHADE
]->text
= NULL
;
849 scr
->window_menu
->entries
[MC_SELECT
]->text
= NULL
;
850 wMenuDestroy(scr
->window_menu
, True
);
851 scr
->window_menu
= NULL
;