]> icculus.org git repositories - dana/openbox.git/blob - plugins/menu/client_menu.c
xinerama support
[dana/openbox.git] / plugins / menu / client_menu.c
1 #include <glib.h>
2
3 #include "kernel/menu.h"
4 #include "kernel/screen.h"
5 #include "kernel/client.h"
6 #include "kernel/openbox.h"
7
8 #include "kernel/frame.h"
9
10 #include "render/theme.h"
11
12 static char *PLUGIN_NAME = "client_menu";
13
14 static Menu *send_to_menu;
15 static Menu *layer_menu;
16
17 typedef struct {
18
19 } Client_Menu_Data;
20
21 #define CLIENT_MENU(m) ((Menu *)m)
22 #define CLIENT_MENU_DATA(m) ((Client_Menu_Data *)((Menu *)m)->plugin_data)
23
24
25 void client_menu_clean_up(Menu *m) {
26 }
27
28 void client_send_to_update(Menu *self)
29 {
30     guint i;
31     
32     for (i = 0; i < screen_num_desktops; ++i) {
33         MenuEntry *e;
34         Action *a = action_from_string("sendtodesktop");
35         a->data.sendto.desk = i;
36         a->data.sendto.follow = FALSE;
37         e = menu_entry_new(screen_desktop_names[i], a);
38         menu_add_entry(self, e);
39     }
40
41     menu_render_full(self);
42 }
43
44 void client_menu_show(Menu *self, int x, int y, Client *client)
45 {
46     int newy;
47     g_assert(!self->invalid);
48     g_assert(client);
49     
50     newy = MAX(client->frame->area.y + client->frame->size.top, y);
51     newy -= ob_rr_theme->bwidth;
52     
53     /* XXX do xinerama shit like in menu.c! im not coding it now because
54        this function isnt even being used right now... */
55     POINT_SET(self->location, 
56               MIN(x, screen_physical_size.width - self->size.width -
57                   ob_rr_theme->bwidth * 2), 
58               MIN(newy, screen_physical_size.height - self->size.height -
59                   ob_rr_theme->bwidth * 2));
60     XMoveWindow(ob_display, self->frame, self->location.x, self->location.y);
61
62     if (!self->shown) {
63         XMapWindow(ob_display, self->frame);
64         stacking_raise(MENU_AS_WINDOW(self));
65         self->shown = TRUE;
66     } else if (self->shown && self->open_submenu) {
67         menu_hide(self->open_submenu);
68     }
69 }
70
71 void plugin_setup_config() { }
72
73 void plugin_shutdown() { }
74
75 void plugin_destroy (Menu *m)
76 {
77 }
78
79 void *plugin_create() /* TODO: need config */
80 {
81     Menu *m = menu_new_full(NULL, "client-menu", NULL,
82                             /*client_menu_show*/NULL, NULL);
83     menu_add_entry(m, menu_entry_new_submenu("Send To Workspace",
84                                              send_to_menu));
85     send_to_menu->parent = m;
86
87     menu_add_entry(m, menu_entry_new("Iconify",
88                                      action_from_string("iconify")));
89     menu_add_entry(m, menu_entry_new("Raise",
90                                      action_from_string("raise")));
91     menu_add_entry(m, menu_entry_new("Lower",
92                                      action_from_string("lower")));
93     menu_add_entry(m, menu_entry_new("Close",
94                                      action_from_string("close")));
95     menu_add_entry(m, menu_entry_new("Shade",
96                                      action_from_string("toggleshade")));
97     menu_add_entry(m, menu_entry_new("Omnipresent",
98                                      action_from_string("toggleomnipresent")));
99     menu_add_entry(m, menu_entry_new("Decorations",
100                                      action_from_string("toggledecorations")));
101     menu_add_entry(m, menu_entry_new_submenu("Layers",
102                                              layer_menu));
103     layer_menu->parent = m;
104
105     /* send to desktop
106        iconify
107        raise
108        lower
109        close
110        kill
111        shade
112        omnipresent
113        decorations
114     */
115     return (void *)m;
116 }
117
118 void plugin_startup()
119 {
120     Menu *t;
121     /* create a Send To Workspace Menu */
122     send_to_menu = menu_new_full(NULL, "send-to-workspace",
123                           NULL, NULL, client_send_to_update);
124     
125     layer_menu = menu_new(NULL, "layer", NULL);
126     menu_add_entry(layer_menu, menu_entry_new("Top Layer",
127                                      action_from_string("sendtotoplayer")));
128     menu_add_entry(layer_menu, menu_entry_new("Normal Layer",
129                                      action_from_string("sendtonormallayer")));
130     menu_add_entry(layer_menu, menu_entry_new("Bottom Layer",
131                                      action_from_string("sendtobottomlayer")));
132                           
133     t = (Menu *)plugin_create("client_menu");
134 }
135