1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client_menu.c for the Openbox window manager
4 Copyright (c) 2003 Ben Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
21 #include "menuframe.h"
30 #define CLIENT_MENU_NAME "client-menu"
31 #define SEND_TO_MENU_NAME "client-send-to-menu"
32 #define LAYER_MENU_NAME "client-layer-menu"
54 static void client_update(ObMenuFrame *frame, gpointer data)
56 ObMenu *menu = frame->menu;
60 frame->show_title = FALSE;
62 for (it = menu->entries; it; it = g_list_next(it)) {
64 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL)
65 e->data.normal.enabled = !!frame->client;
71 e = menu_find_entry_id(menu, CLIENT_ICONIFY);
72 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_ICONIFY;
74 e = menu_find_entry_id(menu, CLIENT_MAXIMIZE);
75 g_free(e->data.normal.label);
76 e->data.normal.label =
77 g_strdup(frame->client->max_vert || frame->client->max_horz ?
78 _("Restore") : _("Maximize"));
79 e->data.normal.enabled =frame->client->functions & OB_CLIENT_FUNC_MAXIMIZE;
81 e = menu_find_entry_id(menu, CLIENT_SHADE);
82 g_free(e->data.normal.label);
83 e->data.normal.label = g_strdup(frame->client->shaded ?
84 _("Roll down") : _("Roll up"));
85 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_SHADE;
87 e = menu_find_entry_id(menu, CLIENT_MOVE);
88 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_MOVE;
90 e = menu_find_entry_id(menu, CLIENT_RESIZE);
91 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_RESIZE;
93 e = menu_find_entry_id(menu, CLIENT_CLOSE);
94 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_CLOSE;
96 e = menu_find_entry_id(menu, CLIENT_DECORATE);
97 e->data.normal.enabled = client_normal(frame->client);
100 static void layer_update(ObMenuFrame *frame, gpointer data)
102 ObMenu *menu = frame->menu;
106 for (it = menu->entries; it; it = g_list_next(it)) {
108 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL)
109 e->data.normal.enabled = !!frame->client;
115 e = menu_find_entry_id(menu, LAYER_TOP);
116 e->data.normal.enabled = !frame->client->above;
118 e = menu_find_entry_id(menu, LAYER_NORMAL);
119 e->data.normal.enabled = (frame->client->above || frame->client->below);
121 e = menu_find_entry_id(menu, LAYER_BOTTOM);
122 e->data.normal.enabled = !frame->client->below;
125 static void send_to_update(ObMenuFrame *frame, gpointer data)
127 ObMenu *menu = frame->menu;
133 menu_clear_entries(menu);
138 for (i = 0; i <= screen_num_desktops; ++i) {
142 if (i >= screen_num_desktops) {
143 menu_add_separator(menu, -1);
146 name = _("All desktops");
149 name = screen_desktop_names[i];
152 act = action_from_string("SendToDesktop",
153 OB_USER_ACTION_MENU_SELECTION);
154 act->data.sendto.desk = desk;
155 act->data.sendto.follow = FALSE;
156 acts = g_slist_prepend(NULL, act);
157 e = menu_add_normal(menu, desk, name, acts);
159 if (frame->client->desktop == desk)
160 e->data.normal.enabled = FALSE;
164 void client_menu_startup()
170 menu = menu_new(LAYER_MENU_NAME, _("Layer"), NULL);
171 menu_set_update_func(menu, layer_update);
173 acts = g_slist_prepend(NULL, action_from_string
174 ("SendToTopLayer", OB_USER_ACTION_MENU_SELECTION));
175 menu_add_normal(menu, LAYER_TOP, _("Always on top"), acts);
177 acts = g_slist_prepend(NULL, action_from_string
178 ("SendToNormalLayer",
179 OB_USER_ACTION_MENU_SELECTION));
180 menu_add_normal(menu, LAYER_NORMAL, _("Normal"), acts);
182 acts = g_slist_prepend(NULL, action_from_string
183 ("SendToBottomLayer",
184 OB_USER_ACTION_MENU_SELECTION));
185 menu_add_normal(menu, LAYER_BOTTOM, _("Always on bottom"),acts);
188 menu = menu_new(SEND_TO_MENU_NAME, _("Send to desktop"), NULL);
189 menu_set_update_func(menu, send_to_update);
192 menu = menu_new(CLIENT_MENU_NAME, _("Client menu"), NULL);
193 menu_set_update_func(menu, client_update);
195 e = menu_add_submenu(menu, CLIENT_SEND_TO, SEND_TO_MENU_NAME);
196 e->data.normal.mask = ob_rr_theme->desk_mask;
197 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
198 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
199 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
201 menu_add_submenu(menu, CLIENT_LAYER, LAYER_MENU_NAME);
203 acts = g_slist_prepend(NULL, action_from_string
204 ("Iconify", OB_USER_ACTION_MENU_SELECTION));
205 e = menu_add_normal(menu, CLIENT_ICONIFY, _("Iconify"), acts);
206 e->data.normal.mask = ob_rr_theme->iconify_mask;
207 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
208 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
209 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
211 acts = g_slist_prepend(NULL, action_from_string
212 ("ToggleMaximizeFull",
213 OB_USER_ACTION_MENU_SELECTION));
214 e = menu_add_normal(menu, CLIENT_MAXIMIZE, "MAXIMIZE", acts);
215 e->data.normal.mask = ob_rr_theme->max_mask;
216 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
217 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
218 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
220 acts = g_slist_prepend(NULL, action_from_string
221 ("Raise", OB_USER_ACTION_MENU_SELECTION));
222 menu_add_normal(menu, CLIENT_RAISE, _("Raise to top"), acts);
224 acts = g_slist_prepend(NULL, action_from_string
225 ("Lower", OB_USER_ACTION_MENU_SELECTION));
226 menu_add_normal(menu, CLIENT_LOWER, _("Lower to bottom"),acts);
228 acts = g_slist_prepend(NULL, action_from_string
229 ("ToggleShade", OB_USER_ACTION_MENU_SELECTION));
230 e = menu_add_normal(menu, CLIENT_SHADE, "SHADE", acts);
231 e->data.normal.mask = ob_rr_theme->shade_mask;
232 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
233 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
234 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
236 acts = g_slist_prepend(NULL, action_from_string
237 ("ToggleDecorations",
238 OB_USER_ACTION_MENU_SELECTION));
239 menu_add_normal(menu, CLIENT_DECORATE, _("Decorate"), acts);
241 menu_add_separator(menu, -1);
243 acts = g_slist_prepend(NULL, action_from_string
244 ("Move", OB_USER_ACTION_MENU_SELECTION));
245 menu_add_normal(menu, CLIENT_MOVE, _("Move"), acts);
247 acts = g_slist_prepend(NULL, action_from_string
248 ("Resize", OB_USER_ACTION_MENU_SELECTION));
249 menu_add_normal(menu, CLIENT_RESIZE, _("Resize"), acts);
251 menu_add_separator(menu, -1);
253 acts = g_slist_prepend(NULL, action_from_string
254 ("Close", OB_USER_ACTION_MENU_SELECTION));
255 e = menu_add_normal(menu, CLIENT_CLOSE, _("Close"), acts);
256 e->data.normal.mask = ob_rr_theme->close_mask;
257 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
258 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
259 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;