2 * ROX-Filer, filer for the ROX desktop project
3 * Copyright (C) 2006, Thomas Leonard and others (see changelog for details).
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA
20 /* panel.c - code for dealing with panel windows */
30 #include <libxml/parser.h>
42 #include "gui_support.h"
55 #include "pinboard.h" /* For pinboard_get_window() */
57 /* The width of the separator at the inner edge of the panel */
60 /* The gap between panel icons */
61 #define PANEL_ICON_SPACING 8
63 enum {TEXT_BESIDE_ICON
, TEXT_UNDER_ICON
};
65 static gboolean tmp_icon_selected
= FALSE
; /* When dragging */
67 typedef struct _PanelIconClass PanelIconClass
;
68 typedef struct _PanelIcon PanelIcon
;
70 struct _PanelIconClass
{
79 GtkWidget
*widget
; /* The drawing area for the icon */
81 GtkWidget
*socket
; /* For applets */
86 #define PANEL_ICON(obj) GTK_CHECK_CAST((obj), panel_icon_get_type(), PanelIcon)
87 #define IS_PANEL_ICON(obj) \
88 G_TYPE_CHECK_INSTANCE_TYPE((obj), panel_icon_get_type())
90 Panel
*current_panel
[PANEL_NUMBER_OF_SIDES
];
92 /* NULL => Not loading a panel */
93 static Panel
*loading_panel
= NULL
;
95 static GtkWidget
*panel_options_dialog
= NULL
;
97 /* Static prototypes */
98 static int panel_delete(GtkWidget
*widget
, GdkEvent
*event
, Panel
*panel
);
99 static void panel_destroyed(GtkWidget
*widget
, Panel
*panel
);
100 static const char *pan_from_file(gchar
*line
);
101 static gint
icon_button_release(GtkWidget
*widget
,
102 GdkEventButton
*event
,
104 static gint
icon_button_press(GtkWidget
*widget
,
105 GdkEventButton
*event
,
107 static void reposition_panel(GtkWidget
*window
,
108 GtkAllocation
*alloc
, Panel
*panel
);
109 static gint
expose_icon(GtkWidget
*widget
,
110 GdkEventExpose
*event
,
112 static gint
draw_icon(GtkWidget
*widget
,
113 GdkRectangle
*badarea
,
115 static gint
panel_button_release(GtkWidget
*widget
,
116 GdkEventButton
*event
,
118 static gint
panel_button_press(GtkWidget
*widget
,
119 GdkEventButton
*event
,
121 static void panel_post_resize(GtkWidget
*box
,
122 GtkRequisition
*req
, Panel
*panel
);
123 static void drag_set_panel_dest(PanelIcon
*pi
);
124 static void add_uri_list(GtkWidget
*widget
,
125 GdkDragContext
*context
,
128 GtkSelectionData
*selection_data
,
132 static void panel_add_item(Panel
*panel
,
136 const gchar
*shortcut
,
139 static gboolean
panel_drag_motion(GtkWidget
*widget
,
140 GdkDragContext
*context
,
145 static gboolean
insert_drag_motion(GtkWidget
*widget
,
146 GdkDragContext
*context
,
151 static gboolean
drag_motion(GtkWidget
*widget
,
152 GdkDragContext
*context
,
157 static void panel_drag_leave(GtkWidget
*widget
,
158 GdkDragContext
*context
,
161 static void drag_leave(GtkWidget
*widget
,
162 GdkDragContext
*context
,
165 static GtkWidget
*make_insert_frame(Panel
*panel
);
166 static gboolean
enter_icon(GtkWidget
*widget
,
167 GdkEventCrossing
*event
,
169 static gint
icon_motion_event(GtkWidget
*widget
,
170 GdkEventMotion
*event
,
172 static gint
panel_leave_event(GtkWidget
*widget
,
173 GdkEventCrossing
*event
,
175 static gint
panel_motion_event(GtkWidget
*widget
,
176 GdkEventMotion
*event
,
178 static void reposition_icon(PanelIcon
*pi
, int index
);
179 static void start_drag(PanelIcon
*pi
, GdkEventMotion
*event
);
180 static void drag_end(GtkWidget
*widget
,
181 GdkDragContext
*context
,
183 static void perform_action(Panel
*panel
,
185 GdkEventButton
*event
);
186 static void run_applet(PanelIcon
*pi
);
187 static void size_request(GtkWidget
*widget
, GtkRequisition
*req
, PanelIcon
*pi
);
188 static void panel_load_from_xml(Panel
*panel
, xmlDocPtr doc
);
189 static gboolean
draw_panel_edge(GtkWidget
*widget
, GdkEventExpose
*event
,
191 static PanelIcon
*panel_icon_new(Panel
*panel
,
192 const char *pathname
,
194 static GType
panel_icon_get_type(void);
195 static gboolean
panel_want_show_text(PanelIcon
*pi
);
196 static void panel_show_menu(GdkEventButton
*event
, PanelIcon
*pi
, Panel
*panel
);
197 static void panel_style_changed(void);
198 static void motion_may_raise(Panel
*panel
, int x
, int y
);
199 static void panel_update(Panel
*panel
);
200 static GList
*build_monitor_number(Option
*option
,
201 xmlNode
*node
, guchar
*label
);
202 static gboolean
may_autoscroll(Panel
*panel
);
203 static void panel_update_geometry(Panel
*panel
);
204 static gboolean
panel_keep_below(Panel
*panel
, gboolean setting
);
207 static GtkWidget
*dnd_highlight
= NULL
; /* (stops flickering) */
210 #define SHOW_APPS_SMALL 1
212 static Option o_panel_style
;
213 static Option o_panel_width
;
214 static Option o_panel_xinerama
;
215 static Option o_panel_monitor
;
216 static Option o_panel_avoid
;
217 static Option o_panel_is_dock
;
218 static Option o_panel_on_top
;
220 static gint panel_monitor
= -1;
222 static int closing_panel
= 0; /* Don't panel_save; destroying! */
224 /****************************************************************
225 * EXTERNAL INTERFACE *
226 ****************************************************************/
228 void panel_init(void)
230 option_add_int(&o_panel_style
, "panel_style", SHOW_APPS_SMALL
);
231 option_add_int(&o_panel_width
, "panel_width", 52);
233 option_add_int(&o_panel_xinerama
, "panel_xinerama", 0);
234 option_add_int(&o_panel_monitor
, "panel_monitor", 0);
236 option_add_int(&o_panel_avoid
, "panel_avoid", TRUE
);
237 option_add_int(&o_panel_is_dock
, "panel_is_dock", TRUE
);
238 option_add_int(&o_panel_on_top
, "panel_on_top", FALSE
);
240 option_add_notify(panel_style_changed
);
242 option_register_widget("monitor-number", build_monitor_number
);
245 /* Return a free edge for a new panel.
246 * If no edge is free, returns PANEL_BOTTOM.
248 static PanelSide
find_free_side()
250 if (!current_panel
[PANEL_BOTTOM
])
253 if (!current_panel
[PANEL_TOP
])
256 if (!current_panel
[PANEL_LEFT
])
259 if (!current_panel
[PANEL_RIGHT
])
265 /* Returns TRUE and sets *target if the property exists, otherwise returns
266 * FALSE and leaves *target unchanged */
267 static gboolean
get_int_prop(xmlNodePtr node
, const char *name
, int *target
)
269 char *prop
= xmlGetProp(node
, name
);
273 *target
= atoi(prop
);
280 static void set_int_prop(xmlNodePtr node
, const char *name
, int value
)
284 sprintf(prop
, "%d", value
);
285 xmlSetProp(node
, name
, prop
);
288 static void panel_load_options_from_xml(Panel
*panel
, xmlDocPtr doc
)
293 root
= xmlDocGetRootElement(doc
);
294 options
= get_subnode(root
, NULL
, "options");
297 get_int_prop(options
, "style", &panel
->style
);
298 get_int_prop(options
, "width", &panel
->width
);
299 get_int_prop(options
, "avoid", &panel
->avoid
);
300 get_int_prop(options
, "xinerama", &panel
->xinerama
);
301 get_int_prop(options
, "monitor", &panel
->monitor
);
304 static void save_panels(void)
306 char *filename
= choices_find_xdg_path_save("panels",
307 "ROX-Filer", "rox.sourceforge.net", TRUE
);
308 char *tmp
= g_strconcat(filename
, ".new", NULL
);
309 FILE *fp
= fopen(tmp
, "w");
315 for (n
= 0; n
< PANEL_NUMBER_OF_SIDES
; ++n
)
317 if (current_panel
[n
])
318 fprintf(fp
, "%s\n", current_panel
[n
]->name
);
321 if (rename(tmp
, filename
))
322 g_critical(_("Unable to replace '%s'"), filename
);
326 g_critical(_("Unable to save '%s'"), tmp
);
332 /* 'name' may be NULL or "" to remove the panel */
333 Panel
*panel_new(const gchar
*name
, PanelSide side
)
337 GtkWidget
*vp
, *box
, *frame
, *align
;
338 xmlDocPtr panel_doc
= NULL
;
339 gboolean need_resave
= FALSE
;
341 g_return_val_if_fail(side
== PANEL_DEFAULT_SIDE
||
342 (side
>= 0 && side
< PANEL_NUMBER_OF_SIDES
), NULL
);
343 g_return_val_if_fail(loading_panel
== NULL
, NULL
);
345 if (name
&& *name
== '\0')
350 else if (strchr(name
, '/'))
351 load_path
= g_strdup(name
);
356 leaf
= g_strconcat("pan_", name
, NULL
);
357 load_path
= choices_find_xdg_path_load(leaf
, PROJECT
, SITE
);
361 if (load_path
&& access(load_path
, F_OK
) == 0)
366 panel_doc
= xmlParseFile(load_path
);
367 root
= xmlDocGetRootElement(panel_doc
);
369 saved_side
= xmlGetProp(root
, "side");
373 old_side
= panel_name_to_side(saved_side
);
376 if (side
== PANEL_DEFAULT_SIDE
)
378 else if (side
!= old_side
)
385 if (side
== PANEL_DEFAULT_SIDE
)
386 side
= find_free_side();
388 if (current_panel
[side
])
393 gtk_widget_destroy(current_panel
[side
]->window
);
399 if (name
== NULL
|| *name
== '\0')
405 panel
= g_new(Panel
, 1);
406 panel
->name
= g_strdup(name
);
408 panel
->window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
409 panel
->autoscroll_speed
= 0;
411 /* These are fallbacks from legacy global options */
412 panel
->style
= o_panel_style
.int_value
;
413 panel
->width
= o_panel_width
.int_value
;
414 panel
->xinerama
= o_panel_xinerama
.int_value
;
415 panel
->monitor
= o_panel_monitor
.int_value
;
416 panel
->avoid
= o_panel_avoid
.int_value
;
418 /* Now try to load options from this panel's XML */
421 panel_load_options_from_xml(panel
, panel_doc
);
425 /* Otherwise ensure old settings are migrated */
429 panel_update_geometry(panel
);
431 gtk_window_set_resizable(GTK_WINDOW(panel
->window
), FALSE
);
432 gtk_window_set_wmclass(GTK_WINDOW(panel
->window
), "ROX-Panel", PROJECT
);
433 gtk_widget_set_name(panel
->window
, "rox-panel");
434 gtk_widget_set_events(panel
->window
,
435 GDK_BUTTON_PRESS_MASK
| GDK_BUTTON_RELEASE_MASK
|
436 GDK_POINTER_MOTION_MASK
| GDK_LEAVE_NOTIFY_MASK
);
438 /* We make the panel a drop target only so that we can auto-raise! */
439 gtk_drag_dest_set(panel
->window
, 0, NULL
, 0, GDK_ACTION_PRIVATE
);
440 g_signal_connect(panel
->window
, "drag_leave",
441 G_CALLBACK(panel_drag_leave
), panel
);
442 g_signal_connect(panel
->window
, "drag_motion",
443 G_CALLBACK(panel_drag_motion
), panel
);
445 g_signal_connect(panel
->window
, "delete-event",
446 G_CALLBACK(panel_delete
), panel
);
447 g_signal_connect(panel
->window
, "destroy",
448 G_CALLBACK(panel_destroyed
), panel
);
449 g_signal_connect(panel
->window
, "button_press_event",
450 G_CALLBACK(panel_button_press
), panel
);
451 g_signal_connect(panel
->window
, "button_release_event",
452 G_CALLBACK(panel_button_release
), panel
);
453 g_signal_connect(panel
->window
, "motion-notify-event",
454 G_CALLBACK(panel_motion_event
), panel
);
455 g_signal_connect(panel
->window
, "leave-notify-event",
456 G_CALLBACK(panel_leave_event
), panel
);
458 if (panel
->side
== PANEL_RIGHT
)
459 align
= gtk_alignment_new(1.0, 0.0, 0.0, 1.0);
460 else if (panel
->side
== PANEL_BOTTOM
)
461 align
= gtk_alignment_new(0.0, 1.0, 1.0, 0.0);
462 else if (panel
->side
== PANEL_TOP
)
463 align
= gtk_alignment_new(0.0, 0.0, 1.0, 0.0);
465 align
= gtk_alignment_new(0.0, 0.0, 0.0, 1.0);
467 gtk_container_add(GTK_CONTAINER(panel
->window
), align
);
469 vp
= gtk_viewport_new(NULL
, NULL
);
470 gtk_container_set_resize_mode(GTK_CONTAINER(vp
), GTK_RESIZE_PARENT
);
471 gtk_viewport_set_shadow_type(GTK_VIEWPORT(vp
), GTK_SHADOW_NONE
);
472 gtk_container_add(GTK_CONTAINER(align
), vp
);
474 g_signal_connect(align
, "expose-event",
475 G_CALLBACK(draw_panel_edge
), panel
);
477 if (side
== PANEL_TOP
|| side
== PANEL_BOTTOM
)
479 panel
->adj
= gtk_viewport_get_hadjustment(GTK_VIEWPORT(vp
));
480 box
= gtk_hbox_new(FALSE
, 0);
481 panel
->before
= gtk_hbox_new(FALSE
, 0);
482 panel
->after
= gtk_hbox_new(FALSE
, 0);
486 panel
->adj
= gtk_viewport_get_vadjustment(GTK_VIEWPORT(vp
));
487 box
= gtk_vbox_new(FALSE
, 0);
488 panel
->before
= gtk_vbox_new(FALSE
, 0);
489 panel
->after
= gtk_vbox_new(FALSE
, 0);
492 gtk_container_add(GTK_CONTAINER(vp
), box
);
493 gtk_box_pack_start(GTK_BOX(box
), panel
->before
, FALSE
, TRUE
, 0);
494 gtk_box_pack_end(GTK_BOX(box
), panel
->after
, FALSE
, TRUE
, 0);
496 frame
= make_insert_frame(panel
);
497 gtk_box_pack_start(GTK_BOX(box
), frame
, TRUE
, TRUE
, 4);
499 /* This is used so that we can find the middle easily! */
500 panel
->gap
= gtk_event_box_new();
501 gtk_box_pack_start(GTK_BOX(box
), panel
->gap
, FALSE
, FALSE
, 0);
503 frame
= make_insert_frame(panel
);
504 g_object_set_data(G_OBJECT(frame
), "after", "yes");
505 gtk_box_pack_start(GTK_BOX(box
), frame
, TRUE
, TRUE
, 4);
507 if (o_panel_is_dock
.int_value
)
508 gtk_window_set_type_hint(GTK_WINDOW(panel
->window
),
509 GDK_WINDOW_TYPE_HINT_DOCK
);
511 gtk_widget_realize(panel
->window
);
512 make_panel_window(panel
->window
);
513 gtk_window_stick(GTK_WINDOW(panel
->window
));
515 gtk_widget_show_all(align
);
517 loading_panel
= panel
;
520 panel_load_from_xml(panel
, panel_doc
);
521 xmlFreeDoc(panel_doc
);
528 parse_file(load_path
, pan_from_file
);
529 info_message(_("Your old panel file has been "
530 "converted to the new XML format."));
535 /* Don't scare users with an empty panel... */
538 panel_add_item(panel
, "~", "Home", FALSE
, NULL
, NULL
, FALSE
);
540 apps
= pathdup(make_path(app_dir
, ".."));
543 panel_add_item(panel
, apps
, "Apps", FALSE
, NULL
, NULL
, FALSE
);
547 loading_panel
= NULL
;
550 current_panel
[side
] = panel
;
552 gtk_widget_queue_resize(box
);
553 g_signal_connect(panel
->window
, "size-request",
554 G_CALLBACK(panel_post_resize
), panel
);
555 g_signal_connect(panel
->window
, "size-allocate",
556 G_CALLBACK(reposition_panel
), panel
);
559 gdk_window_lower(panel
->window
->window
);
560 gtk_widget_show(panel
->window
);
561 /* This has no effect until after window is showing; GTK+ bug? */
562 if (panel_keep_below(panel
, TRUE
))
566 pinboard
= pinboard_get_window();
567 /* (if pinboard is NULL, will go right to the back) */
568 window_put_just_above(panel
->window
->window
, pinboard
);
576 /* Externally visible function to add an item to a panel */
577 gboolean
panel_add(PanelSide side
,
578 const gchar
*path
, const gchar
*label
, gboolean after
, const gchar
*shortcut
, const gchar
*args
,
581 g_return_val_if_fail(side
>= 0 && side
< PANEL_NUMBER_OF_SIDES
, FALSE
);
583 g_return_val_if_fail(current_panel
[side
] != NULL
, FALSE
);
585 panel_add_item(current_panel
[side
], path
, label
, after
, shortcut
, args
, locked
);
590 /* Add the area covered by the panels to the region */
591 void panel_mark_used(GdkRegion
*used
)
595 for (i
= 0; i
< PANEL_NUMBER_OF_SIDES
; i
++)
597 Panel
*panel
= current_panel
[i
];
603 gdk_window_get_root_origin(panel
->window
->window
,
605 rect
.width
= panel
->window
->allocation
.width
;
606 rect
.height
= panel
->window
->allocation
.height
;
608 gdk_region_union_with_rect(used
, &rect
);
612 /* On xrandr screen size changes, update all panels */
613 void panel_update_size(void)
617 for (i
= 0; i
< PANEL_NUMBER_OF_SIDES
; i
++)
619 if (current_panel
[i
])
621 panel_update_geometry(current_panel
[i
]);
622 reposition_panel(current_panel
[i
]->window
,
623 ¤t_panel
[i
]->window
->allocation
,
625 gtk_widget_queue_resize(current_panel
[i
]->window
);
630 /****************************************************************
631 * INTERNAL FUNCTIONS *
632 ****************************************************************/
634 /* User has tried to close the panel via the window manager - confirm */
635 static int panel_delete(GtkWidget
*widget
, GdkEvent
*event
, Panel
*panel
)
637 return !confirm(_("You have tried to close a panel via the window "
638 "manager - I usually find that this is accidental... "
640 GTK_STOCK_CLOSE
, NULL
);
643 static void panel_destroyed(GtkWidget
*widget
, Panel
*panel
)
645 if (panel_options_dialog
)
647 Panel
*dlg_panel
= g_object_get_data(G_OBJECT(panel_options_dialog
),
650 if (dlg_panel
== panel
)
651 gtk_widget_destroy(panel_options_dialog
);
654 if (current_panel
[panel
->side
] == panel
)
655 current_panel
[panel
->side
] = NULL
;
657 if (panel
->side
== PANEL_TOP
|| panel
->side
== PANEL_BOTTOM
)
659 if (current_panel
[PANEL_RIGHT
])
660 gtk_widget_queue_resize(
661 current_panel
[PANEL_RIGHT
]->window
);
662 if (current_panel
[PANEL_LEFT
])
663 gtk_widget_queue_resize(
664 current_panel
[PANEL_LEFT
]->window
);
667 if (panel
->autoscroll_speed
)
668 g_source_remove(panel
->autoscroll_to
);
676 static void panel_load_side(Panel
*panel
, xmlNodePtr side
, gboolean after
)
679 char *label
, *path
, *shortcut
, *args
, *tmp
;
682 for (node
= side
->xmlChildrenNode
; node
; node
= node
->next
)
684 if (node
->type
!= XML_ELEMENT_NODE
)
686 if (strcmp(node
->name
, "icon") != 0)
689 label
= xmlGetProp(node
, "label");
691 label
= g_strdup("<missing label>");
692 path
= xmlNodeGetContent(node
);
694 path
= g_strdup("<missing path>");
695 shortcut
= xmlGetProp(node
, "shortcut");
696 args
= xmlGetProp(node
, "args");
697 tmp
= xmlGetProp(node
, "locked");
700 locked
= text_to_boolean(tmp
, FALSE
);
706 panel_add_item(panel
, path
, label
, after
, shortcut
, args
, locked
);
715 /* Create one panel icon for each icon in the doc */
716 static void panel_load_from_xml(Panel
*panel
, xmlDocPtr doc
)
720 root
= xmlDocGetRootElement(doc
);
721 panel_load_side(panel
, get_subnode(root
, NULL
, "start"), FALSE
);
722 panel_load_side(panel
, get_subnode(root
, NULL
, "end"), TRUE
);
725 /* Called for each line in the config file while loading a new panel */
726 static const char *pan_from_file(gchar
*line
)
730 g_return_val_if_fail(line
!= NULL
, NULL
);
731 g_return_val_if_fail(loading_panel
!= NULL
, NULL
);
736 sep
= strpbrk(line
, "<>");
738 return _("Missing < or > in panel config file");
741 leaf
= g_strndup(line
, sep
- line
);
745 panel_add_item(loading_panel
, sep
+ 1, leaf
, sep
[0] == '>',
753 static gboolean
icon_pointer_in(GtkWidget
*widget
,
754 GdkEventCrossing
*event
,
757 gtk_widget_set_state(widget
,
758 icon
->selected
? GTK_STATE_SELECTED
: GTK_STATE_PRELIGHT
);
763 static gboolean
icon_pointer_out(GtkWidget
*widget
,
764 GdkEventCrossing
*event
,
767 gtk_widget_set_state(widget
,
768 icon
->selected
? GTK_STATE_SELECTED
: GTK_STATE_NORMAL
);
773 static void panel_icon_destroyed(PanelIcon
*pi
)
775 g_return_if_fail(pi
->widget
!= NULL
);
782 /* Set the tooltip AND hide/show the label */
783 static void panel_icon_set_tip(PanelIcon
*pi
)
787 Icon
*icon
= (Icon
*) pi
;
789 g_return_if_fail(pi
!= NULL
);
793 if (panel_want_show_text(pi
))
794 gtk_widget_show(pi
->label
);
796 gtk_widget_hide(pi
->label
);
802 ai
= appinfo_get(icon
->path
, icon
->item
);
804 if (ai
&& ((node
= xml_get_section(ai
, NULL
, "Summary"))))
807 str
= xmlNodeListGetString(node
->doc
,
808 node
->xmlChildrenNode
, 1);
811 gtk_tooltips_set_tip(tooltips
, pi
->widget
, str
, NULL
);
815 else if ((!panel_want_show_text(pi
)) && !pi
->socket
)
817 if (icon
->item
->leafname
&& icon
->item
->leafname
[0])
818 gtk_tooltips_set_tip(tooltips
, pi
->widget
,
819 icon
->item
->leafname
, NULL
);
822 gtk_tooltips_set_tip(tooltips
, pi
->widget
, NULL
, NULL
);
828 /* Add an icon with this path to the panel. If after is TRUE then the
829 * icon is added to the right/bottom end of the panel.
831 * If name is NULL a suitable name is taken from path.
833 static void panel_add_item(Panel
*panel
,
837 const gchar
*shortcut
,
845 g_return_if_fail(panel
!= NULL
);
846 g_return_if_fail(path
!= NULL
);
848 widget
= gtk_event_box_new();
849 gtk_widget_set_events(widget
,
850 GDK_BUTTON1_MOTION_MASK
| GDK_BUTTON2_MOTION_MASK
|
851 GDK_BUTTON3_MOTION_MASK
|
852 GDK_EXPOSURE_MASK
| GDK_BUTTON_PRESS_MASK
|
853 GDK_BUTTON_RELEASE_MASK
);
855 gtk_box_pack_start(GTK_BOX(after
? panel
->after
: panel
->before
),
856 widget
, FALSE
, TRUE
, 0);
858 gtk_box_reorder_child(GTK_BOX(panel
->after
), widget
, 0);
860 gtk_widget_realize(widget
);
862 pi
= panel_icon_new(panel
, path
, name
);
865 /* Widget takes the initial ref of Icon */
866 g_object_set_data(G_OBJECT(widget
), "icon", pi
);
869 g_object_ref(widget
);
871 gtk_widget_set_name(pi
->widget
, "panel-icon");
873 g_signal_connect_swapped(widget
, "destroy",
874 G_CALLBACK(panel_icon_destroyed
), pi
);
876 if (icon
->item
->base_type
== TYPE_DIRECTORY
)
879 g_signal_connect(widget
, "button_release_event",
880 G_CALLBACK(icon_button_release
), pi
);
881 g_signal_connect(widget
, "button_press_event",
882 G_CALLBACK(icon_button_press
), pi
);
883 g_signal_connect(widget
, "motion-notify-event",
884 G_CALLBACK(icon_motion_event
), pi
);
885 g_signal_connect(widget
, "enter-notify-event",
886 G_CALLBACK(icon_pointer_in
), pi
);
887 g_signal_connect(widget
, "leave-notify-event",
888 G_CALLBACK(icon_pointer_out
), pi
);
892 g_signal_connect(widget
, "enter-notify-event",
893 G_CALLBACK(enter_icon
), pi
);
894 g_signal_connect_after(widget
, "expose_event",
895 G_CALLBACK(expose_icon
), pi
);
896 g_signal_connect(widget
, "drag_data_get",
897 G_CALLBACK(drag_data_get
), NULL
);
899 g_signal_connect(widget
, "size_request",
900 G_CALLBACK(size_request
), pi
);
902 drag_set_panel_dest(pi
);
904 pi
->label
= gtk_label_new(icon
->item
->leafname
);
905 gtk_container_add(GTK_CONTAINER(pi
->widget
), pi
->label
);
906 gtk_misc_set_alignment(GTK_MISC(pi
->label
), 0.5, 1);
907 gtk_misc_set_padding(GTK_MISC(pi
->label
), 1, 2);
910 icon_set_shortcut(icon
, shortcut
);
911 icon_set_arguments(icon
, args
);
912 icon
->locked
= locked
;
917 panel_icon_set_tip(pi
);
918 gtk_widget_show(widget
);
921 static gboolean
remove_item_from_side(GtkWidget
*container
, const gchar
*path
,
925 gboolean found
= FALSE
;
927 kids
= gtk_container_get_children(GTK_CONTAINER(container
));
929 for (next
= kids
; next
; next
= next
->next
)
932 icon
= g_object_get_data(G_OBJECT(next
->data
), "icon");
936 if ((!path
|| strcmp(path
, icon
->src_path
) == 0) &&
937 (!label
|| strcmp(label
, icon
->item
->leafname
)==0))
939 icon
->locked
= FALSE
;
951 /* Remove an item with this path. If more than one item matches, only
952 * one is removed. If label is not NULL then it must also match the item.
953 * Returns TRUE if an item was successfully removed.
955 gboolean
panel_remove_item(PanelSide side
, const gchar
*path
,
960 g_return_val_if_fail(side
>= 0 && side
< PANEL_NUMBER_OF_SIDES
, FALSE
);
962 g_return_val_if_fail(path
!= NULL
|| label
!= NULL
, FALSE
);
964 panel
= current_panel
[side
];
967 g_warning("No panel on this side of the screen!");
971 if (remove_item_from_side(panel
->before
, path
, label
) ||
972 remove_item_from_side(panel
->after
, path
, label
))
979 g_warning("Panel item path='%s', label='%s' not found", path
, label
);
983 /* Called when Gtk+ wants to know how much space an icon needs.
984 * 'req' is already big enough for the label, if shown.
986 static void size_request(GtkWidget
*widget
, GtkRequisition
*req
, PanelIcon
*pi
)
988 Icon
*icon
= (Icon
*) pi
;
989 gboolean horz
= (pi
->panel
->side
== PANEL_TOP
||
990 pi
->panel
->side
== PANEL_BOTTOM
);
992 int max_height
= 100;
993 int image_width
, image_height
;
994 Panel
*panel
= pi
->panel
;
997 max_height
= panel
->width
- req
->height
;
999 max_width
= MAX(panel
->width
, req
->width
);
1001 /* TODO: really need to recreate? */
1003 g_object_unref(pi
->image
);
1005 pi
->image
= scale_pixbuf(di_image(icon
->item
)->src_pixbuf
,
1006 MAX(20, max_width
), MAX(20, max_height
));
1008 image_width
= gdk_pixbuf_get_width(pi
->image
);
1009 image_height
= gdk_pixbuf_get_height(pi
->image
);
1011 if (req
->height
> 0 && max_height
< req
->height
)
1013 pi
->style
= TEXT_BESIDE_ICON
;
1014 req
->width
+= image_width
;
1015 req
->height
= MAX(req
->height
, image_height
);
1016 gtk_misc_set_alignment(GTK_MISC(pi
->label
), 1, 0.5);
1020 pi
->style
= TEXT_UNDER_ICON
;
1021 req
->width
= MAX(req
->width
, image_width
);
1022 req
->height
+= image_height
;
1023 gtk_misc_set_alignment(GTK_MISC(pi
->label
), 0.5, 1);
1027 req
->width
+= PANEL_ICON_SPACING
;
1029 req
->height
+= PANEL_ICON_SPACING
;
1032 static gint
expose_icon(GtkWidget
*widget
,
1033 GdkEventExpose
*event
,
1036 return draw_icon(widget
, &event
->area
, pi
);
1039 static gint
draw_icon(GtkWidget
*widget
, GdkRectangle
*badarea
, PanelIcon
*pi
)
1043 Icon
*icon
= (Icon
*) pi
;
1047 int text_height
= 0;
1049 gdk_drawable_get_size(widget
->window
, &area
.width
, &area
.height
);
1051 if (panel_want_show_text(pi
))
1052 text_height
= pi
->label
->requisition
.height
;
1054 g_return_val_if_fail(pi
->image
!= NULL
, FALSE
);
1058 width
= gdk_pixbuf_get_width(image
);
1059 height
= gdk_pixbuf_get_height(image
);
1061 if (pi
->style
== TEXT_UNDER_ICON
)
1063 image_x
= (area
.width
- width
) >> 1;
1064 image_y
= (area
.height
- height
- text_height
) >> 1;
1068 image_x
= PANEL_ICON_SPACING
- 2;
1069 image_y
= (area
.height
- height
) >> 1;
1072 gdk_pixbuf_render_to_drawable_alpha(
1076 image_x
, image_y
, /* dest */
1078 GDK_PIXBUF_ALPHA_FULL
, 128, /* (unused) */
1079 GDK_RGB_DITHER_NORMAL
, 0, 0);
1081 if (icon
->item
->flags
& ITEM_FLAG_SYMLINK
)
1083 draw_emblem_on_icon(widget
->window
, widget
->style
,
1084 ROX_STOCK_SYMLINK
, &image_x
, image_y
+2);
1086 if (icon
->item
->flags
& ITEM_FLAG_MOUNT_POINT
)
1088 draw_emblem_on_icon(widget
->window
, widget
->style
,
1089 icon
->item
->flags
& ITEM_FLAG_MOUNTED
1092 &image_x
, image_y
+2);
1097 static void panel_icon_wink(Icon
*icon
)
1099 PanelIcon
*pi
= (PanelIcon
*) icon
;
1101 wink_widget(pi
->widget
);
1104 /* icon may be NULL if the event is on the background */
1105 static void perform_action(Panel
*panel
, PanelIcon
*pi
, GdkEventButton
*event
)
1108 Icon
*icon
= (Icon
*) pi
;
1110 action
= bind_lookup_bev(icon
? BIND_PANEL_ICON
: BIND_PANEL
, event
);
1112 if (pi
&& pi
->socket
)
1113 if (action
!= ACT_POPUP_MENU
&& action
!= ACT_MOVE_ICON
)
1119 dnd_motion_ungrab();
1120 wink_widget(pi
->widget
);
1124 dnd_motion_ungrab();
1125 wink_widget(pi
->widget
);
1126 run_diritem(icon
->path
, icon
->item
, NULL
, NULL
, TRUE
);
1128 case ACT_POPUP_MENU
:
1129 dnd_motion_ungrab();
1130 panel_show_menu(event
, pi
, panel
);
1133 dnd_motion_start(MOTION_REPOSITION
);
1135 case ACT_PRIME_AND_SELECT
:
1136 if (!icon
->selected
)
1137 icon_select_only(icon
);
1138 dnd_motion_start(MOTION_READY_FOR_DND
);
1140 case ACT_PRIME_AND_TOGGLE
:
1141 icon_set_selected(icon
, !icon
->selected
);
1142 dnd_motion_start(MOTION_READY_FOR_DND
);
1144 case ACT_PRIME_FOR_DND
:
1145 dnd_motion_start(MOTION_READY_FOR_DND
);
1147 case ACT_TOGGLE_SELECTED
:
1148 icon_set_selected(icon
, !icon
->selected
);
1150 case ACT_SELECT_EXCL
:
1151 icon_set_selected(icon
, TRUE
);
1155 case ACT_CLEAR_SELECTION
:
1156 dnd_motion_ungrab();
1157 icon_select_only(NULL
);
1160 g_warning("Unsupported action : %d\n", action
);
1165 static gint
panel_button_release(GtkWidget
*widget
,
1166 GdkEventButton
*event
,
1169 if (dnd_motion_release(event
))
1172 perform_action(panel
, NULL
, event
);
1177 static gint
panel_button_press(GtkWidget
*widget
,
1178 GdkEventButton
*event
,
1181 if (dnd_motion_press(panel
->window
, event
))
1182 perform_action(panel
, NULL
, event
);
1187 static gint
icon_button_release(GtkWidget
*widget
,
1188 GdkEventButton
*event
,
1191 if (pi
->socket
&& event
->button
== 1)
1192 return FALSE
; /* Restart button */
1194 if (dnd_motion_release(event
))
1197 perform_action(pi
->panel
, pi
, event
);
1202 static gint
icon_button_press(GtkWidget
*widget
,
1203 GdkEventButton
*event
,
1206 if (pi
->socket
&& event
->button
== 1)
1207 return FALSE
; /* Restart button */
1209 if (dnd_motion_press(widget
, event
))
1210 perform_action(pi
->panel
, pi
, event
);
1215 /* Stop windows from maximising over all/part of us */
1216 static void panel_setup_struts(Panel
*panel
, GtkAllocation
*alloc
)
1220 gulong left
, right
, top
, bottom
;
1221 gulong left_start_y
, left_end_y
;
1222 gulong right_start_y
, right_end_y
;
1223 gulong top_start_x
, top_end_x
;
1224 gulong bottom_start_x
, bottom_end_x
;
1225 } strut
= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1227 if (panel
->avoid
== FALSE
)
1229 else if (panel
->side
== PANEL_TOP
||
1230 panel
->side
== PANEL_BOTTOM
)
1231 thickness
= alloc
->height
;
1233 thickness
= alloc
->width
;
1235 switch (panel
->side
)
1238 if (!panel
->xinerama
|| !monitor_adjacent
[panel
->monitor
].left
)
1240 strut
.left
= panel
->geometry
.x
+ thickness
;
1241 strut
.left_start_y
= panel
->geometry
.y
;
1242 strut
.left_end_y
= panel
->geometry
.y
+
1243 panel
->geometry
.height
- 1;
1245 /* else there is (part of) a monitor
1253 if (!panel
->xinerama
|| !monitor_adjacent
[panel
->monitor
].right
)
1255 /* RHS of monitor might not abut edge
1256 * of total virtual screen */
1257 strut
.right
= screen_width
-
1259 panel
->geometry
.width
+
1261 strut
.right_start_y
= panel
->geometry
.y
;
1262 strut
.right_end_y
= panel
->geometry
.y
+
1263 panel
->geometry
.height
- 1;
1265 /* else there is (part of) a monitor
1273 if (!panel
->xinerama
|| !monitor_adjacent
[panel
->monitor
].top
)
1275 strut
.top
= panel
->geometry
.y
+ thickness
;
1276 strut
.top_start_x
= panel
->geometry
.x
;
1277 strut
.top_end_x
= panel
->geometry
.x
+
1278 panel
->geometry
.width
- 1;
1280 /* else there is (part of) a monitor above */
1286 default: /* PANEL_BOTTOM */
1287 if (!panel
->xinerama
||
1288 !monitor_adjacent
[panel
->monitor
].bottom
)
1290 /* Bottom of monitor might not abut
1291 * edge of total virtual screen */
1292 strut
.bottom
= screen_height
-
1294 panel
->geometry
.height
+
1296 strut
.bottom_start_x
= panel
->geometry
.x
;
1297 strut
.bottom_end_x
= panel
->geometry
.x
+
1298 panel
->geometry
.width
- 1;
1300 /* else there is (part of) a monitor below */
1310 /* Set full-width strut as well as partial in case
1311 * partial isn't supported by wm */
1312 gdk_property_change(panel
->window
->window
,
1313 gdk_atom_intern("_NET_WM_STRUT",
1315 gdk_atom_intern("CARDINAL", FALSE
),
1316 32, GDK_PROP_MODE_REPLACE
,
1317 (gchar
*) &strut
, 4);
1318 gdk_property_change(panel
->window
->window
,
1319 gdk_atom_intern("_NET_WM_STRUT_PARTIAL",
1321 gdk_atom_intern("CARDINAL", FALSE
),
1322 32, GDK_PROP_MODE_REPLACE
,
1323 (gchar
*) &strut
, 12);
1327 gdk_property_delete(panel
->window
->window
,
1328 gdk_atom_intern("_NET_WM_STRUT_PARTIAL",
1330 gdk_property_delete(panel
->window
->window
,
1331 gdk_atom_intern("_NET_WM_STRUT",
1336 static void reposition_panel(GtkWidget
*window
,
1337 GtkAllocation
*alloc
, Panel
*panel
)
1339 int x
= panel
->geometry
.x
;
1340 int y
= panel
->geometry
.y
;
1341 PanelSide side
= panel
->side
;
1343 if (side
== PANEL_LEFT
|| side
== PANEL_RIGHT
)
1345 if (side
== PANEL_RIGHT
)
1346 x
+= panel
->geometry
.width
- alloc
->width
;
1348 if (current_panel
[PANEL_TOP
])
1350 GtkWidget
*win
= current_panel
[PANEL_TOP
]->window
;
1351 y
+= win
->allocation
.height
;
1355 if (side
== PANEL_BOTTOM
)
1356 y
+= panel
->geometry
.height
- alloc
->height
;
1358 gtk_window_move(GTK_WINDOW(panel
->window
), x
, y
);
1359 gdk_window_move(panel
->window
->window
, x
, y
);
1361 if (side
== PANEL_BOTTOM
|| side
== PANEL_TOP
)
1363 if (current_panel
[PANEL_RIGHT
])
1364 gtk_widget_queue_resize(
1365 current_panel
[PANEL_RIGHT
]->window
);
1366 if (current_panel
[PANEL_LEFT
])
1367 gtk_widget_queue_resize(
1368 current_panel
[PANEL_LEFT
]->window
);
1371 panel_setup_struts(panel
, alloc
);
1374 /* Same as drag_set_dest(), but for panel icons */
1375 static void drag_set_panel_dest(PanelIcon
*pi
)
1377 GtkWidget
*obj
= pi
->widget
;
1379 make_drop_target(pi
->widget
, 0);
1381 g_signal_connect(obj
, "drag_motion", G_CALLBACK(drag_motion
), pi
);
1382 g_signal_connect(obj
, "drag_leave", G_CALLBACK(drag_leave
), pi
);
1383 g_signal_connect(obj
, "drag_end", G_CALLBACK(drag_end
), pi
);
1386 static gboolean
drag_motion(GtkWidget
*widget
,
1387 GdkDragContext
*context
,
1393 GdkDragAction action
= context
->suggested_action
;
1394 const char *type
= NULL
;
1395 Icon
*icon
= (Icon
*) pi
;
1396 DirItem
*item
= icon
->item
;
1397 int panel_x
, panel_y
;
1399 gdk_window_get_pointer(pi
->panel
->window
->window
,
1400 &panel_x
, &panel_y
, NULL
);
1401 motion_may_raise(pi
->panel
, panel_x
, panel_y
);
1403 /* Should we scroll the panel when dragging? */
1404 if (motion_state
!= MOTION_REPOSITION
)
1405 if (pi
->panel
->autoscroll_speed
== 0)
1406 may_autoscroll(pi
->panel
);
1409 goto out
; /* Can't drag a selection to itself */
1411 type
= dnd_motion_item(context
, &item
);
1413 if ((context
->actions
& GDK_ACTION_ASK
) && o_dnd_left_menu
.int_value
1414 && type
!= drop_dest_prog
)
1417 gdk_window_get_pointer(NULL
, NULL
, NULL
, &state
);
1418 if (state
& GDK_BUTTON1_MASK
)
1419 action
= GDK_ACTION_ASK
;
1425 /* We actually must pretend to accept the drop, even if the
1426 * directory isn't writeable, so that the spring-opening
1430 /* Don't allow drops to non-writeable directories */
1431 if (o_dnd_spring_open
.int_value
== FALSE
&&
1432 type
== drop_dest_dir
&&
1433 access(icon
->path
, W_OK
) != 0)
1438 g_dataset_set_data(context
, "drop_dest_type", (gpointer
) type
);
1441 gdk_drag_status(context
, action
, time
);
1442 g_dataset_set_data_full(context
, "drop_dest_path",
1443 g_strdup(icon
->path
), g_free
);
1444 if (type
== drop_dest_dir
)
1445 dnd_spring_load(context
, NULL
);
1447 if (dnd_highlight
&& dnd_highlight
!= pi
->widget
)
1449 gtk_drag_unhighlight(dnd_highlight
);
1450 dnd_highlight
= NULL
;
1453 if (dnd_highlight
== NULL
)
1455 gtk_drag_highlight(pi
->widget
);
1456 dnd_highlight
= pi
->widget
;
1460 return type
!= NULL
;
1464 static void add_uri_list(GtkWidget
*widget
,
1465 GdkDragContext
*context
,
1468 GtkSelectionData
*selection_data
,
1473 gboolean after
= FALSE
;
1476 if (!selection_data
->data
)
1479 g_return_if_fail(selection_data
->data
[selection_data
->length
] == '\0');
1481 if (g_object_get_data(G_OBJECT(widget
), "after"))
1484 uris
= uri_list_to_glist(selection_data
->data
);
1486 for (next
= uris
; next
; next
= next
->next
)
1490 path
= get_local_path((EscapedPath
*) next
->data
);
1493 panel_add_item(panel
, path
, NULL
, after
, NULL
, NULL
, FALSE
);
1501 static void drag_end(GtkWidget
*widget
,
1502 GdkDragContext
*context
,
1505 if (tmp_icon_selected
)
1507 icon_select_only(NULL
);
1508 tmp_icon_selected
= FALSE
;
1512 static void drag_leave(GtkWidget
*widget
,
1513 GdkDragContext
*context
,
1517 panel_drag_leave(widget
, context
, time
, ((PanelIcon
*) icon
)->panel
);
1519 if (dnd_highlight
&& dnd_highlight
== widget
)
1521 gtk_drag_unhighlight(dnd_highlight
);
1522 dnd_highlight
= NULL
;
1528 /* Create XML icon nodes for these widgets.
1529 * Always frees the widgets list.
1531 static void make_widgets(xmlNodePtr side
, GList
*widgets
)
1535 for (next
= widgets
; next
; next
= next
->next
)
1540 icon
= g_object_get_data(G_OBJECT(next
->data
), "icon");
1544 g_warning("Can't find Icon from widget\n");
1548 tree
= xmlNewTextChild(side
, NULL
, "icon", icon
->src_path
);
1550 xmlSetProp(tree
, "label", icon
->item
->leafname
);
1552 xmlSetProp(tree
, "shortcut", icon
->shortcut
);
1554 xmlSetProp(tree
, "args", icon
->args
);
1556 xmlSetProp(tree
, "locked", "true");
1560 g_list_free(widgets
);
1563 void panel_save(Panel
*panel
)
1568 guchar
*save
= NULL
;
1569 guchar
*save_new
= NULL
;
1571 g_return_if_fail(panel
!= NULL
);
1573 if (strchr(panel
->name
, '/'))
1574 save
= g_strdup(panel
->name
);
1579 leaf
= g_strconcat("pan_", panel
->name
, NULL
);
1580 save
= choices_find_xdg_path_save(leaf
, PROJECT
, SITE
, TRUE
);
1587 doc
= xmlNewDoc("1.0");
1588 xmlDocSetRootElement(doc
, xmlNewDocNode(doc
, NULL
, "panel", NULL
));
1590 root
= xmlDocGetRootElement(doc
);
1592 xmlSetProp(root
, "side", panel_side_to_name(panel
->side
));
1594 options
= xmlNewChild(root
, NULL
, "options", NULL
);
1595 set_int_prop(options
, "style", panel
->style
);
1596 set_int_prop(options
, "width", panel
->width
);
1597 set_int_prop(options
, "avoid", panel
->avoid
);
1598 set_int_prop(options
, "xinerama", panel
->xinerama
);
1599 set_int_prop(options
, "monitor", panel
->monitor
);
1601 make_widgets(xmlNewChild(root
, NULL
, "start", NULL
),
1602 gtk_container_get_children(GTK_CONTAINER(panel
->before
)));
1604 make_widgets(xmlNewChild(root
, NULL
, "end", NULL
),
1605 g_list_reverse(gtk_container_get_children(
1606 GTK_CONTAINER(panel
->after
))));
1608 save_new
= g_strconcat(save
, ".new", NULL
);
1609 if (save_xml_file(doc
, save_new
) || rename(save_new
, save
))
1610 delayed_error(_("Error saving panel %s: %s"),
1611 save
, g_strerror(errno
));
1619 /* Create a frame widget which can be used to add icons to the panel */
1620 static GtkWidget
*make_insert_frame(Panel
*panel
)
1623 GtkTargetEntry target_table
[] = {
1624 {"text/uri-list", 0, TARGET_URI_LIST
},
1627 frame
= gtk_frame_new(NULL
);
1628 gtk_frame_set_shadow_type(GTK_FRAME(frame
), GTK_SHADOW_NONE
);
1629 gtk_widget_set_size_request(frame
, 16, 16);
1631 g_signal_connect(frame
, "drag-motion",
1632 G_CALLBACK(insert_drag_motion
), panel
);
1633 g_signal_connect(frame
, "drag-leave",
1634 G_CALLBACK(panel_drag_leave
), panel
);
1636 g_signal_connect(frame
, "drag-data-received",
1637 G_CALLBACK(add_uri_list
), panel
);
1638 gtk_drag_dest_set(frame
,
1639 GTK_DEST_DEFAULT_ALL
,
1641 sizeof(target_table
) / sizeof(*target_table
),
1647 static gboolean
enter_icon(GtkWidget
*widget
,
1648 GdkEventCrossing
*event
,
1651 icon_may_update(icon
);
1652 panel_icon_set_tip((PanelIcon
*) icon
);
1657 static gint
panel_leave_event(GtkWidget
*widget
,
1658 GdkEventCrossing
*event
,
1661 GdkWindow
*pinboard
;
1663 if (event
->mode
!= GDK_CROSSING_NORMAL
)
1664 return FALSE
; /* Grab for menu, DnD, etc */
1666 if (panel_keep_below(panel
, TRUE
))
1668 /* Shouldn't need this as well as keep_below but some WMs don't
1669 * automatically lower as soon as the hint is set */
1670 pinboard
= pinboard_get_window();
1671 window_put_just_above(panel
->window
->window
, pinboard
);
1677 /* If (x, y) is at the edge of the panel then raise */
1678 static void motion_may_raise(Panel
*panel
, int x
, int y
)
1682 if (panel
->side
== PANEL_TOP
)
1684 else if (panel
->side
== PANEL_BOTTOM
)
1685 raise
= y
== panel
->window
->allocation
.height
- 1;
1686 else if (panel
->side
== PANEL_LEFT
)
1689 raise
= x
== panel
->window
->allocation
.width
- 1;
1691 if (raise
&& panel_keep_below(panel
, FALSE
))
1693 /* Shouldn't need this as well as keep_below but some WMs don't
1694 * automatically raise as soon as the hint is set */
1695 gdk_window_raise(panel
->window
->window
);
1699 static gboolean
may_autoscroll(Panel
*panel
)
1701 gboolean horz
= panel
->side
== PANEL_TOP
|| panel
->side
== PANEL_BOTTOM
;
1702 gint max
, panel_x
, panel_y
, delta
, new;
1704 if (panel
->adj
->upper
<= panel
->adj
->page_size
)
1705 goto stop_scrolling
; /* Can see everything already */
1707 gdk_window_get_pointer(panel
->window
->window
, &panel_x
, &panel_y
, NULL
);
1712 max
= panel
->window
->allocation
.width
;
1713 if (panel_y
< 0 || panel_y
> panel
->window
->allocation
.height
)
1714 goto stop_scrolling
; /* Not over the panel */
1719 max
= panel
->window
->allocation
.height
;
1720 if (panel_x
< 0 || panel_x
> panel
->window
->allocation
.width
)
1721 goto stop_scrolling
; /* Not over the panel */
1724 if (delta
>= 20 && delta
<= max
- 20)
1725 goto stop_scrolling
; /* Not at either end */
1727 panel
->autoscroll_speed
= MIN(panel
->autoscroll_speed
+ 2, 200);
1729 new = panel
->adj
->value
- ((delta
< 20) ? panel
->autoscroll_speed
1730 : -panel
->autoscroll_speed
);
1731 new = CLAMP(new, 0, panel
->adj
->upper
- panel
->adj
->page_size
);
1732 gtk_adjustment_set_value(panel
->adj
, new);
1734 panel
->autoscroll_to
= g_timeout_add(40,
1735 (GSourceFunc
) may_autoscroll
, panel
);
1740 panel
->autoscroll_speed
= 0;
1744 static gint
panel_motion_event(GtkWidget
*widget
,
1745 GdkEventMotion
*event
,
1748 motion_may_raise(panel
, event
->x
, event
->y
);
1750 if (motion_state
!= MOTION_REPOSITION
)
1751 if (panel
->autoscroll_speed
== 0)
1752 may_autoscroll(panel
);
1757 static gint
icon_motion_event(GtkWidget
*widget
,
1758 GdkEventMotion
*event
,
1761 Panel
*panel
= pi
->panel
;
1763 gboolean horz
= panel
->side
== PANEL_TOP
|| panel
->side
== PANEL_BOTTOM
;
1767 if (motion_state
== MOTION_READY_FOR_DND
)
1769 if (dnd_motion_moved(event
))
1770 start_drag(pi
, event
);
1773 else if (motion_state
!= MOTION_REPOSITION
)
1776 list
= gtk_container_get_children(GTK_CONTAINER(panel
->before
));
1777 list
= g_list_append(list
, NULL
); /* The gap in the middle */
1778 list
= g_list_concat(list
,
1779 gtk_container_get_children(GTK_CONTAINER(panel
->after
)));
1780 me
= g_list_find(list
, widget
);
1782 g_return_val_if_fail(me
!= NULL
, TRUE
);
1784 val
= horz
? event
->x_root
: event
->y_root
;
1792 prev
= GTK_WIDGET(me
->prev
->data
);
1796 gdk_window_get_origin(prev
->window
, &x
, &y
);
1798 if (val
<= (horz
? x
: y
))
1802 if (dir
== 0 && me
->next
)
1808 next
= GTK_WIDGET(me
->next
->data
);
1812 gdk_window_get_origin(next
->window
, &x
, &y
);
1814 gdk_drawable_get_size(next
->window
, &w
, &h
);
1819 if (val
>= (horz
? x
: y
)-1)
1821 if (next
== panel
->gap
)
1829 reposition_icon(pi
, g_list_index(list
, widget
) + dir
);
1834 static void reposition_icon_on_side(GtkWidget
*side
, GtkWidget
*widget
,
1839 list
= gtk_container_get_children(GTK_CONTAINER(side
));
1841 /* Want to move icon to the list in the given 'side'. Is it there
1845 if (!g_list_find(list
, widget
))
1848 gtk_grab_remove(widget
);
1849 gtk_widget_reparent(widget
, side
);
1850 dnd_motion_grab_pointer();
1851 gtk_grab_add(widget
);
1854 gtk_box_reorder_child(GTK_BOX(side
), widget
, index
);
1859 /* Move icon to this index in the complete widget list.
1860 * 0 makes the icon the left-most icon. The gap in the middle has
1861 * an index number, which allows you to specify that the icon should
1862 * go on the left or right side.
1864 static void reposition_icon(PanelIcon
*pi
, int index
)
1866 Panel
*panel
= pi
->panel
;
1867 GtkWidget
*widget
= pi
->widget
;
1871 list
= gtk_container_get_children(GTK_CONTAINER(panel
->before
));
1872 before_len
= g_list_length(list
);
1875 if (index
<= before_len
)
1876 reposition_icon_on_side(panel
->before
, widget
, index
);
1878 reposition_icon_on_side(panel
->after
, widget
,
1879 index
- (before_len
+ 1));
1884 static void start_drag(PanelIcon
*pi
, GdkEventMotion
*event
)
1886 GtkWidget
*widget
= pi
->widget
;
1887 Icon
*icon
= (Icon
*) pi
;
1889 if (!icon
->selected
)
1891 if (event
->state
& GDK_BUTTON1_MASK
)
1893 /* Select just this one */
1894 icon_select_only(icon
);
1895 tmp_icon_selected
= TRUE
;
1898 icon_set_selected(icon
, TRUE
);
1901 g_return_if_fail(icon_selection
!= NULL
);
1903 if (icon_selection
->next
== NULL
)
1904 drag_one_item(widget
, event
, icon
->path
, icon
->item
, NULL
);
1909 uri_list
= icon_create_uri_list();
1910 drag_selection(widget
, event
, uri_list
);
1915 static void applet_died(GtkWidget
*socket
)
1917 gboolean never_plugged
;
1919 never_plugged
= (!g_object_get_data(G_OBJECT(socket
), "lost_plug"))
1920 && !GTK_SOCKET(socket
)->plug_window
;
1925 _("Applet quit without ever creating a widget!"));
1926 gtk_widget_destroy(socket
);
1929 gtk_widget_unref(socket
);
1932 static void socket_destroyed(GtkWidget
*socket
, GtkWidget
*widget
)
1934 g_object_set_data(G_OBJECT(socket
), "lost_plug", "yes");
1936 gtk_widget_unref(socket
);
1938 gtk_widget_destroy(widget
); /* Remove from panel */
1941 panel_save(g_object_get_data(G_OBJECT(socket
), "panel"));
1944 /* Try to run this applet.
1947 * - No executable AppletRun:
1948 * icon->socket == NULL (unchanged) on return.
1950 * Otherwise, create socket (setting icon->socket) and ref it twice.
1952 * - AppletRun quits without connecting a plug:
1953 * On child death lost_plug is unset and socket is empty.
1955 * Report error and destroy widget (to 'socket destroyed').
1957 * - AppletRun quits while plug is in socket:
1958 * Unref socket once. Socket will be destroyed later.
1960 * - Socket is destroyed.
1961 * Set lost_plug = "yes" and remove widget from panel.
1964 static void run_applet(PanelIcon
*pi
)
1966 GError
*error
= NULL
;
1969 Icon
*icon
= (Icon
*) pi
;
1971 argv
[0] = (char *) make_path(icon
->path
, "AppletRun");
1973 if (access(argv
[0], X_OK
) != 0)
1976 pi
->socket
= gtk_socket_new();
1978 gtk_container_add(GTK_CONTAINER(pi
->widget
), pi
->socket
);
1979 gtk_widget_show_all(pi
->socket
);
1980 gtk_widget_realize(pi
->socket
);
1982 /* Always get button-2 events so we can drag */
1983 XGrabButton(gdk_display
, Button2
, AnyModifier
,
1984 GDK_WINDOW_XWINDOW(pi
->socket
->window
),
1986 ButtonPressMask
| ButtonReleaseMask
| Button2MotionMask
,
1987 GrabModeAsync
, /* Pointer */
1988 GrabModeAsync
, /* Keyboard */
1993 PanelSide side
= pi
->panel
->side
;
1995 /* Set a hint to let applets position their menus correctly */
1996 pos
= g_strdup_printf("%s,%d",
1997 panel_side_to_name(side
), MENU_MARGIN(side
));
1998 gdk_property_change(pi
->socket
->window
,
1999 gdk_atom_intern("_ROX_PANEL_MENU_POS", FALSE
),
2000 gdk_atom_intern("STRING", FALSE
),
2001 8, GDK_PROP_MODE_REPLACE
,
2005 /* Ensure that the properties are set before starting the
2011 g_object_set_data(G_OBJECT(pi
->widget
), "icon", pi
);
2012 g_object_set_data(G_OBJECT(pi
->socket
), "panel", pi
->panel
);
2014 argv
[1] = g_strdup_printf("%ld",
2015 GDK_WINDOW_XWINDOW(pi
->socket
->window
));
2018 if (!g_spawn_async(NULL
, argv
, NULL
, G_SPAWN_DO_NOT_REAP_CHILD
,
2019 NULL
, NULL
, &pid
, &error
))
2021 delayed_error(_("Error running applet:\n%s"), error
->message
);
2022 g_error_free(error
);
2023 gtk_widget_destroy(pi
->socket
);
2028 gtk_widget_ref(pi
->socket
);
2029 on_child_death(pid
, (CallbackFn
) applet_died
, pi
->socket
);
2031 gtk_widget_ref(pi
->socket
);
2032 g_signal_connect(pi
->socket
, "destroy",
2033 G_CALLBACK(socket_destroyed
), pi
->widget
);
2039 static void panel_post_resize(GtkWidget
*win
, GtkRequisition
*req
, Panel
*panel
)
2041 if (panel
->side
== PANEL_TOP
|| panel
->side
== PANEL_BOTTOM
)
2043 req
->width
= panel
->geometry
.width
;
2044 req
->height
+= EDGE_WIDTH
;
2048 int h
= panel
->geometry
.height
;
2050 if (current_panel
[PANEL_TOP
])
2052 GtkWidget
*win
= current_panel
[PANEL_TOP
]->window
;
2053 h
-= win
->allocation
.height
;
2056 if (current_panel
[PANEL_BOTTOM
])
2058 GtkWidget
*win
= current_panel
[PANEL_BOTTOM
]->window
;
2059 h
-= win
->allocation
.height
;
2063 req
->width
+= EDGE_WIDTH
;
2067 static void update_side(GtkWidget
*side
)
2071 kids
= gtk_container_get_children(GTK_CONTAINER(side
));
2072 for (next
= kids
; next
; next
= next
->next
)
2075 pi
= g_object_get_data(next
->data
, "icon");
2076 panel_icon_set_tip(pi
);
2081 /* Tips or style has changed -- update everything on this panel */
2082 static void panel_set_style(Panel
*panel
)
2084 update_side(panel
->before
);
2085 update_side(panel
->after
);
2086 gtk_widget_queue_resize(panel
->window
);
2089 static gboolean
recreate_panels(char **names
)
2093 for (i
= 0; i
< PANEL_NUMBER_OF_SIDES
; i
++)
2097 panel_new(names
[i
], i
);
2107 static void update_side_size(GtkWidget
*side
)
2111 kids
= gtk_container_get_children(GTK_CONTAINER(side
));
2112 for (next
= kids
; next
; next
= next
->next
)
2115 pi
= g_object_get_data(next
->data
, "icon");
2116 gtk_widget_queue_resize(pi
->widget
);
2121 /* Update panel size and redraw */
2122 static void panel_update(Panel
*panel
)
2124 update_side_size(panel
->before
);
2125 update_side_size(panel
->after
);
2126 gtk_widget_queue_resize(panel
->window
);
2127 gtk_widget_queue_draw(panel
->window
);
2130 static void panel_style_changed(void)
2134 if (o_override_redirect
.has_changed
)
2138 names
= g_new(char *, PANEL_NUMBER_OF_SIDES
);
2140 for (i
= 0; i
< PANEL_NUMBER_OF_SIDES
; i
++)
2142 Panel
*panel
= current_panel
[i
];
2143 names
[i
] = panel
? g_strdup(panel
->name
) : NULL
;
2147 g_idle_add((GtkFunction
) recreate_panels
, names
);
2151 static gboolean
draw_panel_edge(GtkWidget
*widget
, GdkEventExpose
*event
,
2154 int x
, y
, width
, height
;
2156 if (panel
->side
== PANEL_TOP
|| panel
->side
== PANEL_BOTTOM
)
2158 width
= panel
->geometry
.width
;
2159 height
= EDGE_WIDTH
;
2162 if (panel
->side
== PANEL_BOTTOM
)
2165 y
= widget
->allocation
.height
- EDGE_WIDTH
;
2170 height
= panel
->geometry
.height
;
2173 if (panel
->side
== PANEL_RIGHT
)
2176 x
= widget
->allocation
.width
- EDGE_WIDTH
;
2179 gdk_draw_rectangle(widget
->window
,
2180 widget
->style
->fg_gc
[GTK_STATE_NORMAL
], TRUE
,
2181 x
, y
, width
, height
);
2186 static gpointer parent_class
;
2188 static void panel_icon_destroy(Icon
*icon
)
2190 PanelIcon
*pi
= (PanelIcon
*) icon
;
2192 g_return_if_fail(pi
!= NULL
);
2195 g_object_unref(pi
->image
);
2197 g_return_if_fail(pi
->widget
!= NULL
);
2199 gtk_widget_destroy(pi
->widget
);
2202 static void panel_remove_items(void)
2206 g_return_if_fail(icon_selection
!= NULL
);
2208 panel
= ((PanelIcon
*) icon_selection
->data
)->panel
;
2210 while (icon_selection
)
2211 icon_destroy((Icon
*) icon_selection
->data
);
2216 /* Icon's size, shape or appearance has changed - update the display */
2217 static void panel_icon_redraw(Icon
*icon
)
2219 PanelIcon
*pi
= (PanelIcon
*) icon
;
2221 gtk_widget_set_state(pi
->widget
,
2222 icon
->selected
? GTK_STATE_SELECTED
2223 : GTK_STATE_NORMAL
);
2225 /* Will regenerate the scaled icon from the new image */
2226 gtk_widget_queue_resize(pi
->widget
);
2228 panel_icon_set_tip((PanelIcon
*) icon
);
2231 static void panel_icon_update(Icon
*icon
)
2233 PanelIcon
*pi
= (PanelIcon
*) icon
;
2235 gtk_widget_queue_draw(pi
->widget
);
2236 gtk_label_set_text(GTK_LABEL(pi
->label
), icon
->item
->leafname
);
2237 panel_save(pi
->panel
);
2240 /* The point of this is to clear the selection if the existing icons
2241 * aren't from the same panel...
2243 static gboolean
panel_icon_same_group(Icon
*icon
, Icon
*other
)
2245 if (IS_PANEL_ICON(other
))
2247 PanelIcon
*a
= (PanelIcon
*) icon
;
2248 PanelIcon
*b
= (PanelIcon
*) other
;
2250 return a
->panel
== b
->panel
;
2256 static void panel_icon_class_init(gpointer gclass
, gpointer data
)
2258 IconClass
*icon
= (IconClass
*) gclass
;
2260 parent_class
= g_type_class_peek_parent(gclass
);
2262 icon
->destroy
= panel_icon_destroy
;
2263 icon
->redraw
= panel_icon_redraw
;
2264 icon
->update
= panel_icon_update
;
2265 icon
->remove_items
= panel_remove_items
;
2266 icon
->same_group
= panel_icon_same_group
;
2267 icon
->wink
= panel_icon_wink
;
2270 static void panel_icon_init(GTypeInstance
*object
, gpointer gclass
)
2272 PanelIcon
*pi
= (PanelIcon
*) object
;
2278 pi
->style
= TEXT_UNDER_ICON
;
2281 static GType
panel_icon_get_type(void)
2283 static GType type
= 0;
2287 static const GTypeInfo info
=
2289 sizeof (PanelIconClass
),
2290 NULL
, /* base_init */
2291 NULL
, /* base_finalise */
2292 panel_icon_class_init
,
2293 NULL
, /* class_finalise */
2294 NULL
, /* class_data */
2296 0, /* n_preallocs */
2300 type
= g_type_register_static(icon_get_type(),
2301 "PanelIcon", &info
, 0);
2307 static PanelIcon
*panel_icon_new(Panel
*panel
,
2308 const char *pathname
,
2314 pi
= g_object_new(panel_icon_get_type(), NULL
);
2317 icon_set_path(icon
, pathname
, name
);
2323 static gboolean
panel_want_show_text(PanelIcon
*pi
)
2325 Icon
*icon
= (Icon
*) pi
;
2326 Panel
*panel
= pi
->panel
;
2328 if (!icon
->item
->leafname
[0])
2331 if (panel
->style
== SHOW_BOTH
)
2333 if (panel
->style
== SHOW_ICON
)
2336 if (icon
->item
->flags
& ITEM_FLAG_APPDIR
)
2339 if (EXECUTABLE_FILE(icon
->item
))
2345 static void xinerama_sensitive(GladeXML
*glade
, gboolean sensitive
)
2347 gtk_widget_set_sensitive(
2348 glade_xml_get_widget(glade
, "panel_xinerama_monitor"),
2352 inline static Panel
*panel_from_opts_widget(GtkWidget
*widget
)
2354 return g_object_get_data(G_OBJECT(gtk_widget_get_toplevel(widget
)),
2358 static void panel_style_radio_toggled(GtkToggleButton
*widget
, int style
)
2362 if (!gtk_toggle_button_get_active(widget
))
2364 panel
= panel_from_opts_widget(GTK_WIDGET(widget
));
2365 if (style
!= panel
->style
)
2367 panel
->style
= style
;
2368 panel_set_style(panel
);
2373 static void panel_xinerama_changed(Panel
*panel
)
2375 panel_update_geometry(panel
);
2376 reposition_panel(panel
->window
, &panel
->window
->allocation
, panel
);
2377 gtk_widget_queue_resize(panel
->window
);
2381 static void panel_side_radio_toggled(GtkWidget
*widget
, PanelSide new_side
)
2385 char *name
, *other_side_name
;
2387 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
)))
2390 panel
= panel_from_opts_widget(widget
);
2391 old_side
= panel
->side
;
2392 if (new_side
== old_side
)
2395 name
= g_strdup(panel
->name
);
2396 other_side_name
= current_panel
[new_side
]
2397 ? g_strdup(current_panel
[new_side
]->name
)
2400 panel_new(name
, new_side
);
2401 g_object_set_data(G_OBJECT(gtk_widget_get_toplevel(widget
)),
2402 "rox-panel", current_panel
[new_side
]);
2403 panel_new(other_side_name
, old_side
);
2406 g_free(other_side_name
);
2409 static void panel_style_radio_0_toggled_cb(GtkToggleButton
*widget
)
2411 panel_style_radio_toggled(widget
, 0);
2414 static void panel_style_radio_1_toggled_cb(GtkToggleButton
*widget
)
2416 panel_style_radio_toggled(widget
, 1);
2419 static void panel_style_radio_2_toggled_cb(GtkToggleButton
*widget
)
2421 panel_style_radio_toggled(widget
, 2);
2424 static void panel_width_changed_cb(GtkSpinButton
*widget
)
2426 Panel
*panel
= panel_from_opts_widget(GTK_WIDGET(widget
));
2427 int width
= gtk_spin_button_get_value_as_int(widget
);
2429 if (width
!= panel
->width
)
2431 panel
->width
= width
;
2432 panel_update(panel
);
2437 static void panel_avoid_toggled_cb(GtkToggleButton
*widget
)
2439 Panel
*panel
= panel_from_opts_widget(GTK_WIDGET(widget
));
2440 gboolean avoid
= gtk_toggle_button_get_active(widget
);
2442 if (avoid
!= panel
->avoid
)
2444 panel
->avoid
= avoid
;
2445 panel_setup_struts(panel
, &panel
->window
->allocation
);
2450 static void panel_xinerama_confine_toggled_cb(GtkWidget
*widget
)
2452 Panel
*panel
= panel_from_opts_widget(widget
);
2453 gboolean xinerama
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
2455 xinerama_sensitive(glade_get_widget_tree(gtk_widget_get_toplevel(widget
)),
2457 if (xinerama
!= panel
->xinerama
)
2459 panel
->xinerama
= xinerama
;
2460 panel_xinerama_changed(panel
);
2464 static void panel_xinerama_monitor_changed_cb(GtkSpinButton
*widget
)
2466 Panel
*panel
= panel_from_opts_widget(GTK_WIDGET(widget
));
2467 int monitor
= gtk_spin_button_get_value_as_int(widget
);
2469 if (monitor
!= panel
->monitor
)
2471 panel
->monitor
= monitor
;
2472 panel_xinerama_changed(panel
);
2476 static void panel_pos_top_toggled_cb(GtkWidget
*widget
)
2478 panel_side_radio_toggled(widget
, PANEL_TOP
);
2481 static void panel_pos_bottom_toggled_cb(GtkWidget
*widget
)
2483 panel_side_radio_toggled(widget
, PANEL_BOTTOM
);
2486 static void panel_pos_left_toggled_cb(GtkWidget
*widget
)
2488 panel_side_radio_toggled(widget
, PANEL_LEFT
);
2491 static void panel_pos_right_toggled_cb(GtkWidget
*widget
)
2493 panel_side_radio_toggled(widget
, PANEL_RIGHT
);
2496 #define CONNECT_GLADE_CB(glade, handler) \
2497 glade_xml_signal_connect(glade, #handler, G_CALLBACK(handler))
2499 static void panel_connect_dialog_signal_handlers(GladeXML
*glade
)
2501 CONNECT_GLADE_CB(glade
, gtk_widget_destroy
);
2502 CONNECT_GLADE_CB(glade
, panel_style_radio_0_toggled_cb
);
2503 CONNECT_GLADE_CB(glade
, panel_style_radio_1_toggled_cb
);
2504 CONNECT_GLADE_CB(glade
, panel_style_radio_2_toggled_cb
);
2505 CONNECT_GLADE_CB(glade
, panel_width_changed_cb
);
2506 CONNECT_GLADE_CB(glade
, panel_avoid_toggled_cb
);
2507 CONNECT_GLADE_CB(glade
, panel_xinerama_confine_toggled_cb
);
2508 CONNECT_GLADE_CB(glade
, panel_xinerama_monitor_changed_cb
);
2509 CONNECT_GLADE_CB(glade
, panel_pos_top_toggled_cb
);
2510 CONNECT_GLADE_CB(glade
, panel_pos_bottom_toggled_cb
);
2511 CONNECT_GLADE_CB(glade
, panel_pos_left_toggled_cb
);
2512 CONNECT_GLADE_CB(glade
, panel_pos_right_toggled_cb
);
2515 static void panel_setup_options_dialog(GladeXML
*glade
, Panel
*panel
)
2518 const char *pos_radio
;
2520 wnm
= g_strdup_printf("panel_style_radio_%d", panel
->style
);
2521 gtk_toggle_button_set_active(
2522 GTK_TOGGLE_BUTTON(glade_xml_get_widget(glade
, wnm
)),
2525 gtk_spin_button_set_value(
2526 GTK_SPIN_BUTTON(glade_xml_get_widget(glade
, "panel_width")),
2528 gtk_toggle_button_set_active(
2529 GTK_TOGGLE_BUTTON(glade_xml_get_widget(glade
, "panel_avoid")),
2531 gtk_toggle_button_set_active(
2532 GTK_TOGGLE_BUTTON(glade_xml_get_widget(glade
,
2533 "panel_xinerama_confine")),
2535 gtk_spin_button_set_adjustment(
2536 GTK_SPIN_BUTTON(glade_xml_get_widget(glade
, "panel_xinerama_monitor")),
2537 GTK_ADJUSTMENT(gtk_adjustment_new(MAX(0, panel
->monitor
),
2538 0, n_monitors
- 1, 1, 10, 1)));
2539 xinerama_sensitive(glade
, panel
->xinerama
);
2540 switch (panel
->side
)
2543 pos_radio
= "panel_pos_top";
2546 pos_radio
= "panel_pos_bottom";
2549 pos_radio
= "panel_pos_left";
2552 pos_radio
= "panel_pos_right";
2558 g_return_if_fail(pos_radio
!= NULL
);
2559 gtk_toggle_button_set_active(
2560 GTK_TOGGLE_BUTTON(glade_xml_get_widget(glade
, pos_radio
)),
2564 static void panel_show_options(Panel
*panel
)
2567 gboolean already_showing
= FALSE
;
2568 GladeXML
*glade
= NULL
;
2570 if (panel_options_dialog
)
2572 dialog
= panel_options_dialog
;
2573 already_showing
= TRUE
;
2574 glade
= glade_get_widget_tree(dialog
);
2578 glade
= get_glade_xml("Panel Options");
2579 dialog
= glade_xml_get_widget(glade
, "Panel Options");
2580 panel_options_dialog
= dialog
;
2581 g_signal_connect(dialog
, "destroy",
2582 G_CALLBACK(gtk_widget_destroyed
),
2583 &panel_options_dialog
);
2584 panel_connect_dialog_signal_handlers(glade
);
2586 g_object_set_data(G_OBJECT(panel_options_dialog
), "rox-panel", panel
);
2588 panel_setup_options_dialog(glade
, panel
);
2590 if (already_showing
)
2592 GtkWindow
*win
= GTK_WINDOW(dialog
);
2594 gtk_widget_hide(dialog
);
2595 /* This extra set_position() should ensure it moves to new position
2597 gtk_window_set_position(win
, GTK_WIN_POS_CENTER_ALWAYS
);
2598 gtk_window_set_position(win
, GTK_WIN_POS_MOUSE
);
2599 gtk_window_present(win
);
2603 gtk_window_set_position(GTK_WINDOW(dialog
), GTK_WIN_POS_MOUSE
);
2604 gtk_widget_show_all(dialog
);
2608 static void panel_position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
,
2609 gboolean
*push_in
, gpointer data
)
2611 int *pos
= (int *) data
;
2612 GtkRequisition requisition
;
2613 int margin
= pos
[2];
2615 int mon_right
= monitor_geom
[mon
].x
+
2616 monitor_geom
[mon
].width
;
2617 int mon_bottom
= monitor_geom
[mon
].y
+
2618 monitor_geom
[mon
].height
;
2620 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
2623 *x
= mon_right
- margin
- requisition
.width
;
2624 else if (pos
[0] == -2)
2625 *x
= monitor_geom
[mon
].x
+ margin
;
2627 *x
= pos
[0] - (requisition
.width
>> 2);
2630 *y
= mon_bottom
- margin
- requisition
.height
;
2631 else if (pos
[1] == -2)
2632 *y
= monitor_geom
[mon
].y
+ margin
;
2634 *y
= pos
[1] - (requisition
.height
>> 2);
2636 *x
= CLAMP(*x
, 0, mon_right
- requisition
.width
);
2637 *y
= CLAMP(*y
, 0, mon_bottom
- requisition
.height
);
2642 static void panel_remove_callback(PanelSide side
)
2644 GtkWidget
*dialog
= gtk_message_dialog_new(NULL
, GTK_DIALOG_MODAL
,
2645 GTK_MESSAGE_QUESTION
, GTK_BUTTONS_OK_CANCEL
,
2646 _("Are you sure you want to remove this panel from the desktop?"));
2648 gtk_dialog_set_default_response(GTK_DIALOG(dialog
), GTK_RESPONSE_OK
);
2649 gtk_window_set_title(GTK_WINDOW(dialog
), _("Remove Panel"));
2650 gtk_window_set_position(GTK_WINDOW(dialog
), GTK_WIN_POS_MOUSE
);
2651 if (gtk_dialog_run(GTK_DIALOG(dialog
)) == GTK_RESPONSE_OK
)
2652 panel_new(NULL
, side
);
2653 gtk_widget_destroy(dialog
);
2656 static void panel_show_menu(GdkEventButton
*event
, PanelIcon
*pi
, Panel
*panel
)
2658 GtkWidget
*option_item
;
2659 GtkWidget
*del_item
;
2660 PanelSide side
= panel
->side
;
2663 pos
[0] = event
->x_root
;
2664 pos
[1] = event
->y_root
;
2665 pos
[2] = MENU_MARGIN(side
);
2666 /* FIXME: Should we read screen from event's window rather than
2668 pos
[3] = gdk_screen_get_monitor_at_point(
2669 gdk_screen_get_default(),
2670 event
->x_root
, event
->y_root
);
2672 option_item
= gtk_image_menu_item_new_with_label(_("Panel Options..."));
2673 g_signal_connect_swapped(option_item
, "activate",
2674 G_CALLBACK(panel_show_options
), panel
);
2676 del_item
= gtk_image_menu_item_new_with_label(_("Remove Panel"));
2677 add_stock_to_menu_item(del_item
, GTK_STOCK_REMOVE
);
2678 g_signal_connect_swapped(del_item
, "activate",
2679 G_CALLBACK(panel_remove_callback
), GINT_TO_POINTER(side
));
2681 icon_prepare_menu((Icon
*) pi
, option_item
, del_item
, NULL
);
2683 if (side
== PANEL_LEFT
)
2685 else if (side
== PANEL_RIGHT
)
2688 if (side
== PANEL_TOP
)
2690 else if (side
== PANEL_BOTTOM
)
2693 gtk_menu_popup(GTK_MENU(icon_menu
), NULL
, NULL
,
2694 panel_position_menu
,
2695 (gpointer
) pos
, event
->button
, event
->time
);
2698 /* Note: also called from icon handler */
2699 static gboolean
panel_drag_motion(GtkWidget
*widget
,
2700 GdkDragContext
*context
,
2706 int panel_x
, panel_y
;
2708 gdk_window_get_pointer(panel
->window
->window
, &panel_x
, &panel_y
, NULL
);
2710 motion_may_raise(panel
, panel_x
, panel_y
);
2711 gdk_drag_status(context
, 0, time
);
2716 static gboolean
insert_drag_motion(GtkWidget
*widget
,
2717 GdkDragContext
*context
,
2723 int panel_x
, panel_y
;
2725 gdk_window_get_pointer(panel
->window
->window
, &panel_x
, &panel_y
, NULL
);
2726 motion_may_raise(panel
, panel_x
, panel_y
);
2731 /* Note: also called from icon handler */
2732 static void panel_drag_leave(GtkWidget
*widget
,
2733 GdkDragContext
*context
,
2737 GdkWindow
*pinboard
, *window
;
2738 GtkAllocation
*alloc
= &panel
->window
->allocation
;
2741 window
= panel
->window
->window
;
2742 gdk_window_get_pointer(window
, &x
, &y
, NULL
);
2743 if ((x
< 0 || y
< 0 || x
> alloc
->width
|| y
> alloc
->height
) &&
2744 panel_keep_below(panel
, TRUE
))
2746 /* Shouldn't need this as well as keep_below but some WMs don't
2747 * automatically lower as soon as the hint is set */
2748 pinboard
= pinboard_get_window();
2749 window_put_just_above(panel
->window
->window
, pinboard
);
2753 static void panel_update_geometry(Panel
*panel
)
2755 if (panel
->xinerama
&& panel
->monitor
>= n_monitors
)
2757 g_warning(_("Xinerama monitor %d unavailable"), panel
->monitor
);
2758 panel
->xinerama
= FALSE
;
2761 if (panel
->xinerama
)
2763 panel
->geometry
= monitor_geom
[panel
->monitor
];
2767 panel
->geometry
.x
= panel
->geometry
.y
= 0;
2768 panel
->geometry
.width
= screen_width
;
2769 panel
->geometry
.height
= screen_height
;
2773 static GList
*build_monitor_number(Option
*option
, xmlNode
*node
, guchar
*label
)
2777 adj
= gtk_adjustment_new(MAX(0, panel_monitor
),
2778 0, n_monitors
- 1, 1, 10, 1);
2779 return build_numentry_base(option
, node
, label
, GTK_ADJUSTMENT(adj
));
2782 static const char *panel_side_to_translated_name(PanelSide side
)
2794 case PANEL_DEFAULT_SIDE
:
2795 return _("Default");
2799 return _("Unknown side");
2802 const char *panel_side_to_name(PanelSide side
)
2814 case PANEL_DEFAULT_SIDE
:
2819 return "UnknownSide";
2822 /* Returns PANEL_NUMBER_OF_SIDES if name is invalid */
2823 PanelSide
panel_name_to_side(gchar
*side
)
2825 if (strcmp(side
, "Top") == 0)
2827 else if (strcmp(side
, "Bottom") == 0)
2828 return PANEL_BOTTOM
;
2829 else if (strcmp(side
, "Left") == 0)
2831 else if (strcmp(side
, "Right") == 0)
2834 g_warning("Unknown panel side '%s'", side
);
2835 return PANEL_NUMBER_OF_SIDES
;
2838 static void panel_add_callback(PanelSide side
)
2840 g_return_if_fail(current_panel
[side
] == NULL
);
2841 panel_new(panel_side_to_name(side
), side
);
2844 GtkWidget
*panel_new_panel_submenu(void)
2846 GtkWidget
*menu
= gtk_menu_new();
2849 for (side
= 0; side
< PANEL_NUMBER_OF_SIDES
; ++side
)
2851 GtkWidget
*item
= gtk_menu_item_new_with_label(
2852 panel_side_to_translated_name(side
));
2854 g_signal_connect_swapped(item
, "activate",
2855 G_CALLBACK(panel_add_callback
), GINT_TO_POINTER(side
));
2856 gtk_widget_set_sensitive(item
, current_panel
[side
] == NULL
);
2857 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
2858 gtk_widget_show(item
);
2863 /* Set the panel to be above/below other windows (setting = TRUE for below),
2866 * If o_panel_on_top is set then do nothing and return FALSE.
2868 static gboolean
panel_keep_below(Panel
*panel
, gboolean setting
)
2870 if (!o_panel_on_top
.int_value
)
2872 keep_below(panel
->window
->window
, setting
);