]> icculus.org git repositories - dana/openbox.git/blob - plugins/menu/client_menu.c
lots of API additions that I didn't forsee until putting it into use.
[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 /* XXX    
51     newy = MAX(client->frame->area.y +
52                client->frame->a_focused_title->area.height + theme_bwidth,
53                y - theme_bwidth);
54 XXX */
55     
56     POINT_SET(self->location, 
57               MIN(x, screen_physical_size.width - self->size.width -
58                   theme_bwidth * 2), 
59               MIN(newy, screen_physical_size.height - self->size.height -
60                   theme_bwidth * 2));
61     XMoveWindow(ob_display, self->frame, self->location.x, self->location.y);
62
63     if (!self->shown) {
64         XMapWindow(ob_display, self->frame);
65         stacking_raise(MENU_AS_WINDOW(self));
66         self->shown = TRUE;
67     } else if (self->shown && self->open_submenu) {
68         menu_hide(self->open_submenu);
69     }
70 }
71
72 void plugin_setup_config() { }
73
74 void plugin_shutdown() { }
75
76 void plugin_destroy (Menu *m)
77 {
78 }
79
80 void *plugin_create() /* TODO: need config */
81 {
82     Menu *m = menu_new_full(NULL, "client-menu", NULL,
83                             client_menu_show, NULL);
84     menu_add_entry(m, menu_entry_new_submenu("Send To Workspace",
85                                              send_to_menu));
86     send_to_menu->parent = m;
87
88     menu_add_entry(m, menu_entry_new("Iconify",
89                                      action_from_string("iconify")));
90     menu_add_entry(m, menu_entry_new("Raise",
91                                      action_from_string("raise")));
92     menu_add_entry(m, menu_entry_new("Lower",
93                                      action_from_string("lower")));
94     menu_add_entry(m, menu_entry_new("Close",
95                                      action_from_string("close")));
96     menu_add_entry(m, menu_entry_new("Shade",
97                                      action_from_string("toggleshade")));
98     menu_add_entry(m, menu_entry_new("Omnipresent",
99                                      action_from_string("toggleomnipresent")));
100     menu_add_entry(m, menu_entry_new("Decorations",
101                                      action_from_string("toggledecorations")));
102     menu_add_entry(m, menu_entry_new_submenu("Layers",
103                                              layer_menu));
104     layer_menu->parent = m;
105
106     /* send to desktop
107        iconify
108        raise
109        lower
110        close
111        kill
112        shade
113        omnipresent
114        decorations
115     */
116     return (void *)m;
117 }
118
119 void plugin_startup()
120 {
121     Menu *t;
122     /* create a Send To Workspace Menu */
123     send_to_menu = menu_new_full(NULL, "send-to-workspace",
124                           NULL, NULL, client_send_to_update);
125     
126     layer_menu = menu_new(NULL, "layer", NULL);
127     menu_add_entry(layer_menu, menu_entry_new("Top Layer",
128                                      action_from_string("sendtotoplayer")));
129     menu_add_entry(layer_menu, menu_entry_new("Normal Layer",
130                                      action_from_string("sendtonormallayer")));
131     menu_add_entry(layer_menu, menu_entry_new("Bottom Layer",
132                                      action_from_string("sendtobottomlayer")));
133                           
134     t = (Menu *)plugin_create("client_menu");
135 }
136