1 | /* Gnome panel: edge (snapped) widget |
---|
2 | * (C) 1999 the Free Software Foundation |
---|
3 | * |
---|
4 | * Authors: Jacob Berkman |
---|
5 | * George Lebl |
---|
6 | */ |
---|
7 | |
---|
8 | #include "config.h" |
---|
9 | #include "edge-widget.h" |
---|
10 | #include "panel_config_global.h" |
---|
11 | #include "foobar-widget.h" |
---|
12 | #include "multiscreen-stuff.h" |
---|
13 | |
---|
14 | extern GlobalConfig global_config; |
---|
15 | extern int pw_minimized_size; |
---|
16 | |
---|
17 | static void edge_pos_class_init (EdgePosClass *klass); |
---|
18 | static void edge_pos_init (EdgePos *pos); |
---|
19 | |
---|
20 | static void edge_pos_set_pos (BasePWidget *basep, |
---|
21 | int x, int y, |
---|
22 | int w, int h, |
---|
23 | gboolean force); |
---|
24 | static void edge_pos_get_pos (BasePWidget *basep, |
---|
25 | int *x, int *y, |
---|
26 | int w, int h); |
---|
27 | |
---|
28 | static void edge_pos_get_size (BasePWidget *basep, |
---|
29 | int *w, int *h); |
---|
30 | |
---|
31 | static void edge_pos_pre_convert_hook (BasePWidget *basep); |
---|
32 | |
---|
33 | static BorderPosClass *parent_class; |
---|
34 | |
---|
35 | GtkType |
---|
36 | edge_pos_get_type () |
---|
37 | { |
---|
38 | static GtkType edge_pos_type = 0; |
---|
39 | |
---|
40 | if (edge_pos_type == 0) { |
---|
41 | GtkTypeInfo edge_pos_info = { |
---|
42 | "EdgePos", |
---|
43 | sizeof (EdgePos), |
---|
44 | sizeof (EdgePosClass), |
---|
45 | (GtkClassInitFunc) edge_pos_class_init, |
---|
46 | (GtkObjectInitFunc) edge_pos_init, |
---|
47 | NULL, |
---|
48 | NULL, |
---|
49 | NULL |
---|
50 | }; |
---|
51 | |
---|
52 | edge_pos_type = gtk_type_unique (TYPE_BORDER_POS, |
---|
53 | &edge_pos_info); |
---|
54 | } |
---|
55 | |
---|
56 | return edge_pos_type; |
---|
57 | } |
---|
58 | |
---|
59 | static void |
---|
60 | edge_pos_class_init (EdgePosClass *klass) |
---|
61 | { |
---|
62 | BasePPosClass *pos_class = BASEP_POS_CLASS(klass); |
---|
63 | |
---|
64 | parent_class = gtk_type_class(TYPE_BORDER_POS); |
---|
65 | |
---|
66 | pos_class->set_pos = edge_pos_set_pos; |
---|
67 | pos_class->get_pos = edge_pos_get_pos; |
---|
68 | pos_class->get_size = edge_pos_get_size; |
---|
69 | pos_class->pre_convert_hook = edge_pos_pre_convert_hook; |
---|
70 | } |
---|
71 | |
---|
72 | static void |
---|
73 | edge_pos_init (EdgePos *pos) { } |
---|
74 | |
---|
75 | static void |
---|
76 | edge_pos_set_pos (BasePWidget *basep, |
---|
77 | int x, int y, |
---|
78 | int w, int h, |
---|
79 | gboolean force) |
---|
80 | { |
---|
81 | BorderEdge newloc; |
---|
82 | int innerx, innery; |
---|
83 | int screen_width, screen_height; |
---|
84 | |
---|
85 | if ( ! force) { |
---|
86 | int minx, miny, maxx, maxy; |
---|
87 | |
---|
88 | gdk_window_get_geometry (GTK_WIDGET (basep)->window, |
---|
89 | &minx, &miny, &maxx, &maxy, NULL); |
---|
90 | gdk_window_get_origin (GTK_WIDGET (basep)->window, |
---|
91 | &minx, &miny); |
---|
92 | |
---|
93 | newloc = BORDER_POS(basep->pos)->edge; |
---|
94 | |
---|
95 | maxx += minx; |
---|
96 | maxy += miny; |
---|
97 | |
---|
98 | if (x >= minx && |
---|
99 | x <= maxx && |
---|
100 | y >= miny && |
---|
101 | y <= maxy) |
---|
102 | return; |
---|
103 | } |
---|
104 | |
---|
105 | innerx = x - multiscreen_x (basep->screen); |
---|
106 | innery = y - multiscreen_y (basep->screen); |
---|
107 | screen_width = multiscreen_width (basep->screen); |
---|
108 | screen_height = multiscreen_height (basep->screen); |
---|
109 | |
---|
110 | if ( innerx > (screen_width / 3) && |
---|
111 | innerx < (2*screen_width / 3) && |
---|
112 | innery > (screen_height / 3) && |
---|
113 | innery < (2*screen_height / 3)) |
---|
114 | return; |
---|
115 | |
---|
116 | if (innerx * screen_height > innery * screen_width) { |
---|
117 | if (screen_height * (screen_width - innerx) > |
---|
118 | innery * screen_width) |
---|
119 | newloc = BORDER_TOP; |
---|
120 | else |
---|
121 | newloc = BORDER_RIGHT; |
---|
122 | } else { |
---|
123 | if (screen_height * (screen_width - innerx) > |
---|
124 | innery * screen_width) |
---|
125 | newloc = BORDER_LEFT; |
---|
126 | else |
---|
127 | newloc = BORDER_BOTTOM; |
---|
128 | } |
---|
129 | if (newloc != BORDER_POS (basep->pos)->edge) |
---|
130 | border_widget_change_edge (BORDER_WIDGET (basep), newloc); |
---|
131 | } |
---|
132 | |
---|
133 | static void |
---|
134 | edge_pos_get_pos (BasePWidget *basep, int *x, int *y, |
---|
135 | int w, int h) |
---|
136 | { |
---|
137 | BorderEdge edge; |
---|
138 | |
---|
139 | *x = *y = 0; |
---|
140 | |
---|
141 | edge = BORDER_POS(basep->pos)->edge; |
---|
142 | |
---|
143 | switch (edge) { |
---|
144 | case BORDER_RIGHT: |
---|
145 | basep_border_get (basep->screen, BORDER_TOP, NULL, NULL, y); |
---|
146 | *y += foobar_widget_get_height (basep->screen); |
---|
147 | *x = multiscreen_width(basep->screen) - w; |
---|
148 | |
---|
149 | break; |
---|
150 | case BORDER_LEFT: |
---|
151 | basep_border_get (basep->screen, BORDER_TOP, y, NULL, NULL); |
---|
152 | *y += foobar_widget_get_height (basep->screen); |
---|
153 | break; |
---|
154 | case BORDER_TOP: |
---|
155 | *y = foobar_widget_get_height (basep->screen); |
---|
156 | break; |
---|
157 | case BORDER_BOTTOM: |
---|
158 | *y = multiscreen_height(basep->screen) - h; |
---|
159 | break; |
---|
160 | } |
---|
161 | |
---|
162 | *x += multiscreen_x (basep->screen); |
---|
163 | *y += multiscreen_y (basep->screen); |
---|
164 | |
---|
165 | basep_border_queue_recalc (basep->screen); |
---|
166 | } |
---|
167 | |
---|
168 | static void |
---|
169 | edge_pos_get_size (BasePWidget *basep, int *w, int *h) |
---|
170 | { |
---|
171 | int a, b; |
---|
172 | |
---|
173 | BorderEdge edge = BORDER_POS(basep->pos)->edge; |
---|
174 | |
---|
175 | switch (edge) { |
---|
176 | case BORDER_RIGHT: |
---|
177 | basep_border_get (basep->screen, BORDER_TOP, NULL, NULL, &a); |
---|
178 | basep_border_get (basep->screen, BORDER_BOTTOM, NULL, NULL, &b); |
---|
179 | *h = multiscreen_height (basep->screen) - foobar_widget_get_height (basep->screen) - a - b; |
---|
180 | break; |
---|
181 | case BORDER_LEFT: |
---|
182 | basep_border_get (basep->screen, BORDER_TOP, &a, NULL, NULL); |
---|
183 | basep_border_get (basep->screen, BORDER_BOTTOM, &b, NULL, NULL); |
---|
184 | *h = multiscreen_height (basep->screen) - foobar_widget_get_height (basep->screen) - a - b; |
---|
185 | break; |
---|
186 | case BORDER_TOP: |
---|
187 | case BORDER_BOTTOM: |
---|
188 | *w = multiscreen_width (basep->screen); |
---|
189 | break; |
---|
190 | } |
---|
191 | } |
---|
192 | |
---|
193 | static void |
---|
194 | edge_pos_pre_convert_hook (BasePWidget *basep) |
---|
195 | { |
---|
196 | basep->keep_in_screen = TRUE; |
---|
197 | PANEL_WIDGET (basep->panel)->packed = FALSE; |
---|
198 | } |
---|
199 | |
---|
200 | GtkWidget * |
---|
201 | edge_widget_new (int screen, |
---|
202 | BorderEdge edge, |
---|
203 | BasePMode mode, |
---|
204 | BasePState state, |
---|
205 | BasePLevel level, |
---|
206 | gboolean avoid_on_maximize, |
---|
207 | int sz, |
---|
208 | gboolean hidebuttons_enabled, |
---|
209 | gboolean hidebutton_pixmaps_enabled, |
---|
210 | PanelBackType back_type, |
---|
211 | char *back_pixmap, |
---|
212 | gboolean fit_pixmap_bg, |
---|
213 | gboolean strech_pixmap_bg, |
---|
214 | gboolean rotate_pixmap_bg, |
---|
215 | GdkColor *back_color) |
---|
216 | { |
---|
217 | EdgeWidget *edgew = gtk_type_new (TYPE_EDGE_WIDGET); |
---|
218 | BasePWidget *basep = BASEP_WIDGET (edgew); |
---|
219 | |
---|
220 | basep->pos = gtk_type_new (TYPE_EDGE_POS); |
---|
221 | |
---|
222 | border_widget_construct (BORDER_WIDGET (basep), |
---|
223 | screen, |
---|
224 | edge, |
---|
225 | TRUE, FALSE, |
---|
226 | sz, mode, state, |
---|
227 | level, |
---|
228 | avoid_on_maximize, |
---|
229 | hidebuttons_enabled, |
---|
230 | hidebutton_pixmaps_enabled, |
---|
231 | back_type, back_pixmap, |
---|
232 | fit_pixmap_bg, strech_pixmap_bg, |
---|
233 | rotate_pixmap_bg, |
---|
234 | back_color); |
---|
235 | |
---|
236 | PANEL_WIDGET (basep->panel)->packed = FALSE; |
---|
237 | |
---|
238 | return GTK_WIDGET (edgew); |
---|
239 | } |
---|