]> icculus.org git repositories - dana/openbox.git/blob - plugins/menu/client_menu.c
remove the placement plugin
[dana/openbox.git] / plugins / menu / client_menu.c
1 #include "kernel/debug.h"
2 #include "kernel/menu.h"
3 #include "kernel/menuframe.h"
4 #include "kernel/screen.h"
5 #include "kernel/client.h"
6 #include "kernel/openbox.h"
7 #include "kernel/frame.h"
8 #include "gettext.h"
9
10 #include <glib.h>
11
12 #define CLIENT_MENU_NAME  "client-menu"
13 #define SEND_TO_MENU_NAME "client-send-to-menu"
14 #define LAYER_MENU_NAME   "client-layer-menu"
15
16 enum {
17     LAYER_TOP,
18     LAYER_NORMAL,
19     LAYER_BOTTOM
20 };
21
22 enum {
23     CLIENT_SEND_TO,
24     CLIENT_LAYER,
25     CLIENT_ICONIFY,
26     CLIENT_MAXIMIZE,
27     CLIENT_RAISE,
28     CLIENT_LOWER,
29     CLIENT_SHADE,
30     CLIENT_DECORATE,
31     CLIENT_MOVE,
32     CLIENT_RESIZE,
33     CLIENT_CLOSE
34 };
35
36 void plugin_setup_config() { }
37
38 static void client_update(ObMenuFrame *frame, gpointer data)
39 {
40     ObMenu *menu = frame->menu;
41     ObMenuEntry *e;
42     GList *it;
43
44     frame->show_title = FALSE;
45
46     for (it = menu->entries; it; it = g_list_next(it)) {
47         e = it->data;
48         if (e->type == OB_MENU_ENTRY_TYPE_NORMAL)
49             e->data.normal.enabled = !!frame->client;
50     }
51
52     if (!frame->client)
53         return;
54
55     e = menu_find_entry_id(menu, CLIENT_ICONIFY);
56     e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_ICONIFY;
57
58     e = menu_find_entry_id(menu, CLIENT_MAXIMIZE);
59     e->data.normal.enabled =frame->client->functions & OB_CLIENT_FUNC_MAXIMIZE;
60
61     e = menu_find_entry_id(menu, CLIENT_SHADE);
62     e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_SHADE;
63
64     e = menu_find_entry_id(menu, CLIENT_MOVE);
65     e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_MOVE;
66
67     e = menu_find_entry_id(menu, CLIENT_RESIZE);
68     e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_RESIZE;
69
70     e = menu_find_entry_id(menu, CLIENT_CLOSE);
71     e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_CLOSE;
72 }
73
74 static void layer_update(ObMenuFrame *frame, gpointer data)
75 {
76     ObMenu *menu = frame->menu;
77     ObMenuEntry *e;
78     GList *it;
79
80     for (it = menu->entries; it; it = g_list_next(it)) {
81         e = it->data;
82         if (e->type == OB_MENU_ENTRY_TYPE_NORMAL)
83             e->data.normal.enabled = !!frame->client;
84     }
85
86     if (!frame->client)
87         return;
88
89     e = menu_find_entry_id(menu, LAYER_TOP);
90     e->data.normal.enabled = !frame->client->above;
91
92     e = menu_find_entry_id(menu, LAYER_NORMAL);
93     e->data.normal.enabled = (frame->client->above || frame->client->below);
94
95     e = menu_find_entry_id(menu, LAYER_BOTTOM);
96     e->data.normal.enabled = !frame->client->below;
97 }
98
99 static void send_to_update(ObMenuFrame *frame, gpointer data)
100 {
101     ObMenu *menu = frame->menu;
102     guint i;
103     GSList *acts;
104     ObAction *act;
105
106     menu_clear_entries(SEND_TO_MENU_NAME);
107
108     if (!frame->client)
109         return;
110
111     for (i = 0; i <= screen_num_desktops; ++i) {
112         gchar *name;
113         guint desk;
114
115         if (i >= screen_num_desktops) {
116             menu_add_separator(CLIENT_MENU_NAME, -1);
117
118             desk = DESKTOP_ALL;
119             name = _("All desktops");
120         } else {
121             desk = i;
122             name = screen_desktop_names[i];
123         }
124
125         act = action_from_string("SendToDesktop");
126         act->data.sendto.desk = desk;
127         act->data.sendto.follow = FALSE;
128         acts = g_slist_prepend(NULL, act);
129         menu_add_normal(SEND_TO_MENU_NAME, desk, name, acts);
130
131         if (frame->client->desktop == desk) {
132             ObMenuEntry *e = menu_find_entry_id(menu, desk);
133             g_assert(e);
134             e->data.normal.enabled = FALSE;
135         }
136     }
137 }
138
139 void plugin_startup()
140 {
141     GSList *acts;
142
143     menu_new(LAYER_MENU_NAME, _("Layer"), NULL);
144     menu_set_update_func(LAYER_MENU_NAME, layer_update);
145
146     acts = g_slist_prepend(NULL, action_from_string("SendToTopLayer"));
147     menu_add_normal(LAYER_MENU_NAME, LAYER_TOP, _("Always on top"), acts);
148
149     acts = g_slist_prepend(NULL, action_from_string("SendToNormalLayer"));
150     menu_add_normal(LAYER_MENU_NAME, LAYER_NORMAL, _("Normal"), acts);
151
152     acts = g_slist_prepend(NULL, action_from_string("SendToBottomLayer"));
153     menu_add_normal(LAYER_MENU_NAME, LAYER_BOTTOM, _("Always on bottom"),acts);
154
155
156     menu_new(SEND_TO_MENU_NAME, _("Send to desktop"), NULL);
157     menu_set_update_func(SEND_TO_MENU_NAME, send_to_update);
158
159
160     menu_new(CLIENT_MENU_NAME, _("Client menu"), NULL);
161     menu_set_update_func(CLIENT_MENU_NAME, client_update);
162
163     menu_add_submenu(CLIENT_MENU_NAME, CLIENT_SEND_TO, SEND_TO_MENU_NAME);
164
165     menu_add_submenu(CLIENT_MENU_NAME, CLIENT_LAYER, LAYER_MENU_NAME);
166
167     acts = g_slist_prepend(NULL, action_from_string("Iconify"));
168     menu_add_normal(CLIENT_MENU_NAME, CLIENT_ICONIFY, _("Iconify"), acts);
169
170     acts = g_slist_prepend(NULL, action_from_string("ToggleMaximizeFull"));
171     menu_add_normal(CLIENT_MENU_NAME, CLIENT_MAXIMIZE, _("Maximize"), acts);
172
173     acts = g_slist_prepend(NULL, action_from_string("Raise"));
174     menu_add_normal(CLIENT_MENU_NAME, CLIENT_RAISE, _("Raise to top"), acts);
175
176     acts = g_slist_prepend(NULL, action_from_string("Lower"));
177     menu_add_normal(CLIENT_MENU_NAME, CLIENT_LOWER, _("Lower to bottom"),acts);
178
179     acts = g_slist_prepend(NULL, action_from_string("ToggleShade"));
180     menu_add_normal(CLIENT_MENU_NAME, CLIENT_SHADE, _("Roll up/down"), acts);
181
182     acts = g_slist_prepend(NULL, action_from_string("ToggleDecorations"));
183     menu_add_normal(CLIENT_MENU_NAME, CLIENT_DECORATE, _("Decorate"), acts);
184
185     menu_add_separator(CLIENT_MENU_NAME, -1);
186
187     acts = g_slist_prepend(NULL, action_from_string("KeyboardMove"));
188     menu_add_normal(CLIENT_MENU_NAME, CLIENT_MOVE, _("Move"), acts);
189
190     acts = g_slist_prepend(NULL, action_from_string("KeyboardResize"));
191     menu_add_normal(CLIENT_MENU_NAME, CLIENT_RESIZE, _("Resize"), acts);
192
193     menu_add_separator(CLIENT_MENU_NAME, -1);
194
195     acts = g_slist_prepend(NULL, action_from_string("Close"));
196     menu_add_normal(CLIENT_MENU_NAME, CLIENT_CLOSE, _("Close"), acts);
197 }
198
199 void plugin_shutdown()
200 {
201     menu_free(LAYER_MENU_NAME);
202     menu_free(SEND_TO_MENU_NAME);
203     menu_free(CLIENT_MENU_NAME);
204 }