~ubuntu-branches/debian/experimental/xfce4-panel/experimental

« back to all changes in this revision

Viewing changes to panel/panel-properties.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez, Lionel Le Folgoc, Yves-Alexis Perez
  • Date: 2011-02-06 18:10:07 UTC
  • mfrom: (1.3.13 upstream) (5.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110206181007-vpw5z3xnm3hdvybx
Tags: 4.8.1-1
[ Lionel Le Folgoc ]
* New upstream bugfix release.
* debian/control:
  - refreshed (b-)deps for this new major release
  - add myself to Uploaders
  - bump Standards-Version to 3.9.1.
* debian/NEWS: dropped, unneeded.
* debian/xfce4-panel.shlibs: refreshed, bump to (>= 4.7.2).
* debian/xfce4-panel.lintian-overrides: refreshed, new lib name.
* debian/xfce4-panel.preinst: added, handles removal of old conffiles.
* debian/xfce4-panel.postinst: explicitly set -e.
* debian/*.install: refreshed.
* debian/rules:
  - call dpkg-buildflags
  - dropped rc files mangling as they don't exist anymore
  - updated removal of *.{l,}a files.
  - drop overrides for dh_auto_{configure,clean}, obsolete.
* debian/xfce4-panel.{preinst,postinst,prerm}: use dpkg-maintscript-helper
  to remove pre-xfconf config files.
* Bugs fixed by 4.7.x/4.8.x series:
  - rgba support                                                  lp: #586012
  - disappearing menus                                             lp: #53897
  - xrandr support                               lp: #176174, Closes: #432914
  - Fails to reap children, creating zombies                      lp: #420187
  - DND of desktop-files on the panel to create new launchers Closes: #480380
* Bumped shlibs to >= 4.7.7, abi break for external plugins.

[ Yves-Alexis Perez ]
* New upstream development release
* debian/xfce4-panel.install:
  - install wrapper and migrate tools in xfce4-panel package
  - update plugins paths
* debian/rules:
  - update path when removing .a/.la files for plugins.
  - add hardening flags to {C,LD}FLAGS
* debian/control:
  - add build-dep on hardening-includes
  - update build-dep on garcon to 0.1.4.
* debian/copyright updated for new release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: panel-properties.c 29412 2009-01-30 19:20:31Z nick $
2
 
 *
3
 
 * Copyright (c) 2005 Jasper Huijsmans <jasper@xfce.org>
4
 
 *
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.
9
 
 *
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.
14
 
 *
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.
18
 
 */
19
 
 
20
 
#ifdef HAVE_CONFIG_H
21
 
#include <config.h>
22
 
#endif
23
 
 
24
 
#ifdef HAVE_STRING_H
25
 
#include <string.h>
26
 
#endif
27
 
#ifdef HAVE_TIME_H
28
 
#include <time.h>
29
 
#endif
30
 
#ifdef HAVE_MATH_H
31
 
#include <math.h>
32
 
#endif
33
 
 
34
 
#include <gtk/gtk.h>
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>
41
 
 
42
 
#include "panel-properties.h"
43
 
#include "panel-private.h"
44
 
#include "panel-dnd.h"
45
 
 
46
 
#define HIDDEN_SIZE     2
47
 
#define OPAQUE          0xffffffff
48
 
#define HIDE_TIMEOUT    350
49
 
#define UNHIDE_TIMEOUT  200
50
 
 
51
 
 
52
 
 
53
 
/* prototypes */
54
 
static void     panel_move_end          (XfcePanelWindow  *window,
55
 
                                         gint              x,
56
 
                                         gint              y);
57
 
static void     panel_move_function     (XfcePanelWindow  *window,
58
 
                                         Panel            *panel,
59
 
                                         gint             *x,
60
 
                                         gint             *y);
61
 
static void     panel_resize_function   (XfcePanelWindow  *window,
62
 
                                         Panel            *panel,
63
 
                                         GtkAllocation    *alloc_old,
64
 
                                         GtkAllocation    *alloc_new,
65
 
                                         gint             *x,
66
 
                                         gint             *y);
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);
73
 
 
74
 
 
75
 
 
76
 
/* moving and resizing */
77
 
static void
78
 
_calculate_coordinates (XfceScreenPosition  position, /* screen position */
79
 
                        GdkRectangle       *screen,   /* monitor geometry */
80
 
                        gint                width,    /* panel size */
81
 
                        gint                height,
82
 
                        gint                *x,       /* output coordinates */
83
 
                        gint                *y)
84
 
{
85
 
    switch (position)
86
 
    {
87
 
        /* floating */
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));
95
 
            break;
96
 
 
97
 
        /* top */
98
 
        case XFCE_SCREEN_POSITION_NW_H:
99
 
            *x = screen->x;
100
 
            *y = screen->y;
101
 
            break;
102
 
 
103
 
        case XFCE_SCREEN_POSITION_N:
104
 
            *x = MAX (screen->x, screen->x + (screen->width - width) / 2);
105
 
            *y = screen->y;
106
 
            break;
107
 
 
108
 
        case XFCE_SCREEN_POSITION_NE_H:
109
 
            *x = MAX (screen->x, screen->x + screen->width - width);
110
 
            *y = screen->y;
111
 
            break;
112
 
 
113
 
        /* left */
114
 
        case XFCE_SCREEN_POSITION_NW_V:
115
 
            *x = screen->x;
116
 
            *y = screen->y;
117
 
            break;
118
 
 
119
 
        case XFCE_SCREEN_POSITION_W:
120
 
            *x = screen->x;
121
 
            *y = MAX (screen->y, screen->y + (screen->height - height) / 2);
122
 
            break;
123
 
 
124
 
        case XFCE_SCREEN_POSITION_SW_V:
125
 
            *x = screen->x;
126
 
            *y = MAX (screen->y, screen->y + screen->height - height);
127
 
            break;
128
 
 
129
 
        /* right */
130
 
        case XFCE_SCREEN_POSITION_NE_V:
131
 
            *x = screen->x + screen->width - width;
132
 
            *y = screen->y;
133
 
            break;
134
 
 
135
 
        case XFCE_SCREEN_POSITION_E:
136
 
            *x = screen->x + screen->width - width;
137
 
            *y = MAX (screen->y, screen->y + (screen->height - height) / 2);
138
 
            break;
139
 
 
140
 
        case XFCE_SCREEN_POSITION_SE_V:
141
 
            *x = screen->x + screen->width - width;
142
 
            *y = MAX (screen->y, screen->y + screen->height - height);
143
 
            break;
144
 
 
145
 
        /* bottom */
146
 
        case XFCE_SCREEN_POSITION_SW_H:
147
 
            *x = screen->x;
148
 
            *y = screen->y + screen->height - height;
149
 
            break;
150
 
 
151
 
        case XFCE_SCREEN_POSITION_S:
152
 
            *x = MAX (screen->x, screen->x + (screen->width - width) / 2);
153
 
            *y = screen->y + screen->height - height;
154
 
            break;
155
 
 
156
 
        case XFCE_SCREEN_POSITION_SE_H:
157
 
            *x = MAX (screen->x, screen->x + screen->width - width);
158
 
            *y = screen->y + screen->height - height;
159
 
            break;
160
 
    }
161
 
}
162
 
 
163
 
 
164
 
 
165
 
static void
166
 
_set_borders (Panel *panel)
167
 
{
168
 
    PanelPrivate *priv;
169
 
    gboolean      top, bottom, left, right;
170
 
 
171
 
    priv = panel->priv;
172
 
 
173
 
    top = bottom = left = right = TRUE;
174
 
 
175
 
    switch (priv->screen_position)
176
 
    {
177
 
        /* floating */
178
 
        case XFCE_SCREEN_POSITION_NONE:
179
 
        case XFCE_SCREEN_POSITION_FLOATING_H:
180
 
        case XFCE_SCREEN_POSITION_FLOATING_V:
181
 
            break;
182
 
 
183
 
        /* top */
184
 
        case XFCE_SCREEN_POSITION_NW_H:
185
 
            top = left = FALSE;
186
 
            right = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
187
 
            break;
188
 
 
189
 
        case XFCE_SCREEN_POSITION_N:
190
 
            top = FALSE;
191
 
            left = right = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
192
 
            break;
193
 
 
194
 
        case XFCE_SCREEN_POSITION_NE_H:
195
 
            top = right = FALSE;
196
 
            left = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
197
 
            break;
198
 
 
199
 
        /* left */
200
 
        case XFCE_SCREEN_POSITION_NW_V:
201
 
            left = top = FALSE;
202
 
            bottom = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
203
 
            break;
204
 
 
205
 
        case XFCE_SCREEN_POSITION_W:
206
 
            left = FALSE;
207
 
            top = bottom = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
208
 
            break;
209
 
 
210
 
        case XFCE_SCREEN_POSITION_SW_V:
211
 
            left = bottom = FALSE;
212
 
            top = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
213
 
            break;
214
 
 
215
 
        /* right */
216
 
        case XFCE_SCREEN_POSITION_NE_V:
217
 
            right = top = FALSE;
218
 
            bottom = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
219
 
            break;
220
 
 
221
 
        case XFCE_SCREEN_POSITION_E:
222
 
            right = FALSE;
223
 
            top = bottom = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
224
 
            break;
225
 
 
226
 
        case XFCE_SCREEN_POSITION_SE_V:
227
 
            right = bottom = FALSE;
228
 
            top = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
229
 
            break;
230
 
 
231
 
        /* bottom */
232
 
        case XFCE_SCREEN_POSITION_SW_H:
233
 
            bottom = left = FALSE;
234
 
            right = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
235
 
            break;
236
 
 
237
 
        case XFCE_SCREEN_POSITION_S:
238
 
            bottom = FALSE;
239
 
            left = right = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
240
 
            break;
241
 
 
242
 
        case XFCE_SCREEN_POSITION_SE_H:
243
 
            bottom = right = FALSE;
244
 
            left = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH);
245
 
            break;
246
 
    }
247
 
 
248
 
    xfce_panel_window_set_show_border (XFCE_PANEL_WINDOW (panel),
249
 
                                       top, bottom, left, right);
250
 
}
251
 
 
252
 
/* fairly arbitrary maximum strut size */
253
 
static gboolean
254
 
_validate_strut( gint width,
255
 
                 gint offset )
256
 
{
257
 
    return ( offset < width / 4 );
258
 
}
259
 
 
260
 
static void
261
 
_set_struts (Panel       *panel,
262
 
             XfceMonitor *xmon,
263
 
             gint         x,
264
 
             gint         y,
265
 
             gint         w,
266
 
             gint         h)
267
 
{
268
 
    PanelPrivate *priv;
269
 
    gulong        data[12] = { 0, };
270
 
    gint          i;
271
 
    gboolean      update = FALSE;
272
 
 
273
 
    /* _NET_WM_STRUT_PARTIAL: CARDINAL[12]/32
274
 
     *
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
278
 
     *
279
 
     * Note: In xinerama use struts relative to combined screen dimensions,
280
 
     *       not just the current monitor.
281
 
     */
282
 
 
283
 
    priv = panel->priv;
284
 
 
285
 
    /* use edit_mode property to test if we are changing position */
286
 
    if (G_UNLIKELY (priv->edit_mode))
287
 
        return;
288
 
 
289
 
    if (!priv->autohide &&
290
 
            !xfce_screen_position_is_floating (priv->screen_position))
291
 
    {
292
 
        if (xfce_screen_position_is_left (priv->screen_position))
293
 
        {
294
 
            /* no struts possible on Xinerama screens when this monitor
295
 
             * has neighbors on the left (see fd.o spec).
296
 
             */
297
 
            if (!xmon->has_neighbor_left
298
 
                && _validate_strut (xmon->geometry.width, w))
299
 
            {
300
 
                data[0] = xmon->geometry.x + w; /* left           */
301
 
                data[4] = y;                    /* left_start_y   */
302
 
                data[5] = y + h - 1;            /* left_end_y     */
303
 
            }
304
 
        }
305
 
        else if (xfce_screen_position_is_right (priv->screen_position))
306
 
        {
307
 
            /* no struts possible on Xinerama screens when this monitor
308
 
             * has neighbors on the right (see fd.o spec).
309
 
             */
310
 
            if (!xmon->has_neighbor_right
311
 
                && _validate_strut (xmon->geometry.width, w))
312
 
            {
313
 
                data[1] =  gdk_screen_get_width (xmon->screen)
314
 
                           - xmon->geometry.x - xmon->geometry.width
315
 
                           + w;         /* right          */
316
 
                data[6] = y;            /* right_start_y  */
317
 
                data[7] = y + h - 1;    /* right_end_y    */
318
 
            }
319
 
        }
320
 
        else if (xfce_screen_position_is_top (priv->screen_position))
321
 
        {
322
 
            /* no struts possible on Xinerama screens when this monitor
323
 
             * has neighbors on the top (see fd.o spec).
324
 
             */
325
 
            if (!xmon->has_neighbor_above
326
 
                && _validate_strut (xmon->geometry.height, h))
327
 
            {
328
 
                data[2] = xmon->geometry.y
329
 
                          + h;          /* top            */
330
 
                data[8] = x;            /* top_start_x    */
331
 
                data[9] = x + w - 1;    /* top_end_x      */
332
 
            }
333
 
        }
334
 
        else
335
 
        {
336
 
            /* no struts possible on Xinerama screens when this monitor
337
 
             * has neighbors on the bottom (see fd.o spec).
338
 
             */
339
 
            if (!xmon->has_neighbor_below
340
 
                && _validate_strut (xmon->geometry.height, h))
341
 
            {
342
 
                data[3] = gdk_screen_get_height (xmon->screen)
343
 
                           - xmon->geometry.y - xmon->geometry.height
344
 
                           + h;         /* bottom         */
345
 
                data[10] = x;           /* bottom_start_x */
346
 
                data[11] = x + w - 1;   /* bottom_end_x   */
347
 
            }
348
 
        }
349
 
    }
350
 
 
351
 
    DBG ("\nStruts\n"
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]);
358
 
 
359
 
    /* Check if values have changed. */
360
 
    for (i = 0; i < 12; i++)
361
 
    {
362
 
        if (data[i] != priv->struts[i])
363
 
        {
364
 
            update = TRUE;
365
 
            priv->struts[i] = data[i];
366
 
        }
367
 
    }
368
 
 
369
 
    if (update)
370
 
    {
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 ();
377
 
 
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 ();
384
 
    }
385
 
 
386
 
    DBG ("all struts are checked and updated");
387
 
}
388
 
 
389
 
static gboolean
390
 
unblock_struts (Panel *panel)
391
 
{
392
 
    PanelPrivate *priv;
393
 
    XfceMonitor  *xmon;
394
 
    gint          x, y, w, h;
395
 
 
396
 
    priv = PANEL (panel)->priv;
397
 
    priv->edit_mode = FALSE;
398
 
 
399
 
    gtk_window_get_position (GTK_WINDOW (panel), &x, &y);
400
 
    gtk_window_get_size (GTK_WINDOW (panel), &w, &h);
401
 
 
402
 
    xmon = panel_app_get_monitor (priv->monitor);
403
 
 
404
 
    _set_struts (panel, xmon, x, y, w, h);
405
 
    return FALSE;
406
 
}
407
 
 
408
 
static void
409
 
panel_move_end (XfcePanelWindow *window,
410
 
                gint             x,
411
 
                gint             y)
412
 
{
413
 
    PanelPrivate *priv;
414
 
    XfceMonitor  *xmon;
415
 
 
416
 
    priv = PANEL (window)->priv;
417
 
 
418
 
    if (xfce_screen_position_is_floating (priv->screen_position))
419
 
    {
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));
426
 
    }
427
 
 
428
 
    xmon = panel_app_get_monitor (priv->monitor);
429
 
 
430
 
    priv->xoffset = x - xmon->geometry.x;
431
 
    priv->yoffset = y - xmon->geometry.y;
432
 
 
433
 
    DBG ("\n + Position: %d\n + Offset: (%d, %d)",
434
 
         priv->screen_position, priv->xoffset, priv->yoffset);
435
 
 
436
 
    panel_app_queue_save ();
437
 
}
438
 
 
439
 
static void
440
 
panel_move_function (XfcePanelWindow *window,
441
 
                     Panel           *panel,
442
 
                     gint            *x,
443
 
                     gint            *y)
444
 
{
445
 
    PanelPrivate *priv;
446
 
    XfceMonitor  *xmon;
447
 
    GdkScreen    *screen;
448
 
 
449
 
    priv = panel->priv;
450
 
 
451
 
    screen = gtk_widget_get_screen (GTK_WIDGET (window));
452
 
    priv->monitor = gdk_screen_get_monitor_at_point (screen, *x, *y);
453
 
 
454
 
    DBG (" + Monitor at (%d, %d) = %d\n", *x, *y, priv->monitor);
455
 
 
456
 
    xmon = panel_app_get_monitor (priv->monitor);
457
 
 
458
 
    _calculate_coordinates (priv->screen_position,
459
 
                            &(xmon->geometry),
460
 
                            GTK_WIDGET (window)->allocation.width,
461
 
                            GTK_WIDGET (window)->allocation.height,
462
 
                            x, y);
463
 
}
464
 
 
465
 
static void
466
 
panel_resize_function (XfcePanelWindow *window,
467
 
                       Panel           *panel,
468
 
                       GtkAllocation   *alloc_old,
469
 
                       GtkAllocation   *alloc_new,
470
 
                       gint            *x,
471
 
                       gint            *y)
472
 
{
473
 
    PanelPrivate *priv;
474
 
    XfceMonitor  *xmon;
475
 
    GdkRectangle  rect;
476
 
 
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 );
480
 
 
481
 
    if (!GTK_WIDGET_VISIBLE (panel))
482
 
        return;
483
 
 
484
 
    priv = panel->priv;
485
 
    xmon = panel_app_get_monitor (priv->monitor);
486
 
 
487
 
    if (priv->full_width < XFCE_PANEL_SPAN_MONITORS)
488
 
    {
489
 
        _calculate_coordinates (priv->screen_position,
490
 
                                &(xmon->geometry),
491
 
                                alloc_new->width,
492
 
                                alloc_new->height,
493
 
                                x, y);
494
 
 
495
 
        priv->xoffset = *x - xmon->geometry.x;
496
 
        priv->yoffset = *y - xmon->geometry.y;
497
 
    }
498
 
    else
499
 
    {
500
 
        rect.x      = 0;
501
 
        rect.y      = 0;
502
 
        rect.width  = gdk_screen_get_width (xmon->screen);
503
 
        rect.height = gdk_screen_get_height (xmon->screen);
504
 
 
505
 
        _calculate_coordinates (priv->screen_position,
506
 
                                &rect,
507
 
                                alloc_new->width,
508
 
                                alloc_new->height,
509
 
                                x, y);
510
 
 
511
 
        priv->xoffset = *x;
512
 
        priv->yoffset = *y;
513
 
    }
514
 
 
515
 
    _set_struts (panel, xmon, *x, *y, alloc_new->width, alloc_new->height);
516
 
}
517
 
 
518
 
static void
519
 
panel_set_position (Panel              *panel,
520
 
                    XfceScreenPosition  position,
521
 
                    gint                xoffset,
522
 
                    gint                yoffset)
523
 
{
524
 
    PanelPrivate   *priv;
525
 
    GtkRequisition  req;
526
 
    gint            x, y;
527
 
    XfceMonitor    *xmon;
528
 
    GdkRectangle    rect;
529
 
 
530
 
    if (!GTK_WIDGET_VISIBLE (panel))
531
 
        return;
532
 
 
533
 
    priv = panel->priv;
534
 
    xmon = panel_app_get_monitor (priv->monitor);
535
 
 
536
 
    priv->screen_position = position;
537
 
    _set_borders (panel);
538
 
 
539
 
    gtk_widget_size_request (GTK_WIDGET (panel), &req);
540
 
 
541
 
    x = y = 0;
542
 
 
543
 
    /* NOTE: xoffset and yoffset are only used for floating panels */
544
 
    if (xfce_screen_position_is_floating (position))
545
 
    {
546
 
        if (G_UNLIKELY (xoffset < 0 || yoffset < 0))
547
 
        {
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);
551
 
        }
552
 
        else
553
 
        {
554
 
            x = xmon->geometry.x + xoffset;
555
 
            y = xmon->geometry.y + yoffset;
556
 
        }
557
 
    }
558
 
 
559
 
    if (priv->full_width < XFCE_PANEL_SPAN_MONITORS)
560
 
    {
561
 
        _calculate_coordinates (position,
562
 
                                &(xmon->geometry),
563
 
                                req.width,
564
 
                                req.height,
565
 
                                &x, &y);
566
 
 
567
 
        priv->xoffset = x - xmon->geometry.x;
568
 
        priv->yoffset = y - xmon->geometry.y;
569
 
    }
570
 
    else
571
 
    {
572
 
        rect.x      = 0;
573
 
        rect.y      = 0;
574
 
        rect.width  = gdk_screen_get_width (xmon->screen);
575
 
        rect.height = gdk_screen_get_height (xmon->screen);
576
 
 
577
 
        _calculate_coordinates (position,
578
 
                                &rect,
579
 
                                req.width,
580
 
                                req.height,
581
 
                                &x, &y);
582
 
 
583
 
        priv->xoffset = x;
584
 
        priv->yoffset = y;
585
 
    }
586
 
 
587
 
    DBG ("\n + Position: %d\n + Offset: (%d, %d)",
588
 
         priv->screen_position, priv->xoffset, priv->yoffset);
589
 
 
590
 
    DBG (" + coordinates: (%d, %d)\n", x, y);
591
 
 
592
 
    gtk_window_move (GTK_WINDOW (panel), x, y);
593
 
 
594
 
    _set_struts (panel, xmon, x, y, req.width, req.height);
595
 
}
596
 
 
597
 
/* screen size */
598
 
void
599
 
panel_screen_size_changed (GdkScreen *screen,
600
 
                           Panel     *panel)
601
 
{
602
 
    PanelPrivate       *priv;
603
 
    XfceMonitor        *xmon;
604
 
    XfcePanelWidthType  width;
605
 
 
606
 
    priv = panel->priv;
607
 
 
608
 
    xmon = panel_app_get_monitor (priv->monitor);
609
 
 
610
 
    gdk_screen_get_monitor_geometry (screen,
611
 
                                     xmon->num,
612
 
                                     &(xmon->geometry));
613
 
 
614
 
    /* new size constraints */
615
 
    if ((width = priv->full_width) != XFCE_PANEL_NORMAL_WIDTH)
616
 
    {
617
 
        priv->full_width = XFCE_PANEL_NORMAL_WIDTH;
618
 
        panel_set_full_width (panel, width);
619
 
    }
620
 
    else
621
 
    {
622
 
        gtk_widget_queue_resize (GTK_WIDGET (panel));
623
 
    }
624
 
}
625
 
 
626
 
/* transparency and autohide */
627
 
static void
628
 
_set_transparent (Panel    *panel,
629
 
                  gboolean  transparent)
630
 
{
631
 
    PanelPrivate *priv;
632
 
    gulong        opacity;
633
 
 
634
 
    if (!GTK_WIDGET (panel)->window)
635
 
        return;
636
 
 
637
 
    priv = panel->priv;
638
 
 
639
 
    if (G_UNLIKELY (priv->opacity == 0))
640
 
    {
641
 
        if (priv->transparency != 0)
642
 
        {
643
 
            priv->opacity =
644
 
                OPAQUE - rint ((gdouble)priv->transparency * OPAQUE / 100);
645
 
        }
646
 
        else
647
 
        {
648
 
            priv->opacity = OPAQUE;
649
 
        }
650
 
    }
651
 
 
652
 
    opacity = (transparent || priv->activetrans) ? priv->opacity : OPAQUE;
653
 
 
654
 
    if (opacity != priv->saved_opacity)
655
 
    {
656
 
        priv->saved_opacity = opacity;
657
 
 
658
 
        gdk_error_trap_push ();
659
 
 
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,
665
 
                             1L);
666
 
 
667
 
        gdk_error_trap_pop ();
668
 
 
669
 
        gtk_widget_queue_draw (GTK_WIDGET (panel));
670
 
    }
671
 
}
672
 
 
673
 
void
674
 
panel_set_hidden (Panel    *panel,
675
 
                  gboolean  hide)
676
 
{
677
 
    PanelPrivate *priv;
678
 
    gint          w, h;
679
 
    XfceMonitor  *xmon;
680
 
 
681
 
    priv = panel->priv;
682
 
 
683
 
    priv->hidden = hide;
684
 
    w = h = 0;
685
 
 
686
 
    if (hide)
687
 
    {
688
 
        if (xfce_screen_position_is_horizontal (priv->screen_position))
689
 
        {
690
 
            w = GTK_WIDGET (panel)->allocation.width;
691
 
            h = HIDDEN_SIZE;
692
 
        }
693
 
        else
694
 
        {
695
 
            w = HIDDEN_SIZE;
696
 
            h = GTK_WIDGET (panel)->allocation.height;
697
 
        }
698
 
 
699
 
        gtk_widget_hide (priv->itembar);
700
 
    }
701
 
    else
702
 
    {
703
 
        xmon = panel_app_get_monitor (priv->monitor);
704
 
 
705
 
        switch (priv->full_width)
706
 
        {
707
 
            case XFCE_PANEL_NORMAL_WIDTH:
708
 
                w = h = -1;
709
 
                break;
710
 
 
711
 
            case XFCE_PANEL_FULL_WIDTH:
712
 
            case XFCE_PANEL_SPAN_MONITORS:
713
 
                if (xfce_screen_position_is_horizontal (priv->screen_position))
714
 
                {
715
 
                    h = -1;
716
 
                    if (priv->full_width == XFCE_PANEL_FULL_WIDTH)
717
 
                        w = xmon->geometry.width;
718
 
                    else
719
 
                        w = gdk_screen_get_width (xmon->screen);
720
 
                }
721
 
                else
722
 
                {
723
 
                    w = -1;
724
 
                    if (priv->full_width == XFCE_PANEL_FULL_WIDTH)
725
 
                        h = xmon->geometry.height;
726
 
                    else
727
 
                        h = gdk_screen_get_height (xmon->screen);
728
 
                }
729
 
                break;
730
 
        }
731
 
 
732
 
        gtk_widget_show (priv->itembar);
733
 
    }
734
 
 
735
 
    gtk_widget_set_size_request (GTK_WIDGET (panel), w, h);
736
 
}
737
 
 
738
 
static gboolean
739
 
_hide_timeout (Panel *panel)
740
 
{
741
 
    PanelPrivate *priv;
742
 
 
743
 
    priv = panel->priv;
744
 
    priv->hide_timeout = 0;
745
 
 
746
 
    if (!priv->hidden && !priv->block_autohide)
747
 
        panel_set_hidden (panel, TRUE);
748
 
 
749
 
    return FALSE;
750
 
}
751
 
 
752
 
static gboolean
753
 
_unhide_timeout (Panel *panel)
754
 
{
755
 
    PanelPrivate *priv;
756
 
 
757
 
    priv = panel->priv;
758
 
    priv->unhide_timeout = 0;
759
 
 
760
 
    if (priv->hidden)
761
 
        panel_set_hidden (panel, FALSE);
762
 
 
763
 
    return FALSE;
764
 
}
765
 
 
766
 
static gboolean
767
 
drag_motion (Panel          *panel,
768
 
             GdkDragContext *context,
769
 
             int             x,
770
 
             int             y,
771
 
             guint           time_,
772
 
             gpointer        user_data)
773
 
{
774
 
    PanelPrivate *priv;
775
 
 
776
 
    priv = panel->priv;
777
 
 
778
 
    if (!priv->hidden || priv->block_autohide)
779
 
        return TRUE;
780
 
 
781
 
    if (priv->hide_timeout)
782
 
    {
783
 
        g_source_remove (priv->hide_timeout);
784
 
        priv->hide_timeout = 0;
785
 
    }
786
 
 
787
 
    if (!priv->unhide_timeout)
788
 
    {
789
 
        priv->unhide_timeout =
790
 
            g_timeout_add (UNHIDE_TIMEOUT,
791
 
                           (GSourceFunc) _unhide_timeout, panel);
792
 
    }
793
 
 
794
 
    return TRUE;
795
 
}
796
 
 
797
 
 
798
 
static void
799
 
drag_leave (Panel          *panel,
800
 
            GdkDragContext *drag_context,
801
 
            guint           time_,
802
 
            gpointer        user_data)
803
 
{
804
 
    int    x, y, w, h, px, py;
805
 
    PanelPrivate *priv;
806
 
 
807
 
    priv = panel->priv;
808
 
 
809
 
    if (!priv->autohide || priv->hidden || priv->block_autohide)
810
 
        return;
811
 
 
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);
816
 
 
817
 
    if (px < x || px > x + w || py < y || py > y + h)
818
 
    {
819
 
        if (priv->unhide_timeout)
820
 
        {
821
 
            g_source_remove (priv->unhide_timeout);
822
 
            priv->unhide_timeout = 0;
823
 
        }
824
 
 
825
 
        if (!priv->hide_timeout)
826
 
        {
827
 
            priv->hide_timeout =
828
 
                g_timeout_add (HIDE_TIMEOUT,
829
 
                               (GSourceFunc) _hide_timeout, panel);
830
 
        }
831
 
    }
832
 
}
833
 
 
834
 
 
835
 
static void
836
 
panel_enter (Panel            *panel,
837
 
             GdkEventCrossing *event)
838
 
{
839
 
    PanelPrivate *priv;
840
 
 
841
 
    if (event->detail != GDK_NOTIFY_INFERIOR)
842
 
    {
843
 
        panel_app_set_current_panel ((gpointer)panel);
844
 
 
845
 
        priv = panel->priv;
846
 
 
847
 
        if (priv->block_autohide)
848
 
            return;
849
 
 
850
 
        _set_transparent (panel, FALSE);
851
 
 
852
 
        if (!priv->autohide)
853
 
            return;
854
 
 
855
 
        if (priv->hide_timeout)
856
 
        {
857
 
            g_source_remove (priv->hide_timeout);
858
 
            priv->hide_timeout = 0;
859
 
        }
860
 
 
861
 
        if (priv->hidden)
862
 
            priv->unhide_timeout = g_timeout_add (UNHIDE_TIMEOUT,
863
 
                                                  (GSourceFunc)_unhide_timeout,
864
 
                                                  panel);
865
 
    }
866
 
}
867
 
 
868
 
 
869
 
static void
870
 
panel_leave (Panel            *panel,
871
 
             GdkEventCrossing *event)
872
 
{
873
 
    PanelPrivate *priv;
874
 
 
875
 
    if (event->detail != GDK_NOTIFY_INFERIOR)
876
 
    {
877
 
        priv = panel->priv;
878
 
 
879
 
        if (priv->block_autohide)
880
 
            return;
881
 
 
882
 
        _set_transparent (panel, TRUE);
883
 
 
884
 
        if (!priv->autohide)
885
 
            return;
886
 
 
887
 
        if (priv->unhide_timeout)
888
 
        {
889
 
            g_source_remove (priv->unhide_timeout);
890
 
            priv->unhide_timeout = 0;
891
 
        }
892
 
 
893
 
        if (!priv->hidden)
894
 
            priv->hide_timeout = g_timeout_add (HIDE_TIMEOUT,
895
 
                                                (GSourceFunc)_hide_timeout,
896
 
                                                panel);
897
 
    }
898
 
}
899
 
 
900
 
static void
901
 
panel_grabbed (Panel    *panel,
902
 
               gboolean  was_grabbed)
903
 
{
904
 
    PanelPrivate *priv = panel->priv;
905
 
 
906
 
    /* block the panel if the widget is grabbed */
907
 
    if (was_grabbed)
908
 
        priv->block_autohide--;
909
 
    else
910
 
        priv->block_autohide++;
911
 
}
912
 
 
913
 
static void
914
 
_window_mapped (Panel *panel)
915
 
{
916
 
    PanelPrivate *priv;
917
 
    XfceMonitor  *xmon;
918
 
    gint          x, y;
919
 
 
920
 
    priv = panel->priv;
921
 
 
922
 
    panel_set_position (panel,
923
 
                        priv->screen_position,
924
 
                        priv->xoffset,
925
 
                        priv->yoffset);
926
 
 
927
 
    _set_transparent (panel, TRUE);
928
 
 
929
 
    gtk_window_get_position (GTK_WINDOW (panel), &x, &y);
930
 
 
931
 
    xmon = panel_app_get_monitor (priv->monitor);
932
 
    priv->xoffset = x - xmon->geometry.x;
933
 
    priv->yoffset = y - xmon->geometry.y;
934
 
 
935
 
    DBG (" + coordinates: (%d, %d)\n", x, y);
936
 
 
937
 
    DBG ("\n + Position: %d\n + Offset: (%d, %d)",
938
 
         priv->screen_position, priv->xoffset, priv->yoffset);
939
 
 
940
 
    if (priv->autohide)
941
 
    {
942
 
        priv->hide_timeout =
943
 
            g_timeout_add (2000, (GSourceFunc)_hide_timeout, panel);
944
 
    }
945
 
 
946
 
}
947
 
 
948
 
/* public API */
949
 
void panel_init_signals (Panel *panel)
950
 
{
951
 
    DBG (" + Connect signals for panel %p", panel);
952
 
 
953
 
    g_signal_connect (G_OBJECT (panel), "enter-notify-event",
954
 
                      G_CALLBACK (panel_enter), NULL);
955
 
 
956
 
    g_signal_connect (G_OBJECT (panel), "leave-notify-event",
957
 
                      G_CALLBACK (panel_leave), NULL);
958
 
 
959
 
    g_signal_connect (G_OBJECT (panel), "grab-notify",
960
 
                      G_CALLBACK (panel_grabbed), NULL);
961
 
 
962
 
    g_signal_connect (G_OBJECT (panel), "map",
963
 
                      G_CALLBACK (_window_mapped), NULL);
964
 
 
965
 
    g_signal_connect (G_OBJECT (panel), "move-end",
966
 
                      G_CALLBACK (panel_move_end), NULL);
967
 
 
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);
971
 
}
972
 
 
973
 
void
974
 
panel_init_position (Panel *panel)
975
 
{
976
 
    PanelPrivate   *priv;
977
 
    GtkOrientation  orientation;
978
 
    XfceMonitor    *xmon;
979
 
    gint            x, y, w, h, max;
980
 
    GtkRequisition  req;
981
 
    GdkRectangle    rect;
982
 
 
983
 
    priv = panel->priv;
984
 
 
985
 
    orientation =
986
 
        xfce_screen_position_is_horizontal (priv->screen_position) ?
987
 
                GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
988
 
 
989
 
    xfce_panel_window_set_orientation (XFCE_PANEL_WINDOW (panel), orientation);
990
 
    xfce_itembar_set_orientation (XFCE_ITEMBAR (priv->itembar), orientation);
991
 
 
992
 
    xmon = panel_app_get_monitor (priv->monitor);
993
 
 
994
 
    gtk_window_set_screen (GTK_WINDOW (panel), xmon->screen);
995
 
 
996
 
    w = h = -1;
997
 
 
998
 
    if (priv->full_width > XFCE_PANEL_NORMAL_WIDTH)
999
 
        xfce_itembar_set_allow_expand (XFCE_ITEMBAR (priv->itembar), TRUE);
1000
 
 
1001
 
    if (xfce_screen_position_is_horizontal (priv->screen_position))
1002
 
    {
1003
 
        if (priv->full_width < XFCE_PANEL_SPAN_MONITORS)
1004
 
            w = xmon->geometry.width;
1005
 
        else
1006
 
            w = gdk_screen_get_width (xmon->screen);
1007
 
 
1008
 
        max = w;
1009
 
    }
1010
 
    else
1011
 
    {
1012
 
        if (priv->full_width < XFCE_PANEL_SPAN_MONITORS)
1013
 
            h = xmon->geometry.height;
1014
 
        else
1015
 
            h = gdk_screen_get_height (xmon->screen);
1016
 
 
1017
 
        max = h;
1018
 
    }
1019
 
 
1020
 
    xfce_itembar_set_maximum_size (XFCE_ITEMBAR (priv->itembar), max);
1021
 
 
1022
 
    if (priv->full_width > XFCE_PANEL_NORMAL_WIDTH)
1023
 
        gtk_widget_set_size_request (GTK_WIDGET (panel), w, h);
1024
 
 
1025
 
    if (!xfce_screen_position_is_floating (priv->screen_position))
1026
 
    {
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);
1030
 
    }
1031
 
 
1032
 
    x = xmon->geometry.x;
1033
 
    y = xmon->geometry.y;
1034
 
 
1035
 
    if (priv->xoffset > 0 || priv->yoffset > 0)
1036
 
    {
1037
 
        x += priv->xoffset;
1038
 
        y += priv->yoffset;
1039
 
    }
1040
 
    else
1041
 
    {
1042
 
        if (priv->full_width < XFCE_PANEL_SPAN_MONITORS)
1043
 
        {
1044
 
            gtk_widget_size_request (GTK_WIDGET (panel), &req);
1045
 
            _calculate_coordinates (priv->screen_position,
1046
 
                                    &(xmon->geometry),
1047
 
                                    req.width,
1048
 
                                    req.height,
1049
 
                                    &x, &y);
1050
 
 
1051
 
            priv->xoffset = x - xmon->geometry.x;
1052
 
            priv->yoffset = y - xmon->geometry.y;
1053
 
        }
1054
 
        else
1055
 
        {
1056
 
            rect.x      = 0;
1057
 
            rect.y      = 0;
1058
 
            rect.width  = gdk_screen_get_width (xmon->screen);
1059
 
            rect.height = gdk_screen_get_height (xmon->screen);
1060
 
 
1061
 
            _calculate_coordinates (priv->screen_position,
1062
 
                                    &rect,
1063
 
                                    req.width,
1064
 
                                    req.height,
1065
 
                                    &x, &y);
1066
 
 
1067
 
            priv->xoffset = x;
1068
 
            priv->yoffset = y;
1069
 
        }
1070
 
    }
1071
 
 
1072
 
    DBG (" + offsets: (%d, %d)\n",
1073
 
             priv->xoffset, priv->yoffset);
1074
 
 
1075
 
    DBG (" + coordinates: (%d, %d)\n", x, y);
1076
 
 
1077
 
    gtk_window_move (GTK_WINDOW (panel), x, y);
1078
 
 
1079
 
    xfce_panel_window_set_move_function (XFCE_PANEL_WINDOW (panel),
1080
 
            (XfcePanelWindowMoveFunc)panel_move_function, panel);
1081
 
 
1082
 
    xfce_panel_window_set_resize_function (XFCE_PANEL_WINDOW (panel),
1083
 
            (XfcePanelWindowResizeFunc)panel_resize_function, panel);
1084
 
}
1085
 
 
1086
 
void
1087
 
panel_center (Panel *panel)
1088
 
{
1089
 
    PanelPrivate   *priv;
1090
 
    GtkRequisition  req;
1091
 
    XfceMonitor    *xmon;
1092
 
 
1093
 
    priv = panel->priv;
1094
 
 
1095
 
    if (priv->screen_position < XFCE_SCREEN_POSITION_FLOATING_H)
1096
 
        return;
1097
 
 
1098
 
    xmon = panel_app_get_monitor (priv->monitor);
1099
 
 
1100
 
    gtk_widget_size_request (GTK_WIDGET (panel), &req);
1101
 
 
1102
 
    priv->xoffset = (xmon->geometry.width - req.width) / 2;
1103
 
    priv->yoffset = (xmon->geometry.height - req.height) / 2;
1104
 
 
1105
 
    DBG ("\n + Position: %d\n + Offset: (%d, %d)",
1106
 
         priv->screen_position, priv->xoffset, priv->yoffset);
1107
 
}
1108
 
 
1109
 
void panel_set_autohide (Panel    *panel,
1110
 
                         gboolean  autohide)
1111
 
{
1112
 
    PanelPrivate *priv;
1113
 
    gint          x, y, w, h;
1114
 
    XfceMonitor  *xmon;
1115
 
 
1116
 
    priv = panel->priv;
1117
 
 
1118
 
    if (autohide == priv->autohide)
1119
 
        return;
1120
 
 
1121
 
    priv->autohide = autohide;
1122
 
 
1123
 
    if (!GTK_WIDGET_VISIBLE (panel))
1124
 
        return;
1125
 
 
1126
 
    if (autohide)
1127
 
    {
1128
 
        panel_set_hidden (panel, TRUE);
1129
 
 
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)
1134
 
        {
1135
 
            while (gtk_events_pending ())
1136
 
                gtk_main_iteration ();
1137
 
 
1138
 
            g_usleep (500000); /* 1/2 sec */
1139
 
            panel_set_hidden (panel, FALSE);
1140
 
        }
1141
 
    }
1142
 
    else if (priv->hidden)
1143
 
    {
1144
 
        panel_set_hidden (panel, FALSE);
1145
 
    }
1146
 
    else
1147
 
    {
1148
 
        gtk_window_get_position (GTK_WINDOW (panel), &x, &y);
1149
 
        gtk_window_get_size (GTK_WINDOW (panel), &w, &h);
1150
 
 
1151
 
        xmon = panel_app_get_monitor (priv->monitor);
1152
 
 
1153
 
        _set_struts (panel, xmon, x, y, w, h);
1154
 
    }
1155
 
}
1156
 
 
1157
 
void panel_block_autohide (Panel *panel)
1158
 
{
1159
 
    PanelPrivate *priv;
1160
 
 
1161
 
    DBG ("block");
1162
 
 
1163
 
    priv = panel->priv;
1164
 
 
1165
 
    priv->block_autohide++;
1166
 
 
1167
 
    if (priv->hidden)
1168
 
        panel_set_hidden (panel, FALSE);
1169
 
 
1170
 
    _set_transparent (panel, FALSE);
1171
 
}
1172
 
 
1173
 
void panel_unblock_autohide (Panel *panel)
1174
 
{
1175
 
    PanelPrivate *priv;
1176
 
    gint          x, y, w, h, px, py;
1177
 
 
1178
 
    DBG ("unblock");
1179
 
 
1180
 
    priv = panel->priv;
1181
 
 
1182
 
    if (priv->block_autohide > 0)
1183
 
    {
1184
 
        priv->block_autohide--;
1185
 
 
1186
 
        if (!priv->block_autohide)
1187
 
        {
1188
 
            gdk_display_get_pointer (gdk_display_get_default (),
1189
 
                                     NULL, &px, &py, NULL);
1190
 
 
1191
 
            gtk_window_get_position (GTK_WINDOW (panel), &x, &y);
1192
 
            gtk_window_get_size (GTK_WINDOW (panel), &w, &h);
1193
 
 
1194
 
            if (px < x || px > x + w || py < y || py > y + h)
1195
 
            {
1196
 
                if (priv->autohide && !priv->hidden)
1197
 
                    panel_set_hidden (panel, TRUE);
1198
 
 
1199
 
                _set_transparent (panel, TRUE);
1200
 
            }
1201
 
        }
1202
 
    }
1203
 
}
1204
 
 
1205
 
void
1206
 
panel_set_full_width (Panel *panel,
1207
 
                      gint   fullwidth)
1208
 
{
1209
 
    PanelPrivate *priv;
1210
 
    XfceMonitor  *xmon;
1211
 
    gint          w = -1, h = -1, max = -1;
1212
 
 
1213
 
    priv = panel->priv;
1214
 
 
1215
 
    if ((XfcePanelWidthType) fullwidth != priv->full_width)
1216
 
    {
1217
 
        priv->full_width = (XfcePanelWidthType) fullwidth;
1218
 
 
1219
 
        if (GTK_WIDGET_VISIBLE (panel))
1220
 
        {
1221
 
            xmon = panel_app_get_monitor (priv->monitor);
1222
 
 
1223
 
            switch (priv->full_width)
1224
 
            {
1225
 
                case XFCE_PANEL_NORMAL_WIDTH:
1226
 
                    xfce_itembar_set_allow_expand (XFCE_ITEMBAR (priv->itembar),
1227
 
                                                   FALSE);
1228
 
 
1229
 
                    if (xfce_screen_position_is_horizontal (priv->screen_position))
1230
 
                        max = xmon->geometry.width;
1231
 
                    else
1232
 
                        max = xmon->geometry.height;
1233
 
                    break;
1234
 
 
1235
 
                case XFCE_PANEL_FULL_WIDTH:
1236
 
                case XFCE_PANEL_SPAN_MONITORS:
1237
 
                    xfce_itembar_set_allow_expand (XFCE_ITEMBAR (priv->itembar),
1238
 
                                                   TRUE);
1239
 
                    if (xfce_screen_position_is_horizontal (
1240
 
                                priv->screen_position))
1241
 
                    {
1242
 
                        if (priv->full_width == XFCE_PANEL_FULL_WIDTH)
1243
 
                            w = xmon->geometry.width;
1244
 
                        else
1245
 
                            w = gdk_screen_get_width (xmon->screen);
1246
 
 
1247
 
                        max = w;
1248
 
                    }
1249
 
                    else
1250
 
                    {
1251
 
                        if (priv->full_width == XFCE_PANEL_FULL_WIDTH)
1252
 
                            h = xmon->geometry.height;
1253
 
                        else
1254
 
                            h = gdk_screen_get_height (xmon->screen);
1255
 
 
1256
 
                        max = h;
1257
 
                    }
1258
 
                    break;
1259
 
            }
1260
 
 
1261
 
            xfce_itembar_set_maximum_size (XFCE_ITEMBAR (priv->itembar), max);
1262
 
 
1263
 
            gtk_widget_set_size_request (GTK_WIDGET (panel), w, h);
1264
 
 
1265
 
            panel_set_position (panel, priv->screen_position,
1266
 
                                priv->xoffset, priv->yoffset);
1267
 
 
1268
 
            gtk_widget_queue_resize (GTK_WIDGET (panel));
1269
 
        }
1270
 
    }
1271
 
}
1272
 
 
1273
 
void
1274
 
panel_set_transparency (Panel *panel,
1275
 
                        gint   transparency)
1276
 
{
1277
 
    PanelPrivate *priv;
1278
 
 
1279
 
    priv = panel->priv;
1280
 
 
1281
 
    if (transparency != priv->transparency)
1282
 
    {
1283
 
        DBG ("Transparency: %d", transparency);
1284
 
 
1285
 
        priv->transparency = transparency;
1286
 
        priv->opacity      = 0;
1287
 
 
1288
 
        _set_transparent (panel, TRUE);
1289
 
    }
1290
 
}
1291
 
 
1292
 
void
1293
 
panel_set_activetrans (Panel    *panel,
1294
 
                       gboolean  activetrans)
1295
 
{
1296
 
    PanelPrivate *priv = panel->priv;
1297
 
 
1298
 
    if (activetrans != priv->activetrans)
1299
 
    {
1300
 
        priv->activetrans = activetrans;
1301
 
 
1302
 
        _set_transparent (panel, TRUE);
1303
 
    }
1304
 
}
1305
 
 
1306
 
/* properties */
1307
 
 
1308
 
gint
1309
 
panel_get_size (Panel *panel)
1310
 
{
1311
 
    PanelPrivate *priv;
1312
 
 
1313
 
    g_return_val_if_fail (PANEL_IS_PANEL (panel), DEFAULT_SIZE);
1314
 
 
1315
 
    priv = panel->priv;
1316
 
 
1317
 
    return priv->size;
1318
 
}
1319
 
 
1320
 
void
1321
 
panel_set_size (Panel *panel,
1322
 
                gint   size)
1323
 
{
1324
 
    PanelPrivate *priv;
1325
 
 
1326
 
    g_return_if_fail (PANEL_IS_PANEL (panel));
1327
 
 
1328
 
    priv = panel->priv;
1329
 
 
1330
 
    if (xfce_screen_position_is_horizontal (priv->screen_position))
1331
 
    {
1332
 
        gtk_widget_set_size_request (priv->itembar, -1, size);
1333
 
    }
1334
 
    else
1335
 
    {
1336
 
        gtk_widget_set_size_request (priv->itembar, size, -1);
1337
 
    }
1338
 
 
1339
 
    if (size != priv->size)
1340
 
    {
1341
 
        priv->size = size;
1342
 
 
1343
 
        gtk_container_foreach (GTK_CONTAINER (priv->itembar),
1344
 
                               (GtkCallback)xfce_panel_item_set_size,
1345
 
                               GINT_TO_POINTER (size));
1346
 
    }
1347
 
}
1348
 
 
1349
 
gint
1350
 
panel_get_monitor (Panel *panel)
1351
 
{
1352
 
    PanelPrivate *priv;
1353
 
 
1354
 
    g_return_val_if_fail (PANEL_IS_PANEL (panel), DEFAULT_MONITOR);
1355
 
 
1356
 
    priv = panel->priv;
1357
 
 
1358
 
    return priv->monitor;
1359
 
}
1360
 
 
1361
 
void
1362
 
panel_set_monitor (Panel *panel,
1363
 
                   gint   monitor)
1364
 
{
1365
 
    PanelPrivate       *priv;
1366
 
    XfceMonitor        *xmon;
1367
 
    XfcePanelWidthType  width;
1368
 
 
1369
 
    g_return_if_fail (PANEL_IS_PANEL (panel));
1370
 
 
1371
 
    priv = panel->priv;
1372
 
 
1373
 
    if (monitor != priv->monitor)
1374
 
    {
1375
 
        /* TODO: check range */
1376
 
        priv->monitor = monitor;
1377
 
 
1378
 
        xmon = panel_app_get_monitor (monitor);
1379
 
 
1380
 
        if (xmon->screen != gtk_widget_get_screen (GTK_WIDGET (panel)))
1381
 
        {
1382
 
            gtk_widget_hide (GTK_WIDGET (panel));
1383
 
            gtk_window_set_screen (GTK_WINDOW (panel), xmon->screen);
1384
 
            gtk_widget_show (GTK_WIDGET (panel));
1385
 
        }
1386
 
 
1387
 
        /* new size constraints */
1388
 
        if ((width = priv->full_width) != XFCE_PANEL_NORMAL_WIDTH)
1389
 
        {
1390
 
            priv->full_width = XFCE_PANEL_NORMAL_WIDTH;
1391
 
            panel_set_full_width (panel, width);
1392
 
        }
1393
 
        else
1394
 
        {
1395
 
            gtk_widget_queue_resize (GTK_WIDGET (panel));
1396
 
        }
1397
 
    }
1398
 
}
1399
 
 
1400
 
XfceScreenPosition
1401
 
panel_get_screen_position (Panel *panel)
1402
 
{
1403
 
    PanelPrivate *priv;
1404
 
 
1405
 
    g_return_val_if_fail (PANEL_IS_PANEL (panel), DEFAULT_SCREEN_POSITION);
1406
 
 
1407
 
    priv = panel->priv;
1408
 
 
1409
 
    return priv->screen_position;
1410
 
}
1411
 
 
1412
 
void
1413
 
panel_set_screen_position (Panel              *panel,
1414
 
                           XfceScreenPosition  position)
1415
 
{
1416
 
    PanelPrivate       *priv;
1417
 
    GtkOrientation      orientation;
1418
 
    XfcePanelWidthType  full_width;
1419
 
 
1420
 
    g_return_if_fail (PANEL_IS_PANEL (panel));
1421
 
 
1422
 
    priv = panel->priv;
1423
 
 
1424
 
    if (position != priv->screen_position)
1425
 
    {
1426
 
        full_width = priv->full_width;
1427
 
 
1428
 
        /* use edit_mode property to test if we are changing position */
1429
 
        priv->edit_mode = TRUE;
1430
 
 
1431
 
        xfce_panel_window_set_move_function (XFCE_PANEL_WINDOW (panel),
1432
 
                                             NULL, NULL);
1433
 
 
1434
 
        xfce_panel_window_set_resize_function (XFCE_PANEL_WINDOW (panel),
1435
 
                                               NULL, NULL);
1436
 
 
1437
 
        if (position == XFCE_SCREEN_POSITION_NONE)
1438
 
            position = XFCE_SCREEN_POSITION_FLOATING_H;
1439
 
 
1440
 
        orientation = xfce_screen_position_get_orientation (position);
1441
 
 
1442
 
        if (xfce_screen_position_get_orientation (priv->screen_position) !=
1443
 
            orientation)
1444
 
        {
1445
 
            if (full_width > XFCE_PANEL_NORMAL_WIDTH)
1446
 
                panel_set_full_width (panel, XFCE_PANEL_NORMAL_WIDTH);
1447
 
 
1448
 
            xfce_panel_window_set_orientation (XFCE_PANEL_WINDOW (panel),
1449
 
                                               orientation);
1450
 
 
1451
 
            xfce_itembar_set_orientation (XFCE_ITEMBAR (priv->itembar),
1452
 
                                          orientation);
1453
 
        }
1454
 
 
1455
 
        gtk_container_foreach (GTK_CONTAINER (priv->itembar),
1456
 
                (GtkCallback)xfce_panel_item_set_screen_position,
1457
 
                GINT_TO_POINTER (position));
1458
 
 
1459
 
        if (xfce_screen_position_is_floating (position))
1460
 
        {
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);
1465
 
 
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);
1469
 
 
1470
 
            priv->xoffset = priv->yoffset = -1;
1471
 
        }
1472
 
        else
1473
 
        {
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;
1478
 
        }
1479
 
 
1480
 
        xfce_panel_window_set_move_function (XFCE_PANEL_WINDOW (panel),
1481
 
                (XfcePanelWindowMoveFunc)panel_move_function, panel);
1482
 
 
1483
 
        xfce_panel_window_set_resize_function (XFCE_PANEL_WINDOW (panel),
1484
 
                (XfcePanelWindowResizeFunc)panel_resize_function, panel);
1485
 
 
1486
 
        priv->screen_position = position;
1487
 
        panel_set_position (panel, position, priv->xoffset, priv->yoffset);
1488
 
 
1489
 
        if (full_width > XFCE_PANEL_NORMAL_WIDTH)
1490
 
        {
1491
 
            panel_set_full_width (panel, full_width);
1492
 
        }
1493
 
 
1494
 
        /* update itembar size request */
1495
 
        panel_set_size (panel, priv->size);
1496
 
 
1497
 
        gtk_widget_queue_resize (GTK_WIDGET (panel));
1498
 
 
1499
 
        g_idle_add((GSourceFunc)unblock_struts, panel);
1500
 
    }
1501
 
}
1502
 
 
1503
 
gint
1504
 
panel_get_xoffset (Panel *panel)
1505
 
{
1506
 
    PanelPrivate *priv;
1507
 
 
1508
 
    g_return_val_if_fail (PANEL_IS_PANEL (panel), DEFAULT_XOFFSET);
1509
 
 
1510
 
    priv = panel->priv;
1511
 
 
1512
 
    return priv->xoffset;
1513
 
}
1514
 
 
1515
 
void
1516
 
panel_set_xoffset (Panel *panel,
1517
 
                   gint   xoffset)
1518
 
{
1519
 
    PanelPrivate *priv;
1520
 
 
1521
 
    g_return_if_fail (PANEL_IS_PANEL (panel));
1522
 
 
1523
 
    priv = panel->priv;
1524
 
 
1525
 
    if (xoffset != priv->xoffset)
1526
 
    {
1527
 
        priv->xoffset = xoffset;
1528
 
        panel_set_position (panel, priv->screen_position,
1529
 
                            xoffset, priv->yoffset);
1530
 
    }
1531
 
}
1532
 
 
1533
 
gint
1534
 
panel_get_yoffset (Panel *panel)
1535
 
{
1536
 
    PanelPrivate *priv;
1537
 
 
1538
 
    g_return_val_if_fail (PANEL_IS_PANEL (panel), DEFAULT_YOFFSET);
1539
 
 
1540
 
    priv = panel->priv;
1541
 
 
1542
 
    return priv->yoffset;
1543
 
}
1544
 
 
1545
 
void
1546
 
panel_set_yoffset (Panel *panel,
1547
 
                   gint   yoffset)
1548
 
{
1549
 
    PanelPrivate *priv;
1550
 
 
1551
 
    g_return_if_fail (PANEL_IS_PANEL (panel));
1552
 
 
1553
 
    priv = panel->priv;
1554
 
 
1555
 
    if (yoffset != priv->yoffset)
1556
 
    {
1557
 
        priv->yoffset = yoffset;
1558
 
        panel_set_position (panel, priv->screen_position,
1559
 
                            priv->xoffset, yoffset);
1560
 
    }
1561
 
}
1562