]> Dogcows Code - chaz/tint2/blob - src/freespace/freespace.c
freespace.patch
[chaz/tint2] / src / freespace / freespace.c
1 /**************************************************************************
2 *
3 * Tint2 : freespace
4 *
5 * Copyright (C) 2011 Mishael A Sibiryakov (death@junki.org)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * 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, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 **************************************************************************/
19
20
21 #include <string.h>
22 #include <stdio.h>
23 #include <cairo.h>
24 #include <cairo-xlib.h>
25 #include <pango/pangocairo.h>
26 #include <stdlib.h>
27
28 #include "window.h"
29 #include "server.h"
30 #include "panel.h"
31 #include "freespace.h"
32 #include "common.h"
33
34 typedef enum {
35 COUNT_WIDTH,
36 COUNT_HEIGHT
37 } SpaceType ;
38
39 void init_freespace_panel(void *p)
40 {
41 Panel *panel =(Panel*)p;
42 FreeSpace *fsp= &panel->freespace;
43
44 if (fsp->area.bg == 0)
45 fsp->area.bg = &g_array_index(backgrounds, Background, 0);
46 fsp->area.parent = p;
47 fsp->area.panel = p;
48 fsp->area.size_mode = SIZE_BY_CONTENT;
49 fsp->area.resize = 1;
50 fsp->area.on_screen = 1;
51 fsp->area._resize = resize_freespace;
52 }
53
54 int freespace_get_max_size(Panel *p, SpaceType t) {
55
56 GSList *walk;
57 Area *a;
58 int sz = 0;
59
60 // Get space used by every element except the freespace
61 for (walk = p->area.list; walk; walk = g_slist_next(walk)) {
62 a = (Area *)walk->data;
63
64 // Skip self
65 if (a->_resize == resize_freespace)
66 continue;
67
68 if (t == COUNT_WIDTH)
69 sz += a->width + (a->bg->border.width * 2) + p->area.paddingx;
70
71 if (t == COUNT_HEIGHT)
72 sz += a->height + (a->bg->border.width * 2) + p->area.paddingy;
73 }
74
75 if (t == COUNT_WIDTH)
76 sz = p->area.width - sz - (p->area.bg->border.width * 2) - p->area.paddingxlr;
77
78 if (t == COUNT_HEIGHT)
79 sz = p->area.height - sz - (p->area.bg->border.width * 2) - p->area.paddingxlr; // Not sure about paddingxlr
80
81 return sz;
82 }
83
84 int resize_freespace(void *obj) {
85
86 FreeSpace *fsp= (FreeSpace *)obj;
87 Panel *panel = (Panel *)fsp->area.panel;
88
89 fsp->area.redraw = 1;
90
91 if (panel_horizontal)
92 fsp->area.width = freespace_get_max_size(panel, COUNT_WIDTH);
93 else
94 fsp->area.height= freespace_get_max_size(panel, COUNT_HEIGHT);
95
96 // Always resize
97 fsp->area.resize = 1;
98
99 return 1;
100 }
This page took 0.031926 seconds and 4 git commands to generate.