1
/* $Id: panel-properties.c 29412 2009-01-30 19:20:31Z nick $
3
* Copyright (c) 2005 Jasper Huijsmans <jasper@xfce.org>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published
7
* by the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Library General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35
#include <libxfce4util/libxfce4util.h>
36
#include <libxfce4panel/xfce-panel-window.h>
37
#include <libxfce4panel/xfce-itembar.h>
38
#include <libxfce4panel/xfce-panel-item-iface.h>
39
#include <libxfce4panel/xfce-panel-enums.h>
40
#include <libxfce4panel/xfce-panel-macros.h>
42
#include "panel-properties.h"
43
#include "panel-private.h"
44
#include "panel-dnd.h"
47
#define OPAQUE 0xffffffff
48
#define HIDE_TIMEOUT 350
49
#define UNHIDE_TIMEOUT 200
54
static void panel_move_end (XfcePanelWindow *window,
57
static void panel_move_function (XfcePanelWindow *window,
61
static void panel_resize_function (XfcePanelWindow *window,
63
GtkAllocation *alloc_old,
64
GtkAllocation *alloc_new,
67
static void panel_enter (Panel *p,
68
GdkEventCrossing *event);
69
static void panel_leave (Panel *p,
70
GdkEventCrossing *event);
71
static void panel_grabbed (Panel *p,
72
gboolean was_grabbed);
76
/* moving and resizing */
78
_calculate_coordinates (XfceScreenPosition position, /* screen position */
79
GdkRectangle *screen, /* monitor geometry */
80
gint width, /* panel size */
82
gint *x, /* output coordinates */
88
case XFCE_SCREEN_POSITION_NONE:
89
case XFCE_SCREEN_POSITION_FLOATING_H:
90
case XFCE_SCREEN_POSITION_FLOATING_V:
91
*x = CLAMP (*x, screen->x,
92
MAX (screen->x, screen->x + screen->width - width));
93
*y = CLAMP (*y, screen->y,
94
MAX (screen->y, screen->y + screen->height - height));
98
case XFCE_SCREEN_POSITION_NW_H:
103
case XFCE_SCREEN_POSITION_N:
104
*x = MAX (screen->x, screen->x + (screen->width - width) / 2);
108
case XFCE_SCREEN_POSITION_NE_H:
109
*x = MAX (screen->x, screen->x + screen->width - width);
114
case XFCE_SCREEN_POSITION_NW_V:
119
case XFCE_SCREEN_POSITION_W:
121
*y = MAX (screen->y, screen->y + (screen->height - height) / 2);
124
case XFCE_SCREEN_POSITION_SW_V:
126
*y = MAX (screen->y, screen->y + screen->height - height);
130
case XFCE_SCREEN_POSITION_NE_V:
131
*x = screen->x + screen->width - width;
135
case XFCE_SCREEN_POSITION_E:
136
*x = screen->x + screen->width - width;
137
*y = MAX (screen->y, screen->y + (screen->height - height) / 2);
140
case XFCE_SCREEN_POSITION_SE_V:
141
*x = screen->x + screen->width - width;
142
*y = MAX (screen->y, screen->y + screen->height - height);
146
case XFCE_SCREEN_POSITION_SW_H:
148
*y = screen->y + screen->height - height;
151
case XFCE_SCREEN_POSITION_S:
152
*x = MAX (screen->x, screen->x + (screen->width - width) / 2);
153
*y = screen->y + screen->height - height;
156
case XFCE_SCREEN_POSITION_SE_H:
157
*x = MAX (screen->x, screen->x + screen->width - width);
158
*y = screen->y + screen->height - height;
166
_set_borders (Panel *panel)
169
gboolean top, bottom, left, right;
173
top = bottom = left = right = TRUE;
175
switch (priv->screen_position)
178
case XFCE_SCREEN_POSITION_NONE:
179
case XFCE_SCREEN_POSITION_FLOATING_H:
180
case XFCE_SCREEN_POSITION_FLOATING_V:
184
case XFCE_SCREEN_POSITION_NW_H:
186
right = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
189
case XFCE_SCREEN_POSITION_N:
191
left = right = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
194
case XFCE_SCREEN_POSITION_NE_H:
196
left = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
200
case XFCE_SCREEN_POSITION_NW_V:
202
bottom = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
205
case XFCE_SCREEN_POSITION_W:
207
top = bottom = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
210
case XFCE_SCREEN_POSITION_SW_V:
211
left = bottom = FALSE;
212
top = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
216
case XFCE_SCREEN_POSITION_NE_V:
218
bottom = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
221
case XFCE_SCREEN_POSITION_E:
223
top = bottom = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
226
case XFCE_SCREEN_POSITION_SE_V:
227
right = bottom = FALSE;
228
top = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
232
case XFCE_SCREEN_POSITION_SW_H:
233
bottom = left = FALSE;
234
right = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
237
case XFCE_SCREEN_POSITION_S:
239
left = right = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
242
case XFCE_SCREEN_POSITION_SE_H:
243
bottom = right = FALSE;
244
left = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
248
xfce_panel_window_set_show_border (XFCE_PANEL_WINDOW (panel),
249
top, bottom, left, right);
252
/* fairly arbitrary maximum strut size */
254
_validate_strut( gint width,
257
return ( offset < width / 4 );
261
_set_struts (Panel *panel,
269
gulong data[12] = { 0, };
271
gboolean update = FALSE;
273
/* _NET_WM_STRUT_PARTIAL: CARDINAL[12]/32
275
* 0: left 1: right 2: top 3: bottom
276
* 4: left_start_y 5: left_end_y 6: right_start_y 7: right_end_y
277
* 8: top_start_x 9: top_end_x 10: bottom_start_x 11: bottom_end_x
279
* Note: In xinerama use struts relative to combined screen dimensions,
280
* not just the current monitor.
285
/* use edit_mode property to test if we are changing position */
286
if (G_UNLIKELY (priv->edit_mode))
289
if (!priv->autohide &&
290
!xfce_screen_position_is_floating (priv->screen_position))
292
if (xfce_screen_position_is_left (priv->screen_position))
294
/* no struts possible on Xinerama screens when this monitor
295
* has neighbors on the left (see fd.o spec).
297
if (!xmon->has_neighbor_left
298
&& _validate_strut (xmon->geometry.width, w))
300
data[0] = xmon->geometry.x + w; /* left */
301
data[4] = y; /* left_start_y */
302
data[5] = y + h - 1; /* left_end_y */
305
else if (xfce_screen_position_is_right (priv->screen_position))
307
/* no struts possible on Xinerama screens when this monitor
308
* has neighbors on the right (see fd.o spec).
310
if (!xmon->has_neighbor_right
311
&& _validate_strut (xmon->geometry.width, w))
313
data[1] = gdk_screen_get_width (xmon->screen)
314
- xmon->geometry.x - xmon->geometry.width
316
data[6] = y; /* right_start_y */
317
data[7] = y + h - 1; /* right_end_y */
320
else if (xfce_screen_position_is_top (priv->screen_position))
322
/* no struts possible on Xinerama screens when this monitor
323
* has neighbors on the top (see fd.o spec).
325
if (!xmon->has_neighbor_above
326
&& _validate_strut (xmon->geometry.height, h))
328
data[2] = xmon->geometry.y
330
data[8] = x; /* top_start_x */
331
data[9] = x + w - 1; /* top_end_x */
336
/* no struts possible on Xinerama screens when this monitor
337
* has neighbors on the bottom (see fd.o spec).
339
if (!xmon->has_neighbor_below
340
&& _validate_strut (xmon->geometry.height, h))
342
data[3] = gdk_screen_get_height (xmon->screen)
343
- xmon->geometry.y - xmon->geometry.height
345
data[10] = x; /* bottom_start_x */
346
data[11] = x + w - 1; /* bottom_end_x */
352
"%ld\t%ld\t%ld\t%ld\n"
353
"%ld\t%ld\t%ld\t%ld\n"
354
"%ld\t%ld\t%ld\t%ld\n",
355
data[0], data[1], data[2], data[3],
356
data[4], data[5], data[6], data[7],
357
data[8], data[9], data[10], data[11]);
359
/* Check if values have changed. */
360
for (i = 0; i < 12; i++)
362
if (data[i] != priv->struts[i])
365
priv->struts[i] = data[i];
371
gdk_error_trap_push ();
372
gdk_property_change (GTK_WIDGET (panel)->window,
373
gdk_atom_intern ("_NET_WM_STRUT_PARTIAL", FALSE),
374
gdk_atom_intern ("CARDINAL", FALSE), 32,
375
GDK_PROP_MODE_REPLACE, (guchar *) & data, 12);
376
gdk_error_trap_pop ();
378
gdk_error_trap_push ();
379
gdk_property_change (GTK_WIDGET (panel)->window,
380
gdk_atom_intern ("_NET_WM_STRUT", FALSE),
381
gdk_atom_intern ("CARDINAL", FALSE), 32,
382
GDK_PROP_MODE_REPLACE, (guchar *) & data, 4);
383
gdk_error_trap_pop ();
386
DBG ("all struts are checked and updated");
390
unblock_struts (Panel *panel)
396
priv = PANEL (panel)->priv;
397
priv->edit_mode = FALSE;
399
gtk_window_get_position (GTK_WINDOW (panel), &x, &y);
400
gtk_window_get_size (GTK_WINDOW (panel), &w, &h);
402
xmon = panel_app_get_monitor (priv->monitor);
404
_set_struts (panel, xmon, x, y, w, h);
409
panel_move_end (XfcePanelWindow *window,
416
priv = PANEL (window)->priv;
418
if (xfce_screen_position_is_floating (priv->screen_position))
420
/* Emit this signal to allow plugins to do something based on the
421
* new position. E.g. the launcher plugin adjusts the arrow type
422
* of the associated menu button. */
423
gtk_container_foreach (GTK_CONTAINER (priv->itembar),
424
(GtkCallback)xfce_panel_item_set_screen_position,
425
GINT_TO_POINTER (priv->screen_position));
428
xmon = panel_app_get_monitor (priv->monitor);
430
priv->xoffset = x - xmon->geometry.x;
431
priv->yoffset = y - xmon->geometry.y;
433
DBG ("\n + Position: %d\n + Offset: (%d, %d)",
434
priv->screen_position, priv->xoffset, priv->yoffset);
436
panel_app_queue_save ();
440
panel_move_function (XfcePanelWindow *window,
451
screen = gtk_widget_get_screen (GTK_WIDGET (window));
452
priv->monitor = gdk_screen_get_monitor_at_point (screen, *x, *y);
454
DBG (" + Monitor at (%d, %d) = %d\n", *x, *y, priv->monitor);
456
xmon = panel_app_get_monitor (priv->monitor);
458
_calculate_coordinates (priv->screen_position,
460
GTK_WIDGET (window)->allocation.width,
461
GTK_WIDGET (window)->allocation.height,
466
panel_resize_function (XfcePanelWindow *window,
468
GtkAllocation *alloc_old,
469
GtkAllocation *alloc_new,
477
DBG ("old: %dx%d\tnew: %dx%d",
478
alloc_old ? alloc_old->width : 0, alloc_old ? alloc_old->height : 0,
479
alloc_new->width, alloc_new->height );
481
if (!GTK_WIDGET_VISIBLE (panel))
485
xmon = panel_app_get_monitor (priv->monitor);
487
if (priv->full_width < XFCE_PANEL_SPAN_MONITORS)
489
_calculate_coordinates (priv->screen_position,
495
priv->xoffset = *x - xmon->geometry.x;
496
priv->yoffset = *y - xmon->geometry.y;
502
rect.width = gdk_screen_get_width (xmon->screen);
503
rect.height = gdk_screen_get_height (xmon->screen);
505
_calculate_coordinates (priv->screen_position,
515
_set_struts (panel, xmon, *x, *y, alloc_new->width, alloc_new->height);
519
panel_set_position (Panel *panel,
520
XfceScreenPosition position,
530
if (!GTK_WIDGET_VISIBLE (panel))
534
xmon = panel_app_get_monitor (priv->monitor);
536
priv->screen_position = position;
537
_set_borders (panel);
539
gtk_widget_size_request (GTK_WIDGET (panel), &req);
543
/* NOTE: xoffset and yoffset are only used for floating panels */
544
if (xfce_screen_position_is_floating (position))
546
if (G_UNLIKELY (xoffset < 0 || yoffset < 0))
548
/* This means we switched to being a floating panel;
549
* calculate the actual position here. */
550
gtk_window_get_position (GTK_WINDOW (panel), &x, &y);
554
x = xmon->geometry.x + xoffset;
555
y = xmon->geometry.y + yoffset;
559
if (priv->full_width < XFCE_PANEL_SPAN_MONITORS)
561
_calculate_coordinates (position,
567
priv->xoffset = x - xmon->geometry.x;
568
priv->yoffset = y - xmon->geometry.y;
574
rect.width = gdk_screen_get_width (xmon->screen);
575
rect.height = gdk_screen_get_height (xmon->screen);
577
_calculate_coordinates (position,
587
DBG ("\n + Position: %d\n + Offset: (%d, %d)",
588
priv->screen_position, priv->xoffset, priv->yoffset);
590
DBG (" + coordinates: (%d, %d)\n", x, y);
592
gtk_window_move (GTK_WINDOW (panel), x, y);
594
_set_struts (panel, xmon, x, y, req.width, req.height);
599
panel_screen_size_changed (GdkScreen *screen,
604
XfcePanelWidthType width;
608
xmon = panel_app_get_monitor (priv->monitor);
610
gdk_screen_get_monitor_geometry (screen,
614
/* new size constraints */
615
if ((width = priv->full_width) != XFCE_PANEL_NORMAL_WIDTH)
617
priv->full_width = XFCE_PANEL_NORMAL_WIDTH;
618
panel_set_full_width (panel, width);
622
gtk_widget_queue_resize (GTK_WIDGET (panel));
626
/* transparency and autohide */
628
_set_transparent (Panel *panel,
629
gboolean transparent)
634
if (!GTK_WIDGET (panel)->window)
639
if (G_UNLIKELY (priv->opacity == 0))
641
if (priv->transparency != 0)
644
OPAQUE - rint ((gdouble)priv->transparency * OPAQUE / 100);
648
priv->opacity = OPAQUE;
652
opacity = (transparent || priv->activetrans) ? priv->opacity : OPAQUE;
654
if (opacity != priv->saved_opacity)
656
priv->saved_opacity = opacity;
658
gdk_error_trap_push ();
660
gdk_property_change (GTK_WIDGET (panel)->window,
661
gdk_atom_intern ("_NET_WM_WINDOW_OPACITY", FALSE),
662
gdk_atom_intern ("CARDINAL", FALSE), 32,
663
GDK_PROP_MODE_REPLACE,
664
(guchar *) & opacity,
667
gdk_error_trap_pop ();
669
gtk_widget_queue_draw (GTK_WIDGET (panel));
674
panel_set_hidden (Panel *panel,
688
if (xfce_screen_position_is_horizontal (priv->screen_position))
690
w = GTK_WIDGET (panel)->allocation.width;
696
h = GTK_WIDGET (panel)->allocation.height;
699
gtk_widget_hide (priv->itembar);
703
xmon = panel_app_get_monitor (priv->monitor);
705
switch (priv->full_width)
707
case XFCE_PANEL_NORMAL_WIDTH:
711
case XFCE_PANEL_FULL_WIDTH:
712
case XFCE_PANEL_SPAN_MONITORS:
713
if (xfce_screen_position_is_horizontal (priv->screen_position))
716
if (priv->full_width == XFCE_PANEL_FULL_WIDTH)
717
w = xmon->geometry.width;
719
w = gdk_screen_get_width (xmon->screen);
724
if (priv->full_width == XFCE_PANEL_FULL_WIDTH)
725
h = xmon->geometry.height;
727
h = gdk_screen_get_height (xmon->screen);
732
gtk_widget_show (priv->itembar);
735
gtk_widget_set_size_request (GTK_WIDGET (panel), w, h);
739
_hide_timeout (Panel *panel)
744
priv->hide_timeout = 0;
746
if (!priv->hidden && !priv->block_autohide)
747
panel_set_hidden (panel, TRUE);
753
_unhide_timeout (Panel *panel)
758
priv->unhide_timeout = 0;
761
panel_set_hidden (panel, FALSE);
767
drag_motion (Panel *panel,
768
GdkDragContext *context,
778
if (!priv->hidden || priv->block_autohide)
781
if (priv->hide_timeout)
783
g_source_remove (priv->hide_timeout);
784
priv->hide_timeout = 0;
787
if (!priv->unhide_timeout)
789
priv->unhide_timeout =
790
g_timeout_add (UNHIDE_TIMEOUT,
791
(GSourceFunc) _unhide_timeout, panel);
799
drag_leave (Panel *panel,
800
GdkDragContext *drag_context,
804
int x, y, w, h, px, py;
809
if (!priv->autohide || priv->hidden || priv->block_autohide)
812
/* check if pointer is inside the window */
813
gdk_display_get_pointer (gdk_display_get_default (), NULL, &px, &py, NULL);
814
gtk_window_get_position (GTK_WINDOW (panel), &x, &y);
815
gtk_window_get_size (GTK_WINDOW (panel), &w, &h);
817
if (px < x || px > x + w || py < y || py > y + h)
819
if (priv->unhide_timeout)
821
g_source_remove (priv->unhide_timeout);
822
priv->unhide_timeout = 0;
825
if (!priv->hide_timeout)
828
g_timeout_add (HIDE_TIMEOUT,
829
(GSourceFunc) _hide_timeout, panel);
836
panel_enter (Panel *panel,
837
GdkEventCrossing *event)
841
if (event->detail != GDK_NOTIFY_INFERIOR)
843
panel_app_set_current_panel ((gpointer)panel);
847
if (priv->block_autohide)
850
_set_transparent (panel, FALSE);
855
if (priv->hide_timeout)
857
g_source_remove (priv->hide_timeout);
858
priv->hide_timeout = 0;
862
priv->unhide_timeout = g_timeout_add (UNHIDE_TIMEOUT,
863
(GSourceFunc)_unhide_timeout,
870
panel_leave (Panel *panel,
871
GdkEventCrossing *event)
875
if (event->detail != GDK_NOTIFY_INFERIOR)
879
if (priv->block_autohide)
882
_set_transparent (panel, TRUE);
887
if (priv->unhide_timeout)
889
g_source_remove (priv->unhide_timeout);
890
priv->unhide_timeout = 0;
894
priv->hide_timeout = g_timeout_add (HIDE_TIMEOUT,
895
(GSourceFunc)_hide_timeout,
901
panel_grabbed (Panel *panel,
902
gboolean was_grabbed)
904
PanelPrivate *priv = panel->priv;
906
/* block the panel if the widget is grabbed */
908
priv->block_autohide--;
910
priv->block_autohide++;
914
_window_mapped (Panel *panel)
922
panel_set_position (panel,
923
priv->screen_position,
927
_set_transparent (panel, TRUE);
929
gtk_window_get_position (GTK_WINDOW (panel), &x, &y);
931
xmon = panel_app_get_monitor (priv->monitor);
932
priv->xoffset = x - xmon->geometry.x;
933
priv->yoffset = y - xmon->geometry.y;
935
DBG (" + coordinates: (%d, %d)\n", x, y);
937
DBG ("\n + Position: %d\n + Offset: (%d, %d)",
938
priv->screen_position, priv->xoffset, priv->yoffset);
943
g_timeout_add (2000, (GSourceFunc)_hide_timeout, panel);
949
void panel_init_signals (Panel *panel)
951
DBG (" + Connect signals for panel %p", panel);
953
g_signal_connect (G_OBJECT (panel), "enter-notify-event",
954
G_CALLBACK (panel_enter), NULL);
956
g_signal_connect (G_OBJECT (panel), "leave-notify-event",
957
G_CALLBACK (panel_leave), NULL);
959
g_signal_connect (G_OBJECT (panel), "grab-notify",
960
G_CALLBACK (panel_grabbed), NULL);
962
g_signal_connect (G_OBJECT (panel), "map",
963
G_CALLBACK (_window_mapped), NULL);
965
g_signal_connect (G_OBJECT (panel), "move-end",
966
G_CALLBACK (panel_move_end), NULL);
968
panel_dnd_set_dest_name_and_widget (GTK_WIDGET (panel));
969
g_signal_connect (panel, "drag-motion", G_CALLBACK (drag_motion), NULL);
970
g_signal_connect (panel, "drag-leave", G_CALLBACK (drag_leave), NULL);
974
panel_init_position (Panel *panel)
977
GtkOrientation orientation;
979
gint x, y, w, h, max;
986
xfce_screen_position_is_horizontal (priv->screen_position) ?
987
GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
989
xfce_panel_window_set_orientation (XFCE_PANEL_WINDOW (panel), orientation);
990
xfce_itembar_set_orientation (XFCE_ITEMBAR (priv->itembar), orientation);
992
xmon = panel_app_get_monitor (priv->monitor);
994
gtk_window_set_screen (GTK_WINDOW (panel), xmon->screen);
998
if (priv->full_width > XFCE_PANEL_NORMAL_WIDTH)
999
xfce_itembar_set_allow_expand (XFCE_ITEMBAR (priv->itembar), TRUE);
1001
if (xfce_screen_position_is_horizontal (priv->screen_position))
1003
if (priv->full_width < XFCE_PANEL_SPAN_MONITORS)
1004
w = xmon->geometry.width;
1006
w = gdk_screen_get_width (xmon->screen);
1012
if (priv->full_width < XFCE_PANEL_SPAN_MONITORS)
1013
h = xmon->geometry.height;
1015
h = gdk_screen_get_height (xmon->screen);
1020
xfce_itembar_set_maximum_size (XFCE_ITEMBAR (priv->itembar), max);
1022
if (priv->full_width > XFCE_PANEL_NORMAL_WIDTH)
1023
gtk_widget_set_size_request (GTK_WIDGET (panel), w, h);
1025
if (!xfce_screen_position_is_floating (priv->screen_position))
1027
xfce_panel_window_set_movable (XFCE_PANEL_WINDOW (panel), FALSE);
1028
xfce_panel_window_set_handle_style (XFCE_PANEL_WINDOW (panel),
1029
XFCE_HANDLE_STYLE_NONE);
1032
x = xmon->geometry.x;
1033
y = xmon->geometry.y;
1035
if (priv->xoffset > 0 || priv->yoffset > 0)
1042
if (priv->full_width < XFCE_PANEL_SPAN_MONITORS)
1044
gtk_widget_size_request (GTK_WIDGET (panel), &req);
1045
_calculate_coordinates (priv->screen_position,
1051
priv->xoffset = x - xmon->geometry.x;
1052
priv->yoffset = y - xmon->geometry.y;
1058
rect.width = gdk_screen_get_width (xmon->screen);
1059
rect.height = gdk_screen_get_height (xmon->screen);
1061
_calculate_coordinates (priv->screen_position,
1072
DBG (" + offsets: (%d, %d)\n",
1073
priv->xoffset, priv->yoffset);
1075
DBG (" + coordinates: (%d, %d)\n", x, y);
1077
gtk_window_move (GTK_WINDOW (panel), x, y);
1079
xfce_panel_window_set_move_function (XFCE_PANEL_WINDOW (panel),
1080
(XfcePanelWindowMoveFunc)panel_move_function, panel);
1082
xfce_panel_window_set_resize_function (XFCE_PANEL_WINDOW (panel),
1083
(XfcePanelWindowResizeFunc)panel_resize_function, panel);
1087
panel_center (Panel *panel)
1095
if (priv->screen_position < XFCE_SCREEN_POSITION_FLOATING_H)
1098
xmon = panel_app_get_monitor (priv->monitor);
1100
gtk_widget_size_request (GTK_WIDGET (panel), &req);
1102
priv->xoffset = (xmon->geometry.width - req.width) / 2;
1103
priv->yoffset = (xmon->geometry.height - req.height) / 2;
1105
DBG ("\n + Position: %d\n + Offset: (%d, %d)",
1106
priv->screen_position, priv->xoffset, priv->yoffset);
1109
void panel_set_autohide (Panel *panel,
1118
if (autohide == priv->autohide)
1121
priv->autohide = autohide;
1123
if (!GTK_WIDGET_VISIBLE (panel))
1128
panel_set_hidden (panel, TRUE);
1130
/* If autohide is blocked unhide again.
1131
* We use the first panel_set_hidden() call to give the user
1132
* some visual feedback. */
1133
if (priv->block_autohide)
1135
while (gtk_events_pending ())
1136
gtk_main_iteration ();
1138
g_usleep (500000); /* 1/2 sec */
1139
panel_set_hidden (panel, FALSE);
1142
else if (priv->hidden)
1144
panel_set_hidden (panel, FALSE);
1148
gtk_window_get_position (GTK_WINDOW (panel), &x, &y);
1149
gtk_window_get_size (GTK_WINDOW (panel), &w, &h);
1151
xmon = panel_app_get_monitor (priv->monitor);
1153
_set_struts (panel, xmon, x, y, w, h);
1157
void panel_block_autohide (Panel *panel)
1165
priv->block_autohide++;
1168
panel_set_hidden (panel, FALSE);
1170
_set_transparent (panel, FALSE);
1173
void panel_unblock_autohide (Panel *panel)
1176
gint x, y, w, h, px, py;
1182
if (priv->block_autohide > 0)
1184
priv->block_autohide--;
1186
if (!priv->block_autohide)
1188
gdk_display_get_pointer (gdk_display_get_default (),
1189
NULL, &px, &py, NULL);
1191
gtk_window_get_position (GTK_WINDOW (panel), &x, &y);
1192
gtk_window_get_size (GTK_WINDOW (panel), &w, &h);
1194
if (px < x || px > x + w || py < y || py > y + h)
1196
if (priv->autohide && !priv->hidden)
1197
panel_set_hidden (panel, TRUE);
1199
_set_transparent (panel, TRUE);
1206
panel_set_full_width (Panel *panel,
1211
gint w = -1, h = -1, max = -1;
1215
if ((XfcePanelWidthType) fullwidth != priv->full_width)
1217
priv->full_width = (XfcePanelWidthType) fullwidth;
1219
if (GTK_WIDGET_VISIBLE (panel))
1221
xmon = panel_app_get_monitor (priv->monitor);
1223
switch (priv->full_width)
1225
case XFCE_PANEL_NORMAL_WIDTH:
1226
xfce_itembar_set_allow_expand (XFCE_ITEMBAR (priv->itembar),
1229
if (xfce_screen_position_is_horizontal (priv->screen_position))
1230
max = xmon->geometry.width;
1232
max = xmon->geometry.height;
1235
case XFCE_PANEL_FULL_WIDTH:
1236
case XFCE_PANEL_SPAN_MONITORS:
1237
xfce_itembar_set_allow_expand (XFCE_ITEMBAR (priv->itembar),
1239
if (xfce_screen_position_is_horizontal (
1240
priv->screen_position))
1242
if (priv->full_width == XFCE_PANEL_FULL_WIDTH)
1243
w = xmon->geometry.width;
1245
w = gdk_screen_get_width (xmon->screen);
1251
if (priv->full_width == XFCE_PANEL_FULL_WIDTH)
1252
h = xmon->geometry.height;
1254
h = gdk_screen_get_height (xmon->screen);
1261
xfce_itembar_set_maximum_size (XFCE_ITEMBAR (priv->itembar), max);
1263
gtk_widget_set_size_request (GTK_WIDGET (panel), w, h);
1265
panel_set_position (panel, priv->screen_position,
1266
priv->xoffset, priv->yoffset);
1268
gtk_widget_queue_resize (GTK_WIDGET (panel));
1274
panel_set_transparency (Panel *panel,
1281
if (transparency != priv->transparency)
1283
DBG ("Transparency: %d", transparency);
1285
priv->transparency = transparency;
1288
_set_transparent (panel, TRUE);
1293
panel_set_activetrans (Panel *panel,
1294
gboolean activetrans)
1296
PanelPrivate *priv = panel->priv;
1298
if (activetrans != priv->activetrans)
1300
priv->activetrans = activetrans;
1302
_set_transparent (panel, TRUE);
1309
panel_get_size (Panel *panel)
1313
g_return_val_if_fail (PANEL_IS_PANEL (panel), DEFAULT_SIZE);
1321
panel_set_size (Panel *panel,
1326
g_return_if_fail (PANEL_IS_PANEL (panel));
1330
if (xfce_screen_position_is_horizontal (priv->screen_position))
1332
gtk_widget_set_size_request (priv->itembar, -1, size);
1336
gtk_widget_set_size_request (priv->itembar, size, -1);
1339
if (size != priv->size)
1343
gtk_container_foreach (GTK_CONTAINER (priv->itembar),
1344
(GtkCallback)xfce_panel_item_set_size,
1345
GINT_TO_POINTER (size));
1350
panel_get_monitor (Panel *panel)
1354
g_return_val_if_fail (PANEL_IS_PANEL (panel), DEFAULT_MONITOR);
1358
return priv->monitor;
1362
panel_set_monitor (Panel *panel,
1367
XfcePanelWidthType width;
1369
g_return_if_fail (PANEL_IS_PANEL (panel));
1373
if (monitor != priv->monitor)
1375
/* TODO: check range */
1376
priv->monitor = monitor;
1378
xmon = panel_app_get_monitor (monitor);
1380
if (xmon->screen != gtk_widget_get_screen (GTK_WIDGET (panel)))
1382
gtk_widget_hide (GTK_WIDGET (panel));
1383
gtk_window_set_screen (GTK_WINDOW (panel), xmon->screen);
1384
gtk_widget_show (GTK_WIDGET (panel));
1387
/* new size constraints */
1388
if ((width = priv->full_width) != XFCE_PANEL_NORMAL_WIDTH)
1390
priv->full_width = XFCE_PANEL_NORMAL_WIDTH;
1391
panel_set_full_width (panel, width);
1395
gtk_widget_queue_resize (GTK_WIDGET (panel));
1401
panel_get_screen_position (Panel *panel)
1405
g_return_val_if_fail (PANEL_IS_PANEL (panel), DEFAULT_SCREEN_POSITION);
1409
return priv->screen_position;
1413
panel_set_screen_position (Panel *panel,
1414
XfceScreenPosition position)
1417
GtkOrientation orientation;
1418
XfcePanelWidthType full_width;
1420
g_return_if_fail (PANEL_IS_PANEL (panel));
1424
if (position != priv->screen_position)
1426
full_width = priv->full_width;
1428
/* use edit_mode property to test if we are changing position */
1429
priv->edit_mode = TRUE;
1431
xfce_panel_window_set_move_function (XFCE_PANEL_WINDOW (panel),
1434
xfce_panel_window_set_resize_function (XFCE_PANEL_WINDOW (panel),
1437
if (position == XFCE_SCREEN_POSITION_NONE)
1438
position = XFCE_SCREEN_POSITION_FLOATING_H;
1440
orientation = xfce_screen_position_get_orientation (position);
1442
if (xfce_screen_position_get_orientation (priv->screen_position) !=
1445
if (full_width > XFCE_PANEL_NORMAL_WIDTH)
1446
panel_set_full_width (panel, XFCE_PANEL_NORMAL_WIDTH);
1448
xfce_panel_window_set_orientation (XFCE_PANEL_WINDOW (panel),
1451
xfce_itembar_set_orientation (XFCE_ITEMBAR (priv->itembar),
1455
gtk_container_foreach (GTK_CONTAINER (priv->itembar),
1456
(GtkCallback)xfce_panel_item_set_screen_position,
1457
GINT_TO_POINTER (position));
1459
if (xfce_screen_position_is_floating (position))
1461
full_width = XFCE_PANEL_NORMAL_WIDTH;
1462
panel_set_full_width (panel, full_width);
1463
panel_set_autohide (panel, FALSE);
1464
xfce_panel_window_set_movable (XFCE_PANEL_WINDOW (panel), TRUE);
1466
if (!xfce_screen_position_is_floating (priv->screen_position))
1467
xfce_panel_window_set_handle_style (XFCE_PANEL_WINDOW (panel),
1468
XFCE_HANDLE_STYLE_BOTH);
1470
priv->xoffset = priv->yoffset = -1;
1474
xfce_panel_window_set_movable (XFCE_PANEL_WINDOW (panel), FALSE);
1475
xfce_panel_window_set_handle_style (XFCE_PANEL_WINDOW (panel),
1476
XFCE_HANDLE_STYLE_NONE);
1477
priv->xoffset = priv->yoffset = 0;
1480
xfce_panel_window_set_move_function (XFCE_PANEL_WINDOW (panel),
1481
(XfcePanelWindowMoveFunc)panel_move_function, panel);
1483
xfce_panel_window_set_resize_function (XFCE_PANEL_WINDOW (panel),
1484
(XfcePanelWindowResizeFunc)panel_resize_function, panel);
1486
priv->screen_position = position;
1487
panel_set_position (panel, position, priv->xoffset, priv->yoffset);
1489
if (full_width > XFCE_PANEL_NORMAL_WIDTH)
1491
panel_set_full_width (panel, full_width);
1494
/* update itembar size request */
1495
panel_set_size (panel, priv->size);
1497
gtk_widget_queue_resize (GTK_WIDGET (panel));
1499
g_idle_add((GSourceFunc)unblock_struts, panel);
1504
panel_get_xoffset (Panel *panel)
1508
g_return_val_if_fail (PANEL_IS_PANEL (panel), DEFAULT_XOFFSET);
1512
return priv->xoffset;
1516
panel_set_xoffset (Panel *panel,
1521
g_return_if_fail (PANEL_IS_PANEL (panel));
1525
if (xoffset != priv->xoffset)
1527
priv->xoffset = xoffset;
1528
panel_set_position (panel, priv->screen_position,
1529
xoffset, priv->yoffset);
1534
panel_get_yoffset (Panel *panel)
1538
g_return_val_if_fail (PANEL_IS_PANEL (panel), DEFAULT_YOFFSET);
1542
return priv->yoffset;
1546
panel_set_yoffset (Panel *panel,
1551
g_return_if_fail (PANEL_IS_PANEL (panel));
1555
if (yoffset != priv->yoffset)
1557
priv->yoffset = yoffset;
1558
panel_set_position (panel, priv->screen_position,
1559
priv->xoffset, yoffset);