-
Notifications
You must be signed in to change notification settings - Fork 0
/
panel.c
1582 lines (1419 loc) · 36.8 KB
/
panel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
///
/// @file panel.c @brief panel functions
///
/// Copyright (c) 2009 - 2011, 2021 by Lutz Sammer. All Rights Reserved.
///
/// Contributor(s):
///
/// License: AGPLv3
///
/// This program is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Affero General Public License as
/// published by the Free Software Foundation, either version 3 of the
/// License.
///
/// This program is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU Affero General Public License for more details.
///
/// $Id$
//////////////////////////////////////////////////////////////////////////////
///
/// @defgroup panel The panel module.
///
/// This module handles panels. An unlimited number of panels are
/// supported. Other names for panels or parts of it are slit, toolbar or
/// dock. Panels can be placed everywhere, can also be abused as desktop
/// buttons or desktop widget.
///
/// A panel can contain buttons, task-list, pager, docked applications,
/// systray or clock.
///
/// Alternatives:
/// - lxde-base/lxpanel
/// @n Lightweight X11 desktop panel
/// @n http:https://lxde.sf.net
/// - x11-misc/fbpanel
/// @n light-weight X11 desktop panel
/// @n http:https://fbpanel.sourceforge.net
///< @{
#include <xcb/xcb.h>
#include "uwm.h"
#ifdef USE_PANEL // {
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <xcb/xcb_atom.h>
#include <xcb/xcb_icccm.h>
#include "queue.h"
#include "core-array/core-array.h"
#include "core-rc/core-rc.h"
#include "draw.h"
#include "tooltip.h"
#include "screen.h"
#include "pointer.h"
#include "image.h"
#include "client.h"
#include "hints.h"
#include "icon.h"
#include "menu.h"
#include "panel.h"
#include "plugin/button.h"
#include "plugin/clock.h"
#include "plugin/netload.h"
#include "plugin/pager.h"
#include "plugin/swallow.h"
#include "plugin/systray.h"
#include "plugin/task.h"
// ------------------------------------------------------------------------ //
/// list of all panels
struct _panel_head_ Panels = SLIST_HEAD_INITIALIZER(Panels);
static uint32_t PanelOpacity; ///< panel window transparency
// ------------------------------------------------------------------------ //
/**
** Get the panel plugin under the given coordinates.
**
** @param panel prove all plugins of this panel
** @param x x-coordinate (panel relative)
** @param y y-coordinate (panel relative)
**
** @returns panel plugin which handles the x, y.
*/
static Plugin *PanelGetPluginByXY(const Panel * panel, int x, int y)
{
Plugin *plugin;
int xoffset;
int yoffset;
xoffset = panel->Border;
yoffset = panel->Border;
STAILQ_FOREACH(plugin, &panel->Plugins, Next) {
int width;
int height;
if (!(width = plugin->Width) || !(height = plugin->Height)) {
continue;
}
if (x >= xoffset && x - xoffset < width && y >= yoffset
&& y - yoffset < height) {
return plugin;
}
if (panel->Layout == PANEL_LAYOUT_HORIZONTAL) {
xoffset += width;
} else {
yoffset += height;
}
}
return NULL;
}
// ------------------------------------------------------------------------ //
// Draw
/**
** Clear panel plugin background with given color.
**
** Generic function for plugins to clear its background.
**
** @param plugin common data of plugin to be cleared
** @param pixel x11 pixel of background color
*/
void PanelClearPluginBackgroundWithColor(const Plugin * plugin,
const uint32_t * pixel)
{
xcb_rectangle_t rectangle;
xcb_change_gc(Connection, RootGC, XCB_GC_FOREGROUND, pixel);
rectangle.x = 0;
rectangle.y = 0;
rectangle.width = plugin->Width;
rectangle.height = plugin->Height;
xcb_poly_fill_rectangle(Connection, plugin->Pixmap, RootGC, 1, &rectangle);
}
/**
** Clear panel plugin background.
**
** Generic function for plugins to clear its background with default color.
**
** @param plugin common data of plugin to be cleared
*/
void PanelClearPluginBackground(const Plugin * plugin)
{
PanelClearPluginBackgroundWithColor(plugin, &Colors.PanelBG.Pixel);
}
/**
** Update plugin on a panel.
**
** @param panel panel which owns the plugin (window)
** @param plugin update content of this plugin on screen
*/
void PanelUpdatePlugin(const Panel * panel, const Plugin * plugin)
{
if (plugin->Pixmap && KeepLooping) {
xcb_copy_area(Connection, plugin->Pixmap, panel->Window, RootGC, 0, 0,
plugin->X, plugin->Y, plugin->Width, plugin->Height);
}
}
/**
** Draw a panel.
**
** @param panel panel which plugins are drawn
**
** @todo FIXME: panel hidden flickers!
*/
static void PanelDraw(const Panel * panel)
{
const Plugin *plugin;
int i;
// draw al plugins
STAILQ_FOREACH(plugin, &panel->Plugins, Next) {
PanelUpdatePlugin(panel, plugin);
}
// draw border around panel
for (i = 0; i < panel->Border; i++) {
xcb_point_t points[3];
xcb_change_gc(Connection, RootGC, XCB_GC_FOREGROUND,
&Colors.PanelUp.Pixel);
// TOP + LEFT
points[0].x = i;
points[0].y = panel->Height - i - 1;
points[1].x = i;
points[1].y = i;
points[2].x = panel->Width - i - 1;
points[2].y = i;
xcb_poly_line(Connection, XCB_COORD_MODE_ORIGIN, panel->Window, RootGC,
3, points);
// BOTTOM + RIGHT
xcb_change_gc(Connection, RootGC, XCB_GC_FOREGROUND,
&Colors.PanelDown.Pixel);
points[0].x = panel->Width - i - 1;
points[0].y = i + 1;
points[1].x = panel->Width - i - 1;
points[1].y = panel->Height - i - 1;
points[2].x = i + 1;
points[2].y = panel->Height - i - 1;
xcb_poly_line(Connection, XCB_COORD_MODE_ORIGIN, panel->Window, RootGC,
3, points);
}
}
/**
** Draw all panels.
*/
void PanelsDraw(void)
{
if (KeepLooping) { // not shuting down
const Panel *panel;
SLIST_FOREACH(panel, &Panels, Next) {
// FIXME: should hidden panels be drawn?
PanelDraw(panel);
}
}
}
/**
** Hide a panel (for autohide).
**
** @param panel panel to hide
**
** @todo should be swallows and docked apps be unmapped?
*/
static void PanelHide(Panel * panel)
{
int x;
int y;
uint32_t values[2];
panel->Hidden = 1;
x = panel->X;
y = panel->Y;
// FIXME: use gravity to hide panel
switch (panel->Gravity) {
case GRAVITY_STATIC:
// FIXME: should also hide, need to resize window size
Debug(2, "FIXME: should hide static panel\n");
break;
case GRAVITY_NORTH_WEST:
if (panel->Layout == PANEL_LAYOUT_HORIZONTAL) {
x = panel->HiddenSize - panel->Width;
} else {
y = panel->HiddenSize - panel->Height;
}
break;
case GRAVITY_NORTH:
y = panel->HiddenSize - panel->Height;
break;
case GRAVITY_NORTH_EAST:
if (panel->Layout == PANEL_LAYOUT_HORIZONTAL) {
x = XcbScreen->width_in_pixels - panel->HiddenSize;
} else {
y = panel->HiddenSize - panel->Height;
}
break;
case GRAVITY_WEST:
x = panel->HiddenSize - panel->Width;
break;
case GRAVITY_CENTER:
break;
case GRAVITY_EAST:
x = XcbScreen->width_in_pixels - panel->HiddenSize;
break;
case GRAVITY_SOUTH_WEST:
if (panel->Layout == PANEL_LAYOUT_HORIZONTAL) {
x = panel->HiddenSize - panel->Width;
} else {
y = XcbScreen->height_in_pixels - panel->HiddenSize;
}
break;
case GRAVITY_SOUTH:
y = XcbScreen->height_in_pixels - panel->HiddenSize;
break;
case GRAVITY_SOUTH_EAST:
if (panel->Layout == PANEL_LAYOUT_HORIZONTAL) {
x = XcbScreen->width_in_pixels - panel->HiddenSize;
} else {
y = XcbScreen->height_in_pixels - panel->HiddenSize;
}
break;
}
#if 0
// determine where to move the panel
if (panel->Layout == PANEL_LAYOUT_HORIZONTAL) {
x = panel->X;
// move to top or bottom side?
if (panel->Y >= (signed)(XcbScreen->height_in_pixels / 2)) {
y = XcbScreen->height_in_pixels - panel->HiddenSize;
} else {
y = panel->HiddenSize - panel->Height;
}
} else {
y = panel->Y;
// move to left or right side?
if (panel->X >= (signed)(XcbScreen->width_in_pixels / 2)) {
x = XcbScreen->width_in_pixels - panel->HiddenSize;
} else {
x = panel->HiddenSize - panel->Width;
}
}
#endif
// move it.
values[0] = x;
values[1] = y;
xcb_configure_window(Connection, panel->Window,
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, values);
}
/**
** Display a panel (for autohide).
**
** @param panel panel to show
*/
static void PanelShow(Panel * panel)
{
if (panel->Hidden) {
uint32_t values[2];
panel->Hidden = 0;
values[0] = panel->X;
values[1] = panel->Y;
xcb_configure_window(Connection, panel->Window,
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, values);
// FIXME: why query pointer? (can generate enter window events?)
// PointerQuery();
}
}
/**
** Hide/show/toggle panel (for commands).
**
** @param panel_nr panel number (should be in configuration order!)
** @param toggle 0: hide, 1: show, -1: toggle.
*/
void PanelToggle(int panel_nr, int toggle)
{
Panel *panel;
SLIST_FOREACH(panel, &Panels, Next) {
if (panel_nr-- <= 0) {
break;
}
}
if (!panel) {
Warning("wrong panel number configured\n");
return;
}
Debug(4, "switch panel %p %+d%+d %d\n", panel, panel->X, panel->Y, toggle);
switch (toggle) {
case 0:
if (!panel->Hidden) {
PanelHide(panel);
}
break;
case 1:
if (panel->Hidden) {
PanelShow(panel);
}
break;
case -1:
if (panel->Hidden) {
PanelShow(panel);
} else {
PanelHide(panel);
}
break;
}
}
/**
** Execute pointer button command.
**
** Generic function to execute pointer button clicks.
**
** @param plugin common plugin data
** @param button pointer button commands to be executed
** @param mask pointer button number
*/
void PanelExecuteButton(const Plugin * plugin, MenuButton * button, int mask)
{
const Screen *screen;
int x;
int y;
//
// Calculate menu hot-spot
//
screen = ScreenGetByXY(plugin->ScreenX, plugin->ScreenY);
if (plugin->Panel->Layout == PANEL_LAYOUT_HORIZONTAL) {
x = plugin->ScreenX;
if (plugin->ScreenY + (int)plugin->Height / 2 <
screen->Y + (int)screen->Height / 2) {
y = plugin->ScreenY + plugin->Height;
} else {
y = -plugin->ScreenY;
}
} else {
y = plugin->ScreenY;
if (plugin->ScreenX + (int)plugin->Width / 2 <
screen->X + (int)screen->Width / 2) {
x = plugin->ScreenX + plugin->Width;
} else {
x = -plugin->ScreenX;
}
}
Debug(3, "menu at %d,%d\n", x, y);
MenuButtonExecute(button, mask, x, y, NULL);
}
// ------------------------------------------------------------------------ //
// Events
// ------------------------------------------------------------------------ //
/**
** Find panel by window.
**
** @param window X11 window id
**
** @returns panel pointer if found, NULL otherwise.
*/
static Panel *PanelByWindow(xcb_window_t window)
{
Panel *panel;
SLIST_FOREACH(panel, &Panels, Next) {
if (window == panel->Window) {
return panel;
}
}
return NULL;
}
/**
** Get the panel under the given coordinates.
**
** @param x x-coordinate (panel relative)
** @param y y-coordinate (panel relative)
**
** @returns panel which handles the x, y.
*/
static Panel *PanelByXY(int x, int y)
{
Panel *panel;
SLIST_FOREACH(panel, &Panels, Next) {
if (!panel->Hidden && x >= panel->X && x < panel->X + panel->Width
&& y >= panel->Y && y < panel->Y + panel->Height) {
return panel;
}
}
return NULL;
}
/**
** Handle a button press on a panel.
**
** @param event X11 button press event
**
** @returns true if event is handled by any panel.
*/
int PanelHandleButtonPress(const xcb_button_press_event_t * event)
{
Panel *panel;
if ((panel = PanelByWindow(event->event))) {
Plugin *plugin;
plugin = PanelGetPluginByXY(panel, event->event_x, event->event_y);
if (plugin && plugin->HandleButtonPress) {
plugin->HandleButtonPress(plugin, event->event_x - plugin->X,
event->event_y - plugin->Y, event->detail);
}
return 1;
}
return 0;
}
/**
** Handle a button release on a panel.
**
** @param event X11 button release event
**
** @returns true if event is handled by any panel.
*/
int PanelHandleButtonRelease(const xcb_button_release_event_t * event)
{
Panel *panel;
if ((panel = PanelByWindow(event->event))) {
Plugin *plugin;
// first inform any plugins that have a grab
STAILQ_FOREACH(plugin, &panel->Plugins, Next) {
if (plugin->Grabbed) {
plugin->HandleButtonRelease(plugin, event->event_x - plugin->X,
event->event_y - plugin->Y, event->detail);
xcb_ungrab_pointer(Connection, XCB_CURRENT_TIME);
plugin->Grabbed = 0;
return 1;
}
}
// normal release: find plugin and send it
plugin = PanelGetPluginByXY(panel, event->event_x, event->event_y);
if (plugin && plugin->HandleButtonRelease) {
plugin->HandleButtonRelease(plugin, event->event_x - plugin->X,
event->event_y - plugin->Y, event->detail);
}
return 1;
}
return 0;
}
/**
** Callback used by tooltip handler to show the tooltip.
**
** @param x current mouse x-coordinate
** @param y current mouse y-coordinate
*/
static void PanelTooltip(int x, int y)
{
const Panel *panel;
const Plugin *plugin;
if ((panel = PanelByXY(x, y))
&& (plugin = PanelGetPluginByXY(panel, x - panel->X, y - panel->Y))) {
plugin->Tooltip(plugin, x, y);
}
}
/**
** Handle a motion notify event over a panel.
**
** @param event X11 motion notify event
**
** @returns true if event is handled by any panel, false otherwise.
*/
int PanelHandleMotionNotify(const xcb_motion_notify_event_t * event)
{
Panel *panel;
// remember last motion for tooltip
TooltipRegister(event->root_x, event->root_y, PanelTooltip);
if ((panel = PanelByWindow(event->event))) {
Plugin *plugin;
plugin = PanelGetPluginByXY(panel, event->event_x, event->event_y);
if (plugin && plugin->HandleMotionNotify) {
plugin->HandleMotionNotify(plugin, event->event_x - plugin->X,
event->event_y - plugin->Y, event->detail);
}
return 1;
}
return 0;
}
/**
** Handle a panel enter notify (for autohide).
**
** @param event X11 enter notify event
**
** @returns true if event is handled by any panel, false otherwise.
*/
int PanelHandleEnterNotify(const xcb_enter_notify_event_t * event)
{
Panel *panel;
if ((panel = PanelByWindow(event->event))) {
PanelShow(panel);
return 1;
}
/*
// FIXME: moved from global event handler
if (SwallowHandleEnterNotify(event)) {
return 1;
}
*/
return 0;
}
/**
** Handle a panel expose event.
**
** @param event X11 expose event
**
** @returns true if event is handled by any panel, false otherwise.
*/
int PanelHandleExpose(const xcb_expose_event_t * event)
{
Panel *panel;
if ((panel = PanelByWindow(event->window))) {
PanelDraw(panel);
return 1;
}
return 0;
}
/**
** Handle timeout for the panel (needed for autohide and tooltip).
**
** @param tick current tick in ms
** @param x current mouse x-coordinate
** @param y current mouse y-coordinate
**
** @todo write more general tooltip handling
** @todo delay of autohide?
*/
void PanelTimeout(uint32_t tick, int x, int y)
{
Panel *panel;
Plugin *plugin;
SLIST_FOREACH(panel, &Panels, Next) {
// FIXME: delay hiding?
if (panel->AutoHide && !panel->Hidden && !MenuShown) {
// mouse outside of the panel
if (x < panel->X || x >= panel->X + panel->Width || y < panel->Y
|| y >= panel->Y + panel->Height) {
PanelHide(panel);
}
}
// call timeout of each plugin
STAILQ_FOREACH(plugin, &panel->Plugins, Next) {
plugin->Timeout(plugin, tick, x, y);
}
}
}
// ------------------------------------------------------------------------ //
/**
** Compute the total width of a panel.
**
** @param panel panel to get its minimum width
**
** @returns the total panel width of all fixed size plugins
*/
static int PanelComputeTotalWidth(const Panel * panel)
{
const Plugin *plugin;
int result;
result = 2 * panel->Border;
STAILQ_FOREACH(plugin, &panel->Plugins, Next) {
if (plugin->Width > 0) {
result += plugin->Width;
}
}
return result;
}
/**
** Compute the total height of a panel.
**
** @param panel panel to get its minimum height
**
** @returns the total panel height of all fixed size plugins
*/
static int PanelComputeTotalHeight(const Panel * panel)
{
const Plugin *plugin;
int result;
result = 2 * panel->Border;
STAILQ_FOREACH(plugin, &panel->Plugins, Next) {
if (plugin->Height > 0) {
result += plugin->Height;
}
}
return result;
}
/**
** Check if the panel fills the screen horizontally.
**
** @param panel panel to check it has fixed width
**
** @returns true if one plugin has variable size.
*/
static int PanelCheckHorizontalFill(const Panel * panel)
{
const Plugin *plugin;
STAILQ_FOREACH(plugin, &panel->Plugins, Next) {
if (!plugin->Width) {
return 1;
}
}
return 0;
}
/**
** Check if the panel fills the screen vertically.
**
** @param panel panel to check it has fixed height
**
** @returns true if one plugin has variable size.
*/
static int PanelCheckVerticalFill(const Panel * panel)
{
const Plugin *plugin;
STAILQ_FOREACH(plugin, &panel->Plugins, Next) {
if (!plugin->Height) {
return 1;
}
}
return 0;
}
/**
** Compute the maximal plugin width.
**
** @param panel panel to find its maximal width
**
** @returns panel maximal width.
*/
static int PanelComputeMaxWidth(const Panel * panel)
{
const Plugin *plugin;
int result;
result = 0;
STAILQ_FOREACH(plugin, &panel->Plugins, Next) {
int temp;
if ((temp = plugin->Width) > 0) {
temp += 2 * panel->Border;
if (temp > result) {
result = temp;
}
}
}
return result;
}
/**
** Compute the maximal plugin height.
**
** @param panel panel to find its maximal height
**
** @returns panel maximal height.
*/
static int PanelComputeMaxHeight(const Panel * panel)
{
const Plugin *plugin;
int result;
result = 0;
STAILQ_FOREACH(plugin, &panel->Plugins, Next) {
int temp;
if ((temp = plugin->Height) > 0) {
temp += 2 * panel->Border;
if (temp > result) {
result = temp;
}
}
}
return result;
}
/**
** Compute the size and position of a panel.
**
** @param panel panel update widths and heights
**
** panel->Height and panel->Width are set with RequestedWidth
*/
static void PanelComputeSize(Panel * panel)
{
Plugin *plugin;
// determine the first dimension
if (panel->Layout == PANEL_LAYOUT_HORIZONTAL) {
if (!panel->Height) {
panel->Height = PanelComputeMaxHeight(panel);
if (!panel->Height) {
panel->Height = PANEL_DEFAULT_HEIGHT;
}
}
} else {
if (!panel->Width) {
panel->Width = PanelComputeMaxWidth(panel);
if (!panel->Width) {
panel->Width = PANEL_DEFAULT_WIDTH;
}
}
}
// now at least one size is known. handle the plugins
STAILQ_FOREACH(plugin, &panel->Plugins, Next) {
if (plugin->SetSize) {
if (panel->Layout == PANEL_LAYOUT_HORIZONTAL) {
plugin->SetSize(plugin, 0, panel->Height - 2 * panel->Border);
} else {
plugin->SetSize(plugin, panel->Width - 2 * panel->Border, 0);
}
}
}
// determine the missing dimension
if (panel->Layout == PANEL_LAYOUT_HORIZONTAL) {
if (!panel->Width) {
if (PanelCheckHorizontalFill(panel)) {
Debug(2, "FIXME: gravity error\n");
panel->Width = XcbScreen->width_in_pixels;
} else {
panel->Width = PanelComputeTotalWidth(panel);
}
if (!panel->Width) {
panel->Width = PANEL_DEFAULT_WIDTH;
}
}
} else {
if (!panel->Height) {
if (PanelCheckVerticalFill(panel)) {
Debug(2, "FIXME: gravity error\n");
panel->Height = XcbScreen->height_in_pixels;
} else {
panel->Height = PanelComputeTotalHeight(panel);
}
if (!panel->Height) {
panel->Height = PANEL_DEFAULT_HEIGHT;
}
}
}
// compute the panel location
panel->X = panel->RequestedX;
panel->Y = panel->RequestedY;
switch (panel->Gravity) {
case GRAVITY_STATIC:
if (panel->X < 0) {
panel->X += XcbScreen->width_in_pixels - panel->Width + 1;
}
if (panel->Y < 0) {
panel->Y += XcbScreen->height_in_pixels - panel->Height + 1;
}
break;
case GRAVITY_NORTH_WEST:
// panel->X += 0;
// panel->Y += 0;
break;
case GRAVITY_NORTH:
panel->X += XcbScreen->width_in_pixels / 2 - panel->Width / 2;
// panel->Y += 0;
break;
case GRAVITY_NORTH_EAST:
panel->X += XcbScreen->width_in_pixels - panel->Width;
// panel->Y += 0;
break;
case GRAVITY_WEST:
// panel->X += 0;
panel->Y += XcbScreen->height_in_pixels / 2 - panel->Height / 2;
break;
case GRAVITY_CENTER:
panel->X += XcbScreen->width_in_pixels / 2 - panel->Width / 2;
panel->Y += XcbScreen->height_in_pixels / 2 - panel->Height / 2;
break;
case GRAVITY_EAST:
panel->X += XcbScreen->width_in_pixels - panel->Width;
panel->Y += XcbScreen->height_in_pixels / 2 - panel->Height / 2;
break;
case GRAVITY_SOUTH_WEST:
// panel->X += 0;
panel->Y += XcbScreen->height_in_pixels - panel->Height;
break;
case GRAVITY_SOUTH:
panel->X += XcbScreen->width_in_pixels / 2 - panel->Width / 2;
panel->Y += XcbScreen->height_in_pixels - panel->Height;
break;
case GRAVITY_SOUTH_EAST:
panel->X += XcbScreen->width_in_pixels - panel->Width;
panel->Y += XcbScreen->height_in_pixels - panel->Height;
break;
}
}
/**
** Layout panel plugins on a panel.
**
** @param panel panel to be layouted
** @param[out] variable_size size of a variable sized plugin
** @param[out] variable_remainder remainding pixels for variable
*/
static void PanelPrepareLayout(Panel * panel, int *variable_size,
int *variable_remainder)
{
Plugin *plugin;
int variable_count;
int width;
int height;
int temp;
panel->Width = panel->RequestedWidth;
panel->Height = panel->RequestedHeight;
// requested size (can be 0), is default for size
STAILQ_FOREACH(plugin, &panel->Plugins, Next) {
plugin->Width = plugin->RequestedWidth;
plugin->Height = plugin->RequestedHeight;
}
PanelComputeSize(panel);
// get the remaining size after setting fixed size plugins
// also, keep track of the number of variable size plugins
width = panel->Width - 2 * panel->Border;
height = panel->Height - 2 * panel->Border;
variable_count = 0;
STAILQ_FOREACH(plugin, &panel->Plugins, Next) {
if (panel->Layout == PANEL_LAYOUT_HORIZONTAL) {
// FIXME: not used swallow should have 0x0 size, see swallow.c
temp = plugin->Width;
if (temp > 0) {
width -= temp;
} else if (!temp) {
++variable_count;
}
} else {
temp = plugin->Height;
if (temp > 0) {
height -= temp;
} else if (!temp) {
++variable_count;
}
}
}
// distribute excess size among variable size plugins
// if there are no variable size plugins, shrink the panel
// if we are out of room, just give them a size of one
*variable_size = 1;
*variable_remainder = 0;
if (panel->Layout == PANEL_LAYOUT_HORIZONTAL) {
if (variable_count) {
if (width >= variable_count) {
*variable_size = width / variable_count;
*variable_remainder = width % variable_count;
}
} else if (width > 0) {
panel->Width -= width;
}
} else {
if (variable_count) {
if (height >= variable_count) {
*variable_size = height / variable_count;
*variable_remainder = height % variable_count;
}
} else if (height > 0) {
panel->Height -= height;
}
}
}
/**
** Resize a panel.
**
** @param panel a panel which must be resized
**
** @todo combine Init+Resize
*/
void PanelResize(Panel * panel)
{
int variable_size;