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"
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"
36 void plugin_setup_config() { }
38 static void client_update(ObMenuFrame
*frame
, gpointer data
)
40 ObMenu
*menu
= frame
->menu
;
44 frame
->show_title
= FALSE
;
46 for (it
= menu
->entries
; it
; it
= g_list_next(it
)) {
48 if (e
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
49 e
->data
.normal
.enabled
= !!frame
->client
;
55 e
= menu_find_entry_id(menu
, CLIENT_ICONIFY
);
56 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_ICONIFY
;
58 e
= menu_find_entry_id(menu
, CLIENT_MAXIMIZE
);
59 e
->data
.normal
.enabled
=frame
->client
->functions
& OB_CLIENT_FUNC_MAXIMIZE
;
61 e
= menu_find_entry_id(menu
, CLIENT_SHADE
);
62 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_SHADE
;
64 e
= menu_find_entry_id(menu
, CLIENT_MOVE
);
65 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_MOVE
;
67 e
= menu_find_entry_id(menu
, CLIENT_RESIZE
);
68 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_RESIZE
;
70 e
= menu_find_entry_id(menu
, CLIENT_CLOSE
);
71 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_CLOSE
;
74 static void layer_update(ObMenuFrame
*frame
, gpointer data
)
76 ObMenu
*menu
= frame
->menu
;
80 for (it
= menu
->entries
; it
; it
= g_list_next(it
)) {
82 if (e
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
83 e
->data
.normal
.enabled
= !!frame
->client
;
89 e
= menu_find_entry_id(menu
, LAYER_TOP
);
90 e
->data
.normal
.enabled
= !frame
->client
->above
;
92 e
= menu_find_entry_id(menu
, LAYER_NORMAL
);
93 e
->data
.normal
.enabled
= (frame
->client
->above
|| frame
->client
->below
);
95 e
= menu_find_entry_id(menu
, LAYER_BOTTOM
);
96 e
->data
.normal
.enabled
= !frame
->client
->below
;
99 static void send_to_update(ObMenuFrame
*frame
, gpointer data
)
101 ObMenu
*menu
= frame
->menu
;
106 menu_clear_entries(SEND_TO_MENU_NAME
);
111 for (i
= 0; i
<= screen_num_desktops
; ++i
) {
115 if (i
>= screen_num_desktops
) {
117 name
= _("All desktops");
120 name
= screen_desktop_names
[i
];
123 act
= action_from_string("SendToDesktop");
124 act
->data
.sendto
.desk
= desk
;
125 act
->data
.sendto
.follow
= FALSE
;
126 acts
= g_slist_prepend(NULL
, act
);
127 menu_add_normal(SEND_TO_MENU_NAME
, desk
, name
, acts
);
129 if (frame
->client
->desktop
== desk
) {
130 ObMenuEntry
*e
= menu_find_entry_id(menu
, desk
);
132 e
->data
.normal
.enabled
= FALSE
;
137 void plugin_startup()
141 menu_new(LAYER_MENU_NAME
, _("Layer"), NULL
);
142 menu_set_update_func(LAYER_MENU_NAME
, layer_update
);
144 acts
= g_slist_prepend(NULL
, action_from_string("SendToTopLayer"));
145 menu_add_normal(LAYER_MENU_NAME
, LAYER_TOP
, _("Always on top"), acts
);
147 acts
= g_slist_prepend(NULL
, action_from_string("SendToNormalLayer"));
148 menu_add_normal(LAYER_MENU_NAME
, LAYER_NORMAL
, _("Normal"), acts
);
150 acts
= g_slist_prepend(NULL
, action_from_string("SendToBottomLayer"));
151 menu_add_normal(LAYER_MENU_NAME
, LAYER_BOTTOM
, _("Always on bottom"),acts
);
154 menu_new(SEND_TO_MENU_NAME
, _("Send to desktop"), NULL
);
155 menu_set_update_func(SEND_TO_MENU_NAME
, send_to_update
);
158 menu_new(CLIENT_MENU_NAME
, _("Client menu"), NULL
);
159 menu_set_update_func(CLIENT_MENU_NAME
, client_update
);
161 menu_add_submenu(CLIENT_MENU_NAME
, CLIENT_SEND_TO
, SEND_TO_MENU_NAME
);
163 menu_add_submenu(CLIENT_MENU_NAME
, CLIENT_LAYER
, LAYER_MENU_NAME
);
165 acts
= g_slist_prepend(NULL
, action_from_string("Iconify"));
166 menu_add_normal(CLIENT_MENU_NAME
, CLIENT_ICONIFY
, _("Iconify"), acts
);
168 acts
= g_slist_prepend(NULL
, action_from_string("ToggleMaximizeFull"));
169 menu_add_normal(CLIENT_MENU_NAME
, CLIENT_MAXIMIZE
, _("Maximize"), acts
);
171 acts
= g_slist_prepend(NULL
, action_from_string("Raise"));
172 menu_add_normal(CLIENT_MENU_NAME
, CLIENT_RAISE
, _("Raise to top"), acts
);
174 acts
= g_slist_prepend(NULL
, action_from_string("Lower"));
175 menu_add_normal(CLIENT_MENU_NAME
, CLIENT_LOWER
, _("Lower to bottom"),acts
);
177 acts
= g_slist_prepend(NULL
, action_from_string("ToggleShade"));
178 menu_add_normal(CLIENT_MENU_NAME
, CLIENT_SHADE
, _("Shade"), acts
);
180 acts
= g_slist_prepend(NULL
, action_from_string("ToggleDecorations"));
181 menu_add_normal(CLIENT_MENU_NAME
, CLIENT_DECORATE
, _("Decorate"), acts
);
183 menu_add_separator(CLIENT_MENU_NAME
, -1);
185 acts
= g_slist_prepend(NULL
, action_from_string("KeyboardMove"));
186 menu_add_normal(CLIENT_MENU_NAME
, CLIENT_MOVE
, _("Move"), acts
);
188 acts
= g_slist_prepend(NULL
, action_from_string("KeyboardResize"));
189 menu_add_normal(CLIENT_MENU_NAME
, CLIENT_RESIZE
, _("Resize"), acts
);
191 menu_add_separator(CLIENT_MENU_NAME
, -1);
193 acts
= g_slist_prepend(NULL
, action_from_string("Close"));
194 menu_add_normal(CLIENT_MENU_NAME
, CLIENT_CLOSE
, _("Close"), acts
);
197 void plugin_shutdown()
199 menu_free(LAYER_MENU_NAME
);
200 menu_free(SEND_TO_MENU_NAME
);
201 menu_free(CLIENT_MENU_NAME
);