1
// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
3
// Copyright (C) 2011-2013 Wingpanel Developers
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 by
7
// the Free Software Foundation, either version 3 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 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, see <http://www.gnu.org/licenses/>.
18
public abstract class Wingpanel.Widgets.BasePanel : Gtk.Window {
35
private const int SHADOW_SIZE = 4;
37
private int panel_height = 0;
40
private int panel_width;
41
private int panel_displacement = -40;
42
private uint animation_timer = 0;
44
private PanelShadow shadow = new PanelShadow ();
49
skip_taskbar_hint = true;
51
set_visual (get_screen ().get_rgba_visual ());
52
set_type_hint (Gdk.WindowTypeHint.DOCK);
56
// Update the panel size on screen size or monitor changes
57
screen.size_changed.connect (on_monitors_changed);
58
screen.monitors_changed.connect (on_monitors_changed);
60
destroy.connect (Gtk.main_quit);
63
protected abstract Gtk.StyleContext get_draw_style_context ();
65
public override void realize () {
70
public override bool draw (Cairo.Context cr) {
72
get_allocation (out size);
74
if (panel_height != size.height) {
75
panel_height = size.height;
76
message ("New Panel Height: %i", size.height);
77
shadow.move (panel_x, panel_y + panel_height + panel_displacement);
81
var ctx = get_draw_style_context ();
82
ctx.render_background (cr, size.x, size.y, size.width, size.height);
85
if (animation_timer == 0) {
86
panel_displacement = -panel_height;
87
animation_timer = Timeout.add (300 / panel_height, animation_callback);
90
var child = get_child ();
93
propagate_draw (child, cr);
101
private bool animation_callback () {
102
if (panel_displacement >= 0 ) {
105
panel_displacement += 1;
106
move (panel_x, panel_y + panel_displacement);
107
shadow.move (panel_x, panel_y + panel_height + panel_displacement);
112
private void on_monitors_changed () {
116
private void set_struts () {
117
if (!get_realized ())
120
// Since uchar is 8 bits in vala but the struts are 32 bits
121
// we have to allocate 4 times as much and do bit-masking
122
var struts = new ulong[Struts.N_VALUES];
124
struts[Struts.TOP] = panel_height + panel_y;
125
struts[Struts.TOP_START] = panel_x;
126
struts[Struts.TOP_END] = panel_x + panel_width;
128
var first_struts = new ulong[Struts.BOTTOM + 1];
129
for (var i = 0; i < first_struts.length; i++)
130
first_struts[i] = struts[i];
132
unowned X.Display display = Gdk.X11Display.get_xdisplay (get_display ());
133
var xid = Gdk.X11Window.get_xid (get_window ());
135
display.change_property (xid, display.intern_atom ("_NET_WM_STRUT_PARTIAL", false), X.XA_CARDINAL,
136
32, X.PropMode.Replace, (uchar[]) struts, struts.length);
137
display.change_property (xid, display.intern_atom ("_NET_WM_STRUT", false), X.XA_CARDINAL,
138
32, X.PropMode.Replace, (uchar[]) first_struts, first_struts.length);
141
private void panel_resize (bool redraw) {
142
Gdk.Rectangle monitor_dimensions;
144
screen.get_monitor_geometry (screen.get_primary_monitor(), out monitor_dimensions);
146
panel_x = monitor_dimensions.x;
147
panel_y = monitor_dimensions.y;
148
panel_width = monitor_dimensions.width;
150
move (panel_x, panel_y + panel_displacement);
151
shadow.move (panel_x, panel_y + panel_height + panel_displacement);
153
this.set_size_request (panel_width, -1);
154
shadow.set_size_request (panel_width, SHADOW_SIZE);