NEWS: add entry for libXRes support
[wmaker-crm.git] / src / winmenu.c
blobdf5e43ba1e33f1f2b3f6a2f5db4769ebd31f89ed
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.
22 #include "wconfig.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <string.h>
29 #include <X11/Xlib.h>
30 #include <X11/Xutil.h>
31 #include <X11/XKBlib.h>
33 #include "WindowMaker.h"
34 #include "actions.h"
35 #include "menu.h"
36 #include "main.h"
37 #include "window.h"
38 #include "client.h"
39 #include "application.h"
40 #include "keybind.h"
41 #include "misc.h"
42 #include "framewin.h"
43 #include "workspace.h"
44 #include "winspector.h"
45 #include "dialog.h"
46 #include "stacking.h"
47 #include "icon.h"
48 #include "xinerama.h"
49 #include "winmenu.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.
63 enum
65 MC_MAXIMIZE,
66 MC_OTHERMAX,
67 MC_MINIATURIZE,
68 MC_SHADE,
69 MC_HIDE,
70 MC_MOVERESIZE,
71 MC_SELECT,
72 MC_CHANGEWKSPC,
73 MC_PROPERTIES,
74 MC_OPTIONS,
75 MC_RELAUNCH,
76 MC_CLOSE,
77 MC_KILL
80 static const struct {
81 const char *label;
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
105 enum
107 WO_KEEP_ON_TOP,
108 WO_KEEP_AT_BOTTOM,
109 WO_OMNIPRESENT
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 {
122 const char *label;
123 unsigned int shortcut_idx;
124 int maxim_direction;
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 */
146 (void) menu;
148 switch (entry->order) {
149 case WO_KEEP_ON_TOP:
150 if (wwin->frame->core->stacking->window_level != WMFloatingLevel)
151 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
152 else
153 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
154 break;
156 case WO_KEEP_AT_BOTTOM:
157 if (wwin->frame->core->stacking->window_level != WMSunkenLevel)
158 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
159 else
160 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
161 break;
163 case WO_OMNIPRESENT:
164 wWindowSetOmnipresent(wwin, !wwin->flags.omnipresent);
165 break;
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 */
174 (void) menu;
176 handleMaximize(wwin, menu_maximize_entries[entry->order].maxim_direction);
179 static void updateUnmaximizeShortcut(WMenuEntry * entry, int flags)
181 int key;
183 switch (flags & (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS)) {
184 case MAX_HORIZONTAL:
185 key = WKBD_HMAXIMIZE;
186 break;
188 case MAX_VERTICAL:
189 key = WKBD_VMAXIMIZE;
190 break;
192 case MAX_LEFTHALF | MAX_VERTICAL:
193 key = WKBD_LHMAXIMIZE;
194 break;
196 case MAX_RIGHTHALF | MAX_VERTICAL:
197 key = WKBD_RHMAXIMIZE;
198 break;
200 case MAX_TOPHALF | MAX_HORIZONTAL:
201 key = WKBD_THMAXIMIZE;
202 break;
204 case MAX_BOTTOMHALF | MAX_HORIZONTAL:
205 key = WKBD_BHMAXIMIZE;
206 break;
208 case MAX_LEFTHALF | MAX_TOPHALF:
209 key = WKBD_LTCMAXIMIZE;
210 break;
212 case MAX_RIGHTHALF | MAX_TOPHALF:
213 key = WKBD_RTCMAXIMIZE;
214 break;
216 case MAX_LEFTHALF | MAX_BOTTOMHALF:
217 key = WKBD_LBCMAXIMIZE;
218 break;
220 case MAX_RIGHTHALF | MAX_BOTTOMHALF:
221 key = WKBD_RBCMAXIMIZE;
222 break;
224 case MAX_MAXIMUS:
225 key = WKBD_MAXIMUS;
226 break;
228 default:
229 key = WKBD_MAXIMIZE;
230 break;
233 entry->rtext = GetShortcutKey(wKeyBindings[key]);
236 static void execMenuCommand(WMenu * menu, WMenuEntry * entry)
238 WWindow *wwin = (WWindow *) entry->clientdata;
239 WApplication *wapp;
241 CloseWindowMenu(menu->frame->screen_ptr);
243 switch (entry->order) {
244 case MC_CLOSE:
245 /* send delete message */
246 wClientSendProtocol(wwin, w_global.atom.wm.delete_window,
247 w_global.timestamp.last_event);
248 break;
250 case MC_KILL:
251 wretain(wwin);
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)
258 wClientKill(wwin);
260 wrelease(wwin);
261 break;
263 case MC_MINIATURIZE:
264 if (wwin->flags.miniaturized) {
265 wDeiconifyWindow(wwin);
266 } else {
267 if (wwin->protocols.MINIATURIZE_WINDOW) {
268 wClientSendProtocol(wwin, w_global.atom.gnustep.wm_miniaturize_window,
269 w_global.timestamp.last_event);
270 } else {
271 wIconifyWindow(wwin);
274 break;
276 case MC_MAXIMIZE:
277 if (wwin->flags.maximized)
278 wUnmaximizeWindow(wwin);
279 else
280 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_HORIZONTAL,
281 wGetHeadForWindow(wwin));
282 break;
284 case MC_SHADE:
285 if (wwin->flags.shaded)
286 wUnshadeWindow(wwin);
287 else
288 wShadeWindow(wwin);
289 break;
291 case MC_SELECT:
292 if (!wwin->flags.miniaturized)
293 wSelectWindow(wwin, !wwin->flags.selected);
294 else
295 wIconSelect(wwin->icon);
296 break;
298 case MC_MOVERESIZE:
299 wKeyboardMoveResizeWindow(wwin);
300 break;
302 case MC_PROPERTIES:
303 wShowInspectorForWindow(wwin);
304 break;
306 case MC_RELAUNCH:
307 (void) RelaunchWindow(wwin);
308 break;
310 case MC_HIDE:
311 wapp = wApplicationOf(wwin->main_window);
312 wHideApplication(wapp);
313 break;
317 static void switchWSCommand(WMenu * menu, WMenuEntry * entry)
319 WWindow *wwin = (WWindow *) entry->clientdata;
321 /* Parameter not used, but tell the compiler that it is ok */
322 (void) menu;
324 wSelectWindow(wwin, False);
325 wWindowChangeWorkspace(wwin, entry->order);
328 static void makeShortcutCommand(WMenu * menu, WMenuEntry * entry)
330 WWindow *wwin = (WWindow *) entry->clientdata;
331 WScreen *scr = wwin->screen_ptr;
332 int index = entry->order - wlengthof(menu_options_entries);
334 /* Parameter not used, but tell the compiler that it is ok */
335 (void) menu;
337 if (scr->shortcutWindows[index]) {
338 WMFreeArray(scr->shortcutWindows[index]);
339 scr->shortcutWindows[index] = NULL;
342 if (wwin->flags.selected && scr->selected_windows) {
343 scr->shortcutWindows[index] = WMDuplicateArray(scr->selected_windows);
344 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
345 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
346 } else {
347 scr->shortcutWindows[index] = WMCreateArray(4);
348 WMAddToArray(scr->shortcutWindows[index], wwin);
351 wSelectWindow(wwin, !wwin->flags.selected);
352 XFlush(dpy);
353 wusleep(3000);
354 wSelectWindow(wwin, !wwin->flags.selected);
355 XFlush(dpy);
358 static void updateWorkspaceMenu(WMenu * menu)
360 WScreen *scr = menu->frame->screen_ptr;
361 char title[MAX_WORKSPACENAME_WIDTH + 1];
362 WMenuEntry *entry;
363 int i;
365 for (i = 0; i < scr->workspace_count; i++) {
366 if (i < menu->entry_no) {
368 entry = menu->entries[i];
369 if (strcmp(entry->text, scr->workspaces[i]->name) != 0) {
370 wfree(entry->text);
371 strncpy(title, scr->workspaces[i]->name, MAX_WORKSPACENAME_WIDTH);
372 title[MAX_WORKSPACENAME_WIDTH] = 0;
373 menu->entries[i]->text = wstrdup(title);
374 menu->entries[i]->rtext = GetShortcutKey(wKeyBindings[WKBD_MOVE_WORKSPACE1 + i]);
375 menu->flags.realized = 0;
377 } else {
378 strncpy(title, scr->workspaces[i]->name, MAX_WORKSPACENAME_WIDTH);
379 title[MAX_WORKSPACENAME_WIDTH] = 0;
381 entry = wMenuAddCallback(menu, title, switchWSCommand, NULL);
382 entry->rtext = GetShortcutKey(wKeyBindings[WKBD_MOVE_WORKSPACE1 + i]);
384 menu->flags.realized = 0;
387 /* workspace shortcut labels */
388 if (i / 10 == scr->current_workspace / 10)
389 entry->rtext = GetShortcutKey(wKeyBindings[WKBD_MOVE_WORKSPACE1 + (i % 10)]);
390 else
391 entry->rtext = NULL;
394 if (!menu->flags.realized)
395 wMenuRealize(menu);
398 static void updateMakeShortcutMenu(WMenu * menu, WWindow * wwin)
400 WMenu *smenu = menu->cascades[menu->entries[MC_OPTIONS]->cascade];
401 int i;
402 char buffer[64];
403 KeyCode kcode;
405 if (!smenu)
406 return;
408 for (i = wlengthof(menu_options_entries); i < smenu->entry_no; i++) {
409 int shortcutNo = i - wlengthof(menu_options_entries);
410 WMenuEntry *entry = smenu->entries[i];
411 WMArray *shortSelWindows = wwin->screen_ptr->shortcutWindows[shortcutNo];
413 snprintf(buffer, sizeof(buffer), _("Set Shortcut %i"), shortcutNo + 1);
415 if (!shortSelWindows) {
416 entry->flags.indicator_on = 0;
417 } else {
418 entry->flags.indicator_on = 1;
419 if (WMCountInArray(shortSelWindows, wwin))
420 entry->flags.indicator_type = MI_DIAMOND;
421 else
422 entry->flags.indicator_type = MI_CHECK;
425 if (strcmp(buffer, entry->text) != 0) {
426 wfree(entry->text);
427 entry->text = wstrdup(buffer);
428 smenu->flags.realized = 0;
431 kcode = wKeyBindings[WKBD_WINDOW1 + shortcutNo].keycode;
433 if (kcode) {
434 char *tmp;
436 tmp = GetShortcutKey(wKeyBindings[WKBD_WINDOW1 + shortcutNo]);
437 if (tmp == NULL) {
438 if (entry->rtext != NULL) {
439 /* There was a shortcut, but there is no more */
440 wfree(entry->rtext);
441 entry->rtext = NULL;
442 smenu->flags.realized = 0;
444 } else if (entry->rtext == NULL) {
445 /* There was no shortcut, but there is one now */
446 entry->rtext = tmp;
447 smenu->flags.realized = 0;
448 } else if (strcmp(tmp, entry->rtext) != 0) {
449 /* There was a shortcut, but it has changed */
450 wfree(entry->rtext);
451 entry->rtext = tmp;
452 smenu->flags.realized = 0;
453 } else {
454 /* There was a shortcut but it did not change */
455 wfree(tmp);
457 wMenuSetEnabled(smenu, i, True);
458 } else {
459 wMenuSetEnabled(smenu, i, False);
460 if (entry->rtext) {
461 wfree(entry->rtext);
462 entry->rtext = NULL;
463 smenu->flags.realized = 0;
466 entry->clientdata = wwin;
468 if (!smenu->flags.realized)
469 wMenuRealize(smenu);
472 static void updateOptionsMenu(WMenu * menu, WWindow * wwin)
474 WMenu *smenu = menu->cascades[menu->entries[MC_OPTIONS]->cascade];
476 /* keep on top check */
477 smenu->entries[WO_KEEP_ON_TOP]->clientdata = wwin;
478 smenu->entries[WO_KEEP_ON_TOP]->flags.indicator_on =
479 (wwin->frame->core->stacking->window_level == WMFloatingLevel) ? 1 : 0;
480 wMenuSetEnabled(smenu, WO_KEEP_ON_TOP, !wwin->flags.miniaturized);
481 smenu->entries[WO_KEEP_ON_TOP]->rtext = GetShortcutKey(wKeyBindings[WKBD_KEEP_ON_TOP]);
483 /* keep at bottom check */
484 smenu->entries[WO_KEEP_AT_BOTTOM]->clientdata = wwin;
485 smenu->entries[WO_KEEP_AT_BOTTOM]->flags.indicator_on =
486 (wwin->frame->core->stacking->window_level == WMSunkenLevel) ? 1 : 0;
487 wMenuSetEnabled(smenu, WO_KEEP_AT_BOTTOM, !wwin->flags.miniaturized);
488 smenu->entries[WO_KEEP_AT_BOTTOM]->rtext = GetShortcutKey(wKeyBindings[WKBD_KEEP_AT_BOTTOM]);
490 /* omnipresent check */
491 smenu->entries[WO_OMNIPRESENT]->clientdata = wwin;
492 smenu->entries[WO_OMNIPRESENT]->flags.indicator_on = IS_OMNIPRESENT(wwin);
493 smenu->entries[WO_OMNIPRESENT]->rtext = GetShortcutKey(wKeyBindings[WKBD_OMNIPRESENT]);
495 smenu->flags.realized = 0;
496 wMenuRealize(smenu);
499 static void updateMaximizeMenu(WMenu * menu, WWindow * wwin)
501 WMenu *smenu = menu->cascades[menu->entries[MC_OTHERMAX]->cascade];
502 int i;
504 for (i = 0; i < smenu->entry_no; i++) {
505 smenu->entries[i]->clientdata = wwin;
506 smenu->entries[i]->rtext = GetShortcutKey(wKeyBindings[menu_maximize_entries[i].shortcut_idx]);
509 smenu->flags.realized = 0;
510 wMenuRealize(smenu);
513 static WMenu *makeWorkspaceMenu(WScreen * scr)
515 WMenu *menu;
517 menu = wMenuCreate(scr, NULL, False);
518 if (!menu) {
519 wwarning(_("could not create submenu for window menu"));
520 return NULL;
523 updateWorkspaceMenu(menu);
526 * The Workspace Menu is made visible in the screen structure because
527 * it is updated when there is a change on workspaces. This was done
528 * to be efficient, avoiding re-generating completely the window menu
529 * and its sub-menus every time it is needed.
531 scr->workspace_submenu = menu;
533 return menu;
536 static WMenu *makeOptionsMenu(WScreen * scr)
538 WMenu *menu;
539 WMenuEntry *entry;
540 int i;
542 menu = wMenuCreate(scr, NULL, False);
543 if (!menu) {
544 wwarning(_("could not create submenu for window menu"));
545 return NULL;
548 for (i = 0; i < wlengthof(menu_options_entries); i++) {
549 entry = wMenuAddCallback(menu, _(menu_options_entries[i]), execWindowOptionCommand, NULL);
550 entry->flags.indicator = 1;
551 entry->flags.indicator_type = MI_CHECK;
554 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
555 entry = wMenuAddCallback(menu, "", makeShortcutCommand, NULL);
556 entry->flags.indicator = 1;
559 return menu;
562 static WMenu *makeMaximizeMenu(WScreen * scr)
564 WMenu *menu;
565 int i;
567 menu = wMenuCreate(scr, NULL, False);
568 if (!menu) {
569 wwarning(_("could not create submenu for window menu"));
570 return NULL;
573 for (i = 0; i < wlengthof(menu_maximize_entries); i++)
574 wMenuAddCallback(menu, _(menu_maximize_entries[i].label), execMaximizeCommand, NULL);
576 return menu;
579 static WMenu *createWindowMenu(WScreen * scr)
581 WMenu *menu;
582 int i;
584 menu = wMenuCreate(scr, NULL, False);
586 for (i = 0; i < wlengthof(window_menu_entries); i++) {
587 WMenuEntry *entry;
589 entry = wMenuAddCallback(menu, _(window_menu_entries[i].label),
590 (window_menu_entries[i].generate_submenu == NULL)?execMenuCommand:NULL,
591 NULL);
592 if (window_menu_entries[i].generate_submenu != NULL) {
593 WMenu *submenu;
595 submenu = window_menu_entries[i].generate_submenu(scr);
596 wMenuEntrySetCascade(menu, entry, submenu);
600 return menu;
603 void CloseWindowMenu(WScreen * scr)
605 if (scr->window_menu) {
606 if (scr->window_menu->flags.mapped)
607 wMenuUnmap(scr->window_menu);
609 if (scr->window_menu->entries[0]->clientdata) {
610 WWindow *wwin = (WWindow *) scr->window_menu->entries[0]->clientdata;
612 wwin->flags.menu_open_for_me = 0;
614 scr->window_menu->entries[0]->clientdata = NULL;
618 static void updateMenuForWindow(WMenu * menu, WWindow * wwin)
620 WApplication *wapp = wApplicationOf(wwin->main_window);
621 WScreen *scr = wwin->screen_ptr;
622 int i;
624 updateOptionsMenu(menu, wwin);
625 updateMaximizeMenu(menu, wwin);
627 updateMakeShortcutMenu(menu, wwin);
629 wMenuSetEnabled(menu, MC_HIDE, wapp != NULL && !WFLAGP(wapp->main_window_desc, no_appicon));
631 wMenuSetEnabled(menu, MC_CLOSE, (wwin->protocols.DELETE_WINDOW && !WFLAGP(wwin, no_closable)));
633 if (wwin->flags.miniaturized) {
634 static char *text = NULL;
635 if (!text)
636 text = _("Deminiaturize");
638 menu->entries[MC_MINIATURIZE]->text = text;
639 } else {
640 static char *text = NULL;
641 if (!text)
642 text = _("Miniaturize");
644 menu->entries[MC_MINIATURIZE]->text = text;
647 wMenuSetEnabled(menu, MC_MINIATURIZE, !WFLAGP(wwin, no_miniaturizable));
649 if (wwin->flags.maximized) {
650 static char *text = NULL;
651 if (!text)
652 text = _("Unmaximize");
654 menu->entries[MC_MAXIMIZE]->text = text;
655 updateUnmaximizeShortcut(menu->entries[MC_MAXIMIZE], wwin->flags.maximized);
656 } else {
657 static char *text = NULL;
658 if (!text)
659 text = _("Maximize");
661 menu->entries[MC_MAXIMIZE]->text = text;
662 menu->entries[MC_MAXIMIZE]->rtext = GetShortcutKey(wKeyBindings[WKBD_MAXIMIZE]);
664 wMenuSetEnabled(menu, MC_MAXIMIZE, IS_RESIZABLE(wwin));
666 wMenuSetEnabled(menu, MC_MOVERESIZE, IS_RESIZABLE(wwin)
667 && !wwin->flags.miniaturized);
669 if (wwin->flags.shaded) {
670 static char *text = NULL;
671 if (!text)
672 text = _("Unshade");
674 menu->entries[MC_SHADE]->text = text;
675 } else {
676 static char *text = NULL;
677 if (!text)
678 text = _("Shade");
680 menu->entries[MC_SHADE]->text = text;
683 wMenuSetEnabled(menu, MC_SHADE, !WFLAGP(wwin, no_shadeable)
684 && !wwin->flags.miniaturized);
686 if (wwin->flags.selected) {
687 static char *text = NULL;
688 if (!text)
689 text = _("Deselect");
691 menu->entries[MC_SELECT]->text = text;
692 } else {
693 static char *text = NULL;
694 if (!text)
695 text = _("Select");
697 menu->entries[MC_SELECT]->text = text;
700 wMenuSetEnabled(menu, MC_CHANGEWKSPC, !IS_OMNIPRESENT(wwin));
702 if (!wwin->flags.inspector_open) {
703 wMenuSetEnabled(menu, MC_PROPERTIES, True);
704 } else {
705 wMenuSetEnabled(menu, MC_PROPERTIES, False);
708 /* Update shortcut labels except for (Un)Maximize which is
709 * handled separately.
711 menu->entries[MC_MINIATURIZE]->rtext = GetShortcutKey(wKeyBindings[WKBD_MINIATURIZE]);
712 menu->entries[MC_SHADE]->rtext = GetShortcutKey(wKeyBindings[WKBD_SHADE]);
713 menu->entries[MC_HIDE]->rtext = GetShortcutKey(wKeyBindings[WKBD_HIDE]);
714 menu->entries[MC_MOVERESIZE]->rtext = GetShortcutKey(wKeyBindings[WKBD_MOVERESIZE]);
715 menu->entries[MC_SELECT]->rtext = GetShortcutKey(wKeyBindings[WKBD_SELECT]);
716 menu->entries[MC_RELAUNCH]->rtext = GetShortcutKey(wKeyBindings[WKBD_RELAUNCH]);
717 menu->entries[MC_CLOSE]->rtext = GetShortcutKey(wKeyBindings[WKBD_CLOSE]);
719 /* set the client data of the entries to the window */
720 for (i = 0; i < menu->entry_no; i++) {
721 menu->entries[i]->clientdata = wwin;
724 for (i = 0; i < scr->workspace_submenu->entry_no; i++) {
725 scr->workspace_submenu->entries[i]->clientdata = wwin;
726 if (i == scr->current_workspace)
727 wMenuSetEnabled(scr->workspace_submenu, i, False);
728 else
729 wMenuSetEnabled(scr->workspace_submenu, i, True);
732 menu->flags.realized = 0;
733 wMenuRealize(menu);
736 static WMenu *open_window_menu_core(WWindow *wwin)
738 WScreen *scr = wwin->screen_ptr;
739 WMenu *menu;
741 wwin->flags.menu_open_for_me = 1;
743 if (!scr->window_menu) {
744 scr->window_menu = createWindowMenu(scr);
746 /* hack to save some memory allocation/deallocation */
747 wfree(scr->window_menu->entries[MC_MINIATURIZE]->text);
748 wfree(scr->window_menu->entries[MC_MAXIMIZE]->text);
749 wfree(scr->window_menu->entries[MC_SHADE]->text);
750 wfree(scr->window_menu->entries[MC_SELECT]->text);
751 } else {
752 updateWorkspaceMenu(scr->workspace_submenu);
755 menu = scr->window_menu;
756 if (menu->flags.mapped) {
757 wMenuUnmap(menu);
758 if (menu->entries[0]->clientdata == wwin)
759 return NULL;
762 updateMenuForWindow(menu, wwin);
764 return menu;
767 static void prepare_menu_position(WMenu *menu, int *x, int *y)
769 WMRect rect;
771 rect = wGetRectForHead(menu->frame->screen_ptr,
772 wGetHeadForPointerLocation(menu->frame->screen_ptr));
773 if (*x < rect.pos.x - menu->frame->core->width / 2)
774 *x = rect.pos.x - menu->frame->core->width / 2;
775 if (*y < rect.pos.y)
776 *y = rect.pos.y;
779 void OpenWindowMenu(WWindow *wwin, int x, int y, int keyboard)
781 WMenu *menu;
783 menu = open_window_menu_core(wwin);
784 if (!menu)
785 return;
787 /* Specific menu position */
788 x -= menu->frame->core->width / 2;
789 if (x + menu->frame->core->width > wwin->frame_x + wwin->frame->core->width)
790 x = wwin->frame_x + wwin->frame->core->width - menu->frame->core->width;
791 if (x < wwin->frame_x)
792 x = wwin->frame_x;
794 /* Common menu position */
795 prepare_menu_position(menu, &x, &y);
797 if (!wwin->flags.internal_window)
798 wMenuMapAt(menu, x, y, keyboard);
801 void OpenWindowMenu2(WWindow *wwin, int x, int y, int keyboard)
803 int i;
804 WMenu *menu;
805 WScreen *scr = wwin->screen_ptr;
807 menu = open_window_menu_core(wwin);
808 if (!menu)
809 return;
811 /* Specific menu position */
812 for (i = 0; i < scr->workspace_submenu->entry_no; i++) {
813 scr->workspace_submenu->entries[i]->clientdata = wwin;
814 wMenuSetEnabled(scr->workspace_submenu, i, True);
817 x -= menu->frame->core->width / 2;
819 /* Common menu position */
820 prepare_menu_position(menu, &x, &y);
822 if (!wwin->flags.internal_window)
823 wMenuMapAt(menu, x, y, keyboard);
826 void OpenMiniwindowMenu(WWindow * wwin, int x, int y)
828 WMenu *menu;
830 menu = open_window_menu_core(wwin);
831 if (!menu)
832 return;
834 x -= menu->frame->core->width / 2;
836 wMenuMapAt(menu, x, y, False);
839 void DestroyWindowMenu(WScreen *scr)
841 if (scr->window_menu) {
842 scr->window_menu->entries[MC_MINIATURIZE]->text = NULL;
843 scr->window_menu->entries[MC_MAXIMIZE]->text = NULL;
844 scr->window_menu->entries[MC_SHADE]->text = NULL;
845 scr->window_menu->entries[MC_SELECT]->text = NULL;
846 wMenuDestroy(scr->window_menu, True);
847 scr->window_menu = NULL;