1 | /* Gnome panel: general applet functionality |
---|
2 | * (C) 1997 the Free Software Foundation |
---|
3 | * |
---|
4 | * Authors: George Lebl |
---|
5 | * Federico Mena |
---|
6 | * Miguel de Icaza |
---|
7 | */ |
---|
8 | |
---|
9 | #include <config.h> |
---|
10 | #include <string.h> |
---|
11 | #include <signal.h> |
---|
12 | #include <gnome.h> |
---|
13 | #include <gdk/gdkx.h> |
---|
14 | |
---|
15 | #include "panel-include.h" |
---|
16 | #include "gnome-panel.h" |
---|
17 | #include "scroll-menu.h" |
---|
18 | |
---|
19 | #define SMALL_ICON_SIZE 20 |
---|
20 | |
---|
21 | #define APPLET_EVENT_MASK (GDK_BUTTON_PRESS_MASK | \ |
---|
22 | GDK_BUTTON_RELEASE_MASK | \ |
---|
23 | GDK_POINTER_MOTION_MASK | \ |
---|
24 | GDK_POINTER_MOTION_HINT_MASK) |
---|
25 | |
---|
26 | extern GSList *panels; |
---|
27 | |
---|
28 | GSList *applets = NULL; |
---|
29 | GSList *applets_last = NULL; |
---|
30 | int applet_count = 0; |
---|
31 | |
---|
32 | /*config sync stuff*/ |
---|
33 | extern int config_sync_timeout; |
---|
34 | extern int applets_to_sync; |
---|
35 | extern int panels_to_sync; |
---|
36 | extern int need_complete_save; |
---|
37 | |
---|
38 | extern gboolean commie_mode; |
---|
39 | extern GlobalConfig global_config; |
---|
40 | extern PanelWidget *current_panel; |
---|
41 | |
---|
42 | static void |
---|
43 | move_applet_callback (GtkWidget *widget, AppletInfo *info) |
---|
44 | { |
---|
45 | PanelWidget *panel; |
---|
46 | |
---|
47 | g_return_if_fail (info != NULL); |
---|
48 | g_return_if_fail (info->widget != NULL); |
---|
49 | g_return_if_fail (info->widget->parent != NULL); |
---|
50 | g_return_if_fail (IS_PANEL_WIDGET (info->widget->parent)); |
---|
51 | |
---|
52 | panel = PANEL_WIDGET (info->widget->parent); |
---|
53 | |
---|
54 | panel_widget_applet_drag_start (panel, info->widget, |
---|
55 | PW_DRAG_OFF_CENTER); |
---|
56 | } |
---|
57 | |
---|
58 | /*destroy widgets and call the above cleanup function*/ |
---|
59 | void |
---|
60 | panel_clean_applet (AppletInfo *info) |
---|
61 | { |
---|
62 | g_return_if_fail (info != NULL); |
---|
63 | |
---|
64 | if (info->widget != NULL) { |
---|
65 | if(info->type == APPLET_STATUS) { |
---|
66 | status_applet_put_offscreen (info->data); |
---|
67 | } |
---|
68 | /* destroy will remove it from the panel */ |
---|
69 | gtk_widget_destroy (info->widget); |
---|
70 | info->widget = NULL; |
---|
71 | } |
---|
72 | |
---|
73 | info->data = NULL; |
---|
74 | } |
---|
75 | |
---|
76 | static gboolean |
---|
77 | kill_applet_in_idle(gpointer data) |
---|
78 | { |
---|
79 | AppletInfo *info = data; |
---|
80 | if (info->type == APPLET_EXTERN) { |
---|
81 | Extern *ext = info->data; |
---|
82 | extern_save_last_position (ext, TRUE /* sync */); |
---|
83 | ext->clean_remove = TRUE; |
---|
84 | } else if (info->type == APPLET_SWALLOW) { |
---|
85 | Swallow *swallow = info->data; |
---|
86 | swallow->clean_remove = TRUE; |
---|
87 | } |
---|
88 | panel_clean_applet (info); |
---|
89 | return FALSE; |
---|
90 | } |
---|
91 | |
---|
92 | static void |
---|
93 | remove_applet_callback(GtkWidget *widget, AppletInfo *info) |
---|
94 | { |
---|
95 | gtk_idle_add (kill_applet_in_idle, info); |
---|
96 | } |
---|
97 | |
---|
98 | static void |
---|
99 | applet_callback_callback(GtkWidget *widget, gpointer data) |
---|
100 | { |
---|
101 | AppletUserMenu *menu = data; |
---|
102 | |
---|
103 | g_return_if_fail(menu->info != NULL); |
---|
104 | |
---|
105 | switch(menu->info->type) { |
---|
106 | case APPLET_EXTERN: |
---|
107 | { |
---|
108 | CORBA_Environment ev; |
---|
109 | Extern *ext = menu->info->data; |
---|
110 | g_assert(ext); |
---|
111 | g_assert(ext->applet); |
---|
112 | |
---|
113 | CORBA_exception_init(&ev); |
---|
114 | GNOME_Applet_do_callback(ext->applet, menu->name, &ev); |
---|
115 | if(ev._major) |
---|
116 | panel_clean_applet(ext->info); |
---|
117 | CORBA_exception_free(&ev); |
---|
118 | break; |
---|
119 | } |
---|
120 | case APPLET_LAUNCHER: |
---|
121 | if(strcmp(menu->name,"properties")==0) |
---|
122 | launcher_properties(menu->info->data); |
---|
123 | else if (strcmp (menu->name, "help") == 0) |
---|
124 | panel_show_help ("launchers.html"); |
---|
125 | else if (strcmp (menu->name, "help_on_app") == 0) { |
---|
126 | Launcher * launcher = menu->info->data; |
---|
127 | if (launcher->dentry != NULL) { |
---|
128 | char *path = panel_gnome_kde_help_path |
---|
129 | (launcher->dentry->docpath); |
---|
130 | if (path != NULL) { |
---|
131 | gnome_url_show (path); |
---|
132 | g_free (path); |
---|
133 | } |
---|
134 | } |
---|
135 | } |
---|
136 | break; |
---|
137 | case APPLET_DRAWER: |
---|
138 | if(strcmp(menu->name,"properties")==0) { |
---|
139 | Drawer *drawer = menu->info->data; |
---|
140 | g_assert(drawer); |
---|
141 | panel_config(drawer->drawer); |
---|
142 | } else if (strcmp (menu->name, "help") == 0) |
---|
143 | panel_show_help ("drawers.html"); |
---|
144 | break; |
---|
145 | case APPLET_SWALLOW: |
---|
146 | if (strcmp (menu->name, "help") == 0) |
---|
147 | panel_show_help ("specialobjects.html#SWALLOWEDAPP"); |
---|
148 | #if 0 |
---|
149 | if(strcmp(menu->name,"properties")==0) { |
---|
150 | Swallow *swallow = info->data; |
---|
151 | g_assert(swallow); |
---|
152 | swallow_properties(swallow); /* doesn't exist yet*/ |
---|
153 | } |
---|
154 | #endif |
---|
155 | break; |
---|
156 | case APPLET_MENU: |
---|
157 | if(strcmp(menu->name,"properties")==0) |
---|
158 | menu_properties(menu->info->data); |
---|
159 | else if(strcmp(menu->name,"edit_menus")==0) { |
---|
160 | char *tmp; |
---|
161 | if((tmp = panel_is_program_in_path("gmenu"))) { |
---|
162 | gnome_execute_async (g_get_home_dir (), 1, &tmp); |
---|
163 | g_free(tmp); |
---|
164 | } |
---|
165 | } else if (strcmp (menu->name, "help") == 0) { |
---|
166 | Menu *menu2 = menu->info->data; |
---|
167 | char *page; |
---|
168 | page = (menu2->path && strcmp (menu2->path,".")) |
---|
169 | ? "menus.html" : "mainmenu.html"; |
---|
170 | panel_show_help (page); |
---|
171 | } |
---|
172 | break; |
---|
173 | case APPLET_LOCK: { |
---|
174 | /* |
---|
175 | <jwz> Blank Screen Now |
---|
176 | <jwz> Lock Screen Now |
---|
177 | <jwz> Kill Daemon |
---|
178 | <jwz> Restart Daemon |
---|
179 | <jwz> Preferences |
---|
180 | <jwz> (or "configuration" instead? whatever word you use) |
---|
181 | <jwz> those should do xscreensaver-command -activate, -lock, -exit... |
---|
182 | <jwz> and "xscreensaver-command -exit ; xscreensaver &" |
---|
183 | <jwz> and "xscreensaver-demo" |
---|
184 | */ |
---|
185 | char *command = NULL; |
---|
186 | gboolean freeit = FALSE; |
---|
187 | if (strcmp (menu->name, "help") == 0) |
---|
188 | panel_show_help ("specialobjects.html#LOCKBUTTON"); |
---|
189 | else if (!strcmp (menu->name, "restart")) { |
---|
190 | command = "xss-command -exit ; xss &"; |
---|
191 | } else if (!strcmp (menu->name, "prefs")) { |
---|
192 | command = "xss-demo"; |
---|
193 | } else { |
---|
194 | command = g_strdup_printf ("xss-command -%s", |
---|
195 | menu->name); |
---|
196 | freeit = TRUE; |
---|
197 | } |
---|
198 | if (command) |
---|
199 | gnome_execute_shell (g_get_home_dir (), command); |
---|
200 | if (freeit) |
---|
201 | g_free (command); |
---|
202 | break; |
---|
203 | } |
---|
204 | case APPLET_LOGOUT: |
---|
205 | if (strcmp (menu->name, "help") == 0) |
---|
206 | panel_show_help ("specialobjects.html#LOGOUTBUTTON"); |
---|
207 | break; |
---|
208 | case APPLET_STATUS: |
---|
209 | if (strcmp (menu->name, "help") == 0) |
---|
210 | panel_show_help ("specialobjects.html#STATUSDOC"); |
---|
211 | break; |
---|
212 | case APPLET_RUN: |
---|
213 | if (strcmp (menu->name, "help") == 0) |
---|
214 | panel_show_help ("specialobjects.html#RUNBUTTON"); |
---|
215 | break; |
---|
216 | default: break; |
---|
217 | } |
---|
218 | } |
---|
219 | |
---|
220 | static void |
---|
221 | applet_menu_deactivate(GtkWidget *w, AppletInfo *info) |
---|
222 | { |
---|
223 | GtkWidget *panel = get_panel_parent(info->widget); |
---|
224 | info->menu_age = 0; |
---|
225 | |
---|
226 | if(IS_BASEP_WIDGET(panel)) |
---|
227 | BASEP_WIDGET(panel)->autohide_inhibit = FALSE; |
---|
228 | } |
---|
229 | |
---|
230 | AppletUserMenu * |
---|
231 | applet_get_callback (GList *user_menu, const char *name) |
---|
232 | { |
---|
233 | GList *li; |
---|
234 | |
---|
235 | for (li = user_menu; li != NULL; li = li->next) { |
---|
236 | AppletUserMenu *menu = li->data; |
---|
237 | if (strcmp (menu->name, name) == 0) |
---|
238 | return menu; |
---|
239 | } |
---|
240 | |
---|
241 | return NULL; |
---|
242 | } |
---|
243 | |
---|
244 | void |
---|
245 | applet_add_callback(AppletInfo *info, |
---|
246 | const char *callback_name, |
---|
247 | const char *stock_item, |
---|
248 | const char *menuitem_text) |
---|
249 | { |
---|
250 | AppletUserMenu *menu; |
---|
251 | |
---|
252 | g_return_if_fail (info != NULL); |
---|
253 | |
---|
254 | menu = applet_get_callback (info->user_menu, callback_name); |
---|
255 | if (menu == NULL) { |
---|
256 | menu = g_new0 (AppletUserMenu, 1); |
---|
257 | menu->name = g_strdup (callback_name); |
---|
258 | menu->stock_item = g_strdup (stock_item); |
---|
259 | menu->text = g_strdup (menuitem_text); |
---|
260 | menu->sensitive = TRUE; |
---|
261 | menu->info = info; |
---|
262 | menu->menuitem = NULL; |
---|
263 | menu->submenu = NULL; |
---|
264 | info->user_menu = g_list_append (info->user_menu, menu); |
---|
265 | } else { |
---|
266 | g_free (menu->stock_item); |
---|
267 | menu->stock_item = NULL; |
---|
268 | g_free (menu->text); |
---|
269 | menu->text = NULL; |
---|
270 | menu->text = g_strdup (menuitem_text); |
---|
271 | menu->stock_item = g_strdup (stock_item); |
---|
272 | } |
---|
273 | |
---|
274 | /*make sure the menu is rebuilt*/ |
---|
275 | if(info->menu) { |
---|
276 | GList *list; |
---|
277 | for(list=info->user_menu;list!=NULL;list=g_list_next(list)) { |
---|
278 | AppletUserMenu *menu = list->data; |
---|
279 | menu->menuitem=NULL; |
---|
280 | menu->submenu=NULL; |
---|
281 | } |
---|
282 | gtk_widget_unref(info->menu); |
---|
283 | info->menu = NULL; |
---|
284 | info->menu_age = 0; |
---|
285 | } |
---|
286 | } |
---|
287 | |
---|
288 | void |
---|
289 | applet_remove_callback(AppletInfo *info, const char *callback_name) |
---|
290 | { |
---|
291 | AppletUserMenu *menu; |
---|
292 | |
---|
293 | g_return_if_fail (info != NULL); |
---|
294 | |
---|
295 | menu = applet_get_callback (info->user_menu, callback_name); |
---|
296 | if (menu != NULL) { |
---|
297 | info->user_menu = g_list_remove (info->user_menu, menu); |
---|
298 | g_free(menu->name); |
---|
299 | menu->name = NULL; |
---|
300 | g_free(menu->stock_item); |
---|
301 | menu->stock_item = NULL; |
---|
302 | g_free(menu->text); |
---|
303 | menu->text = NULL; |
---|
304 | g_free(menu); |
---|
305 | } else |
---|
306 | return; /*it just isn't there*/ |
---|
307 | |
---|
308 | /*make sure the menu is rebuilt*/ |
---|
309 | if (info->menu != NULL) { |
---|
310 | GList *list; |
---|
311 | for (list = info->user_menu; list != NULL; list = list->next) { |
---|
312 | AppletUserMenu *menu = list->data; |
---|
313 | menu->menuitem = NULL; |
---|
314 | menu->submenu = NULL; |
---|
315 | } |
---|
316 | gtk_widget_unref (info->menu); |
---|
317 | info->menu = NULL; |
---|
318 | info->menu_age = 0; |
---|
319 | } |
---|
320 | } |
---|
321 | |
---|
322 | void |
---|
323 | applet_callback_set_sensitive(AppletInfo *info, const char *callback_name, int sensitive) |
---|
324 | { |
---|
325 | AppletUserMenu *menu; |
---|
326 | |
---|
327 | g_return_if_fail(info != NULL); |
---|
328 | |
---|
329 | menu = applet_get_callback(info->user_menu, callback_name); |
---|
330 | if (menu != NULL) |
---|
331 | menu->sensitive = sensitive; |
---|
332 | else |
---|
333 | return; /*it just isn't there*/ |
---|
334 | |
---|
335 | /*make sure the menu is rebuilt*/ |
---|
336 | if(info->menu) { |
---|
337 | GList *list; |
---|
338 | for(list=info->user_menu;list!=NULL;list=g_list_next(list)) { |
---|
339 | AppletUserMenu *menu = list->data; |
---|
340 | menu->menuitem=NULL; |
---|
341 | menu->submenu=NULL; |
---|
342 | } |
---|
343 | gtk_widget_unref(info->menu); |
---|
344 | info->menu = NULL; |
---|
345 | info->menu_age = 0; |
---|
346 | } |
---|
347 | } |
---|
348 | |
---|
349 | static void |
---|
350 | setup_an_item(AppletUserMenu *menu, |
---|
351 | GtkWidget *submenu, |
---|
352 | int is_submenu) |
---|
353 | { |
---|
354 | menu->menuitem = gtk_menu_item_new (); |
---|
355 | gtk_signal_connect (GTK_OBJECT (menu->menuitem), "destroy", |
---|
356 | GTK_SIGNAL_FUNC (gtk_widget_destroyed), |
---|
357 | &menu->menuitem); |
---|
358 | if(menu->stock_item && *(menu->stock_item)) |
---|
359 | setup_menuitem (menu->menuitem, |
---|
360 | gnome_stock_pixmap_widget(submenu, |
---|
361 | menu->stock_item), |
---|
362 | menu->text); |
---|
363 | else |
---|
364 | setup_menuitem (menu->menuitem, |
---|
365 | NULL, |
---|
366 | menu->text); |
---|
367 | |
---|
368 | if(submenu) |
---|
369 | gtk_menu_append (GTK_MENU (submenu), menu->menuitem); |
---|
370 | |
---|
371 | /*if an item not a submenu*/ |
---|
372 | if(!is_submenu) { |
---|
373 | gtk_signal_connect(GTK_OBJECT(menu->menuitem), "activate", |
---|
374 | (GtkSignalFunc) applet_callback_callback, |
---|
375 | menu); |
---|
376 | gtk_signal_connect(GTK_OBJECT (submenu), "destroy", |
---|
377 | GTK_SIGNAL_FUNC (gtk_widget_destroyed), |
---|
378 | &menu->submenu); |
---|
379 | /* if the item is a submenu and doesn't have it's menu |
---|
380 | created yet*/ |
---|
381 | } else if(!menu->submenu) { |
---|
382 | menu->submenu = hack_scroll_menu_new(); |
---|
383 | } |
---|
384 | |
---|
385 | if(menu->submenu) { |
---|
386 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu->menuitem), |
---|
387 | menu->submenu); |
---|
388 | gtk_signal_connect (GTK_OBJECT (menu->submenu), "destroy", |
---|
389 | GTK_SIGNAL_FUNC (gtk_widget_destroyed), |
---|
390 | &menu->submenu); |
---|
391 | } |
---|
392 | |
---|
393 | gtk_widget_set_sensitive(menu->menuitem,menu->sensitive); |
---|
394 | } |
---|
395 | |
---|
396 | static void |
---|
397 | add_to_submenus (AppletInfo *info, |
---|
398 | const char *path, |
---|
399 | const char *name, |
---|
400 | AppletUserMenu *menu, |
---|
401 | GtkWidget *submenu, |
---|
402 | GList *user_menu) |
---|
403 | { |
---|
404 | char *n = g_strdup (name); |
---|
405 | char *p = strchr (n, '/'); |
---|
406 | char *t; |
---|
407 | AppletUserMenu *s_menu; |
---|
408 | |
---|
409 | /*this is the last one*/ |
---|
410 | if (p == NULL) { |
---|
411 | g_free (n); |
---|
412 | setup_an_item (menu, submenu, FALSE); |
---|
413 | return; |
---|
414 | } |
---|
415 | |
---|
416 | /*this is the last one and we are a submenu, we have already been |
---|
417 | set up*/ |
---|
418 | if(p==(n + strlen(n) - 1)) { |
---|
419 | g_free(n); |
---|
420 | return; |
---|
421 | } |
---|
422 | |
---|
423 | *p = '\0'; |
---|
424 | p++; |
---|
425 | |
---|
426 | t = g_strconcat (path, n, "/", NULL); |
---|
427 | s_menu = applet_get_callback (user_menu, t); |
---|
428 | /*the user did not give us this sub menu, whoops, will create an empty |
---|
429 | one then*/ |
---|
430 | if (s_menu == NULL) { |
---|
431 | s_menu = g_new0 (AppletUserMenu,1); |
---|
432 | s_menu->name = g_strdup (t); |
---|
433 | s_menu->stock_item = NULL; |
---|
434 | s_menu->text = g_strdup (_("???")); |
---|
435 | s_menu->sensitive = TRUE; |
---|
436 | s_menu->info = info; |
---|
437 | s_menu->menuitem = NULL; |
---|
438 | s_menu->submenu = NULL; |
---|
439 | info->user_menu = g_list_append (info->user_menu,s_menu); |
---|
440 | user_menu = info->user_menu; |
---|
441 | } |
---|
442 | |
---|
443 | if (s_menu->submenu == NULL) { |
---|
444 | s_menu->submenu = hack_scroll_menu_new(); |
---|
445 | /*a more elegant way to do this should be done |
---|
446 | when I don't want to go to sleep */ |
---|
447 | if (s_menu->menuitem != NULL) { |
---|
448 | gtk_widget_destroy (s_menu->menuitem); |
---|
449 | s_menu->menuitem = NULL; |
---|
450 | } |
---|
451 | } |
---|
452 | if (s_menu->menuitem == NULL) |
---|
453 | setup_an_item (s_menu, submenu, TRUE); |
---|
454 | |
---|
455 | add_to_submenus (info, t, p, menu, s_menu->submenu, user_menu); |
---|
456 | |
---|
457 | g_free(t); |
---|
458 | g_free(n); |
---|
459 | } |
---|
460 | |
---|
461 | void |
---|
462 | create_applet_menu (AppletInfo *info, gboolean is_basep) |
---|
463 | { |
---|
464 | GtkWidget *menuitem, *panel_menu; |
---|
465 | GList *user_menu = info->user_menu; |
---|
466 | gchar *pixmap; |
---|
467 | |
---|
468 | info->menu = hack_scroll_menu_new (); |
---|
469 | |
---|
470 | if ( ! commie_mode) { |
---|
471 | menuitem = gtk_menu_item_new(); |
---|
472 | setup_menuitem(menuitem, |
---|
473 | gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_REMOVE), |
---|
474 | _("Remove from panel")); |
---|
475 | gtk_signal_connect(GTK_OBJECT(menuitem), "activate", |
---|
476 | (GtkSignalFunc) remove_applet_callback, |
---|
477 | info); |
---|
478 | gtk_menu_append(GTK_MENU(info->menu), menuitem); |
---|
479 | |
---|
480 | menuitem = gtk_menu_item_new(); |
---|
481 | setup_menuitem(menuitem,NULL,_("Move")); |
---|
482 | gtk_signal_connect(GTK_OBJECT(menuitem), "activate", |
---|
483 | (GtkSignalFunc) move_applet_callback, |
---|
484 | info); |
---|
485 | gtk_menu_append(GTK_MENU(info->menu), menuitem); |
---|
486 | } |
---|
487 | |
---|
488 | panel_menu = hack_scroll_menu_new(); |
---|
489 | make_panel_submenu (panel_menu, TRUE, is_basep); |
---|
490 | menuitem = gtk_menu_item_new (); |
---|
491 | |
---|
492 | pixmap = gnome_pixmap_file ("gnome-panel.png"); |
---|
493 | if (pixmap == NULL) { |
---|
494 | g_message (_("Cannot find pixmap file %s"), "gnome-panel.png"); |
---|
495 | setup_menuitem (menuitem, NULL, _("Panel")); |
---|
496 | } else { |
---|
497 | setup_menuitem (menuitem, |
---|
498 | gnome_stock_pixmap_widget_at_size (NULL, pixmap, |
---|
499 | SMALL_ICON_SIZE, |
---|
500 | SMALL_ICON_SIZE), |
---|
501 | _("Panel")); |
---|
502 | g_free (pixmap); |
---|
503 | } |
---|
504 | gtk_menu_append (GTK_MENU (info->menu), menuitem); |
---|
505 | gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), panel_menu); |
---|
506 | |
---|
507 | if(user_menu) { |
---|
508 | menuitem = gtk_menu_item_new(); |
---|
509 | gtk_menu_append(GTK_MENU(info->menu), menuitem); |
---|
510 | gtk_widget_set_sensitive (menuitem, FALSE); |
---|
511 | gtk_widget_show(menuitem); |
---|
512 | } |
---|
513 | |
---|
514 | for(;user_menu!=NULL;user_menu = g_list_next(user_menu)) { |
---|
515 | AppletUserMenu *menu=user_menu->data; |
---|
516 | add_to_submenus (info, "", menu->name, menu, info->menu, |
---|
517 | info->user_menu); |
---|
518 | } |
---|
519 | |
---|
520 | /*connect the deactivate signal, so that we can "re-allow" autohide |
---|
521 | when the menu is deactivated*/ |
---|
522 | gtk_signal_connect (GTK_OBJECT (info->menu), "deactivate", |
---|
523 | GTK_SIGNAL_FUNC (applet_menu_deactivate), |
---|
524 | info); |
---|
525 | } |
---|
526 | |
---|
527 | static void |
---|
528 | set_data(GtkWidget *menu, gpointer panel) |
---|
529 | { |
---|
530 | GList *children, *li; |
---|
531 | |
---|
532 | gtk_object_set_data (GTK_OBJECT (menu), "menu_panel", panel); |
---|
533 | |
---|
534 | children = gtk_container_children (GTK_CONTAINER (menu)); |
---|
535 | |
---|
536 | for(li = children; li; li = li->next) { |
---|
537 | GtkMenuItem *item = li->data; |
---|
538 | if (item->submenu != NULL) |
---|
539 | set_data (item->submenu, panel); |
---|
540 | } |
---|
541 | g_list_free (children); |
---|
542 | } |
---|
543 | |
---|
544 | void |
---|
545 | show_applet_menu(AppletInfo *info, GdkEventButton *event) |
---|
546 | { |
---|
547 | GtkWidget *panel; |
---|
548 | |
---|
549 | g_return_if_fail(info!=NULL); |
---|
550 | |
---|
551 | panel = get_panel_parent(info->widget); |
---|
552 | |
---|
553 | if (info->menu == NULL) |
---|
554 | create_applet_menu (info, IS_BASEP_WIDGET (panel)); |
---|
555 | g_assert (info->menu != NULL); |
---|
556 | |
---|
557 | if(IS_BASEP_WIDGET(panel)) { |
---|
558 | BASEP_WIDGET(panel)->autohide_inhibit = TRUE; |
---|
559 | basep_widget_queue_autohide(BASEP_WIDGET(panel)); |
---|
560 | } |
---|
561 | info->menu_age = 0; |
---|
562 | |
---|
563 | set_data (info->menu, info->widget->parent); |
---|
564 | |
---|
565 | gtk_menu_popup (GTK_MENU (info->menu), |
---|
566 | NULL, |
---|
567 | NULL, |
---|
568 | global_config.off_panel_popups ? |
---|
569 | applet_menu_position : |
---|
570 | NULL, |
---|
571 | info, |
---|
572 | event->button, |
---|
573 | event->time); |
---|
574 | } |
---|
575 | |
---|
576 | |
---|
577 | |
---|
578 | static gboolean |
---|
579 | applet_button_press (GtkWidget *widget, GdkEventButton *event, AppletInfo *info) |
---|
580 | { |
---|
581 | if (event->button == 3) { |
---|
582 | if ( ! panel_applet_in_drag) { |
---|
583 | if(info->type == APPLET_SWALLOW) { |
---|
584 | Swallow *swallow = info->data; |
---|
585 | GtkWidget *handle_box = swallow->handle_box; |
---|
586 | if(!GTK_HANDLE_BOX(handle_box)->child_detached) |
---|
587 | show_applet_menu(info, event); |
---|
588 | } else { |
---|
589 | show_applet_menu (info, event); |
---|
590 | } |
---|
591 | } |
---|
592 | } |
---|
593 | /* don't let any button click events to the panel or moving the applets |
---|
594 | * would move the panel */ |
---|
595 | return TRUE; |
---|
596 | } |
---|
597 | |
---|
598 | static GList *launchers_to_kill = NULL; |
---|
599 | |
---|
600 | void |
---|
601 | remove_unused_launchers (void) |
---|
602 | { |
---|
603 | GList *li; |
---|
604 | |
---|
605 | for (li = launchers_to_kill; li != NULL; li = li->next) { |
---|
606 | char *file = li->data; |
---|
607 | li->data = NULL; |
---|
608 | |
---|
609 | unlink (file); |
---|
610 | |
---|
611 | g_free (file); |
---|
612 | } |
---|
613 | |
---|
614 | g_list_free (launchers_to_kill); |
---|
615 | launchers_to_kill = NULL; |
---|
616 | } |
---|
617 | |
---|
618 | static void |
---|
619 | applet_destroy (GtkWidget *w, AppletInfo *info) |
---|
620 | { |
---|
621 | GList *li; |
---|
622 | |
---|
623 | g_return_if_fail (info != NULL); |
---|
624 | |
---|
625 | info->widget = NULL; |
---|
626 | |
---|
627 | if (info->type == APPLET_DRAWER) { |
---|
628 | Drawer *drawer = info->data; |
---|
629 | g_assert(drawer); |
---|
630 | if(drawer->drawer) { |
---|
631 | GtkWidget *dw = drawer->drawer; |
---|
632 | drawer->drawer = NULL; |
---|
633 | PANEL_WIDGET(BASEP_WIDGET(dw)->panel)->master_widget = NULL; |
---|
634 | gtk_widget_destroy(dw); |
---|
635 | } |
---|
636 | } else if (info->type == APPLET_LAUNCHER) { |
---|
637 | Launcher *launcher = info->data; |
---|
638 | |
---|
639 | /* we CAN'T unlink the file here as we may just |
---|
640 | * be killing stuff before exit, basically we |
---|
641 | * just want to schedule removals until session |
---|
642 | * saving */ |
---|
643 | |
---|
644 | if (launcher->dentry->location != NULL) { |
---|
645 | char *file = g_strdup (launcher->dentry->location); |
---|
646 | launchers_to_kill = |
---|
647 | g_list_prepend (launchers_to_kill, file); |
---|
648 | } |
---|
649 | } |
---|
650 | |
---|
651 | |
---|
652 | if (info->menu != NULL) { |
---|
653 | gtk_widget_unref(info->menu); |
---|
654 | info->menu = NULL; |
---|
655 | info->menu_age = 0; |
---|
656 | } |
---|
657 | |
---|
658 | info->type = APPLET_EMPTY; |
---|
659 | |
---|
660 | if (info->data_destroy) |
---|
661 | info->data_destroy (info->data); |
---|
662 | info->data_destroy = NULL; |
---|
663 | info->data = NULL; |
---|
664 | |
---|
665 | /*free the user menu*/ |
---|
666 | for(li = info->user_menu; li != NULL; li = g_list_next(li)) { |
---|
667 | AppletUserMenu *umenu = li->data; |
---|
668 | |
---|
669 | li->data = NULL; |
---|
670 | |
---|
671 | g_free(umenu->name); |
---|
672 | umenu->name = NULL; |
---|
673 | g_free(umenu->stock_item); |
---|
674 | umenu->stock_item = NULL; |
---|
675 | g_free(umenu->text); |
---|
676 | umenu->text = NULL; |
---|
677 | |
---|
678 | g_free(umenu); |
---|
679 | } |
---|
680 | g_list_free (info->user_menu); |
---|
681 | info->user_menu = NULL; |
---|
682 | } |
---|
683 | |
---|
684 | gboolean |
---|
685 | register_toy (GtkWidget *applet, |
---|
686 | gpointer data, |
---|
687 | GDestroyNotify data_destroy, |
---|
688 | PanelWidget *panel, |
---|
689 | int pos, |
---|
690 | gboolean exactpos, |
---|
691 | AppletType type) |
---|
692 | { |
---|
693 | AppletInfo *info; |
---|
694 | int newpos; |
---|
695 | gboolean insert_at_pos; |
---|
696 | |
---|
697 | g_return_val_if_fail (applet != NULL, FALSE); |
---|
698 | g_return_val_if_fail (panel != NULL, FALSE); |
---|
699 | |
---|
700 | if ( ! GTK_WIDGET_NO_WINDOW (applet)) |
---|
701 | gtk_widget_set_events (applet, (gtk_widget_get_events (applet) | |
---|
702 | APPLET_EVENT_MASK) & |
---|
703 | ~( GDK_POINTER_MOTION_MASK | |
---|
704 | GDK_POINTER_MOTION_HINT_MASK)); |
---|
705 | |
---|
706 | info = g_new0 (AppletInfo, 1); |
---|
707 | info->applet_id = applet_count; |
---|
708 | info->type = type; |
---|
709 | info->widget = applet; |
---|
710 | info->menu = NULL; |
---|
711 | info->menu_age = 0; |
---|
712 | info->data = data; |
---|
713 | info->data_destroy = data_destroy; |
---|
714 | info->user_menu = NULL; |
---|
715 | |
---|
716 | gtk_object_set_data (GTK_OBJECT (applet), "applet_info", info); |
---|
717 | |
---|
718 | if (type == APPLET_DRAWER) { |
---|
719 | Drawer *drawer = data; |
---|
720 | PanelWidget *assoc_panel = |
---|
721 | PANEL_WIDGET (BASEP_WIDGET (drawer->drawer)->panel); |
---|
722 | |
---|
723 | gtk_object_set_data (GTK_OBJECT (applet), |
---|
724 | PANEL_APPLET_ASSOC_PANEL_KEY, assoc_panel); |
---|
725 | assoc_panel->master_widget = applet; |
---|
726 | } |
---|
727 | |
---|
728 | gtk_object_set_data (GTK_OBJECT (applet), |
---|
729 | PANEL_APPLET_FORBIDDEN_PANELS, NULL); |
---|
730 | |
---|
731 | if (applets == NULL) { |
---|
732 | applets_last = applets = g_slist_append (NULL, info); |
---|
733 | } else { |
---|
734 | applets_last = g_slist_append (applets_last, info); |
---|
735 | applets_last = applets_last->next; |
---|
736 | } |
---|
737 | applet_count++; |
---|
738 | |
---|
739 | /*we will need to save this applet's config now*/ |
---|
740 | applets_to_sync = TRUE; |
---|
741 | |
---|
742 | /*add at the beginning if pos == -1*/ |
---|
743 | if (pos >= 0) { |
---|
744 | newpos = pos; |
---|
745 | insert_at_pos = FALSE; |
---|
746 | } else { |
---|
747 | newpos = 0; |
---|
748 | insert_at_pos = TRUE; |
---|
749 | } |
---|
750 | /* if exact pos is on then insert at that precise location */ |
---|
751 | if (exactpos) |
---|
752 | insert_at_pos = TRUE; |
---|
753 | |
---|
754 | if (panel_widget_add_full (panel, applet, newpos, TRUE, |
---|
755 | insert_at_pos)==-1) { |
---|
756 | GSList *list; |
---|
757 | for(list = panels; list != NULL; list = g_slist_next(list)) |
---|
758 | if (panel_widget_add_full (panel, applet, 0, |
---|
759 | TRUE, TRUE)!=-1) |
---|
760 | break; |
---|
761 | if(!list) { |
---|
762 | /*can't put it anywhere, clean up*/ |
---|
763 | gtk_widget_destroy(applet); |
---|
764 | info->widget = NULL; |
---|
765 | panel_clean_applet(info); |
---|
766 | g_warning(_("Can't find an empty spot")); |
---|
767 | return FALSE; |
---|
768 | } |
---|
769 | panel = PANEL_WIDGET(list->data); |
---|
770 | } |
---|
771 | |
---|
772 | if(IS_BUTTON_WIDGET (applet) || !GTK_WIDGET_NO_WINDOW(applet)) |
---|
773 | gtk_signal_connect(GTK_OBJECT(applet), |
---|
774 | "button_press_event", |
---|
775 | GTK_SIGNAL_FUNC(applet_button_press), |
---|
776 | info); |
---|
777 | |
---|
778 | gtk_signal_connect(GTK_OBJECT(applet), "destroy", |
---|
779 | GTK_SIGNAL_FUNC(applet_destroy), |
---|
780 | info); |
---|
781 | |
---|
782 | gtk_widget_show_all(applet); |
---|
783 | |
---|
784 | /*gtk_signal_connect (GTK_OBJECT (applet), |
---|
785 | "drag_request_event", |
---|
786 | GTK_SIGNAL_FUNC(panel_dnd_drag_request), |
---|
787 | info); |
---|
788 | |
---|
789 | gtk_widget_dnd_drag_set (GTK_WIDGET(applet), TRUE, |
---|
790 | applet_drag_types, 1);*/ |
---|
791 | |
---|
792 | orientation_change (info, panel); |
---|
793 | size_change (info, panel); |
---|
794 | back_change (info, panel); |
---|
795 | |
---|
796 | return TRUE; |
---|
797 | } |
---|