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 e->data.normal.enabled =frame->client->functions & OB_CLIENT_FUNC_MAXIMIZE;
77 e = menu_find_entry_id(menu, CLIENT_SHADE);
78 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_SHADE;
80 e = menu_find_entry_id(menu, CLIENT_MOVE);
81 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_MOVE;
83 e = menu_find_entry_id(menu, CLIENT_RESIZE);
84 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_RESIZE;
86 e = menu_find_entry_id(menu, CLIENT_CLOSE);
87 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_CLOSE;
90 static void layer_update(ObMenuFrame *frame, gpointer data)
92 ObMenu *menu = frame->menu;
96 for (it = menu->entries; it; it = g_list_next(it)) {
98 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL)
99 e->data.normal.enabled = !!frame->client;
105 e = menu_find_entry_id(menu, LAYER_TOP);
106 e->data.normal.enabled = !frame->client->above;
108 e = menu_find_entry_id(menu, LAYER_NORMAL);
109 e->data.normal.enabled = (frame->client->above || frame->client->below);
111 e = menu_find_entry_id(menu, LAYER_BOTTOM);
112 e->data.normal.enabled = !frame->client->below;
115 static void send_to_update(ObMenuFrame *frame, gpointer data)
117 ObMenu *menu = frame->menu;
122 menu_clear_entries(menu);
127 for (i = 0; i <= screen_num_desktops; ++i) {
131 if (i >= screen_num_desktops) {
132 menu_add_separator(menu, -1);
135 name = _("All desktops");
138 name = screen_desktop_names[i];
141 act = action_from_string("SendToDesktop",
142 OB_USER_ACTION_MENU_SELECTION);
143 act->data.sendto.desk = desk;
144 act->data.sendto.follow = FALSE;
145 acts = g_slist_prepend(NULL, act);
146 menu_add_normal(menu, desk, name, acts);
148 if (frame->client->desktop == desk) {
149 ObMenuEntry *e = menu_find_entry_id(menu, desk);
151 e->data.normal.enabled = FALSE;
156 void client_menu_startup()
162 menu = menu_new(LAYER_MENU_NAME, _("Layer"), NULL);
163 menu_set_update_func(menu, layer_update);
165 acts = g_slist_prepend(NULL, action_from_string
166 ("SendToTopLayer", OB_USER_ACTION_MENU_SELECTION));
167 menu_add_normal(menu, LAYER_TOP, _("Always on top"), acts);
169 acts = g_slist_prepend(NULL, action_from_string
170 ("SendToNormalLayer",
171 OB_USER_ACTION_MENU_SELECTION));
172 menu_add_normal(menu, LAYER_NORMAL, _("Normal"), acts);
174 acts = g_slist_prepend(NULL, action_from_string
175 ("SendToBottomLayer",
176 OB_USER_ACTION_MENU_SELECTION));
177 menu_add_normal(menu, LAYER_BOTTOM, _("Always on bottom"),acts);
180 menu = menu_new(SEND_TO_MENU_NAME, _("Send to desktop"), NULL);
181 menu_set_update_func(menu, send_to_update);
184 menu = menu_new(CLIENT_MENU_NAME, _("Client menu"), NULL);
185 menu_set_update_func(menu, client_update);
187 e = menu_add_submenu(menu, CLIENT_SEND_TO, SEND_TO_MENU_NAME);
188 e->data.normal.mask = ob_rr_theme->desk_mask;
189 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
190 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
191 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
193 menu_add_submenu(menu, CLIENT_LAYER, LAYER_MENU_NAME);
195 acts = g_slist_prepend(NULL, action_from_string
196 ("Iconify", OB_USER_ACTION_MENU_SELECTION));
197 e = menu_add_normal(menu, CLIENT_ICONIFY, _("Iconify"), acts);
198 e->data.normal.mask = ob_rr_theme->iconify_mask;
199 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
200 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
201 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
203 acts = g_slist_prepend(NULL, action_from_string
204 ("ToggleMaximizeFull",
205 OB_USER_ACTION_MENU_SELECTION));
206 e = menu_add_normal(menu, CLIENT_MAXIMIZE, _("Maximize"), acts);
207 e->data.normal.mask = ob_rr_theme->max_mask;
208 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
209 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
210 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
212 acts = g_slist_prepend(NULL, action_from_string
213 ("Raise", OB_USER_ACTION_MENU_SELECTION));
214 menu_add_normal(menu, CLIENT_RAISE, _("Raise to top"), acts);
216 acts = g_slist_prepend(NULL, action_from_string
217 ("Lower", OB_USER_ACTION_MENU_SELECTION));
218 menu_add_normal(menu, CLIENT_LOWER, _("Lower to bottom"),acts);
220 acts = g_slist_prepend(NULL, action_from_string
221 ("ToggleShade", OB_USER_ACTION_MENU_SELECTION));
222 e = menu_add_normal(menu, CLIENT_SHADE, _("Roll up/down"), acts);
223 e->data.normal.mask = ob_rr_theme->shade_mask;
224 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
225 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
226 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
228 acts = g_slist_prepend(NULL, action_from_string
229 ("ToggleDecorations",
230 OB_USER_ACTION_MENU_SELECTION));
231 menu_add_normal(menu, CLIENT_DECORATE, _("Decorate"), acts);
233 menu_add_separator(menu, -1);
235 acts = g_slist_prepend(NULL, action_from_string
236 ("Move", OB_USER_ACTION_MENU_SELECTION));
237 menu_add_normal(menu, CLIENT_MOVE, _("Move"), acts);
239 acts = g_slist_prepend(NULL, action_from_string
240 ("Resize", OB_USER_ACTION_MENU_SELECTION));
241 menu_add_normal(menu, CLIENT_RESIZE, _("Resize"), acts);
243 menu_add_separator(menu, -1);
245 acts = g_slist_prepend(NULL, action_from_string
246 ("Close", OB_USER_ACTION_MENU_SELECTION));
247 e = menu_add_normal(menu, CLIENT_CLOSE, _("Close"), acts);
248 e->data.normal.mask = ob_rr_theme->close_mask;
249 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
250 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
251 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;