]>
Dogcows Code - chaz/tint2/blob - src/launcher/launcher.c
83038d095bf81eb7bc2554547940d20703c6c5d9
1 /**************************************************************************
4 * Copyright (C) 2010 (mrovi@interfete-web-club.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 **************************************************************************/
22 #include <cairo-xlib.h>
23 #include <pango/pangocairo.h>
36 int launcher_max_icon_size
;
39 void default_launcher()
42 launcher_max_icon_size
= 0;
51 void init_launcher_panel(void *p
)
53 Panel
*panel
=(Panel
*)p
;
54 Launcher
*launcher
= &panel
->launcher
;
56 launcher
->area
.parent
= p
;
57 launcher
->area
.panel
= p
;
58 launcher
->area
._draw_foreground
= draw_launcher
;
59 launcher
->area
.size_mode
= SIZE_BY_CONTENT
;
60 launcher
->area
._resize
= resize_launcher
;
61 launcher
->area
.resize
= 1;
62 launcher
->area
.redraw
= 1;
63 launcher
->area
.on_screen
= 1;
65 if (panel_horizontal
) {
66 // panel horizonal => fixed height and posy
67 launcher
->area
.posy
= panel
->area
.bg
->border
.width
+ panel
->area
.paddingy
;
68 launcher
->area
.height
= panel
->area
.height
- (2 * launcher
->area
.posy
);
71 // panel vertical => fixed width, height, posy and posx
72 launcher
->area
.posx
= panel
->area
.bg
->border
.width
+ panel
->area
.paddingxlr
;
73 launcher
->area
.width
= panel
->area
.width
- (2 * panel
->area
.bg
->border
.width
) - (2 * panel
->area
.paddingy
);
78 GSList
* path
= launcher
->list_icon_paths
;
79 GSList
* cmd
= launcher
->list_cmds
;
80 while (path
!= NULL
&& cmd
!= NULL
)
82 LauncherIcon
*launcherIcon
= malloc(sizeof(LauncherIcon
));
83 launcherIcon
->icon
= imlib_load_image(path
->data
);
84 launcherIcon
->cmd
= strdup(cmd
->data
);
85 launcher
->list_icons
= g_slist_append(launcher
->list_icons
, launcherIcon
);
86 path
= g_slist_next(path
);
87 cmd
= g_slist_next(cmd
);
93 void cleanup_launcher()
97 for (i
= 0 ; i
< nb_panel
; i
++) {
98 Panel
*panel
= &panel1
[i
];
99 Launcher
*launcher
= &panel
->launcher
;
100 free_area(&launcher
->area
);
102 for (l
= launcher
->list_icons
; l
; l
= l
->next
) {
103 LauncherIcon
*launcherIcon
= (LauncherIcon
*)l
->data
;
104 if (launcherIcon
&& launcherIcon
->icon
) {
105 imlib_context_set_image (launcherIcon
->icon
);
108 free(launcherIcon
->cmd
);
111 g_slist_free(launcher
->list_icons
);
112 for (l
= launcher
->list_icon_paths
; l
; l
= l
->next
) {
115 g_slist_free(launcher
->list_icon_paths
);
116 for (l
= launcher
->list_cmds
; l
; l
= l
->next
) {
119 g_slist_free(launcher
->list_cmds
);
121 launcher_enabled
= 0;
124 void resize_launcher(void *obj
)
126 Launcher
*launcher
= obj
;
127 Panel
*panel
= launcher
->area
.panel
;
129 int count
, icon_size
;
130 int icons_per_column
=1, icons_per_row
=1, marging
=0;
132 if (panel_horizontal
)
133 icon_size
= launcher
->area
.height
;
135 icon_size
= launcher
->area
.width
;
136 icon_size
= icon_size
- (2 * launcher
->area
.bg
->border
.width
) - (2 * launcher
->area
.paddingy
);
137 if (launcher_max_icon_size
> 0 && icon_size
> launcher_max_icon_size
)
138 icon_size
= launcher_max_icon_size
;
141 for (l
= launcher
->list_icons
; l
; l
= l
->next
) {
145 if (panel_horizontal
) {
146 if (!count
) launcher
->area
.width
= 0;
148 int height
= launcher
->area
.height
- 2*launcher
->area
.bg
->border
.width
- 2*launcher
->area
.paddingy
;
149 // here icons_per_column always higher than 0
150 icons_per_column
= (height
+launcher
->area
.paddingx
) / (icon_size
+launcher
->area
.paddingx
);
151 marging
= height
- (icons_per_column
-1)*(icon_size
+launcher
->area
.paddingx
) - icon_size
;
152 icons_per_row
= count
/ icons_per_column
+ (count%icons_per_column
!= 0);
153 launcher
->area
.width
= (2 * launcher
->area
.bg
->border
.width
) + (2 * launcher
->area
.paddingxlr
) + (icon_size
* icons_per_row
) + ((icons_per_row
-1) * launcher
->area
.paddingx
);
156 launcher
->area
.posx
= panel
->area
.bg
->border
.width
+ panel
->area
.paddingxlr
;
157 launcher
->area
.posy
= panel
->area
.bg
->border
.width
;
160 if (!count
) launcher
->area
.height
= 0;
162 int width
= launcher
->area
.width
- 2*launcher
->area
.bg
->border
.width
- 2*launcher
->area
.paddingy
;
163 // here icons_per_row always higher than 0
164 icons_per_row
= (width
+launcher
->area
.paddingx
) / (icon_size
+launcher
->area
.paddingx
);
165 marging
= width
- (icons_per_row
-1)*(icon_size
+launcher
->area
.paddingx
) - icon_size
;
166 icons_per_column
= count
/ icons_per_row
+ (count%icons_per_row
!= 0);
167 launcher
->area
.height
= (2 * launcher
->area
.bg
->border
.width
) + (2 * launcher
->area
.paddingxlr
) + (icon_size
* icons_per_column
) + ((icons_per_column
-1) * launcher
->area
.paddingx
);
170 launcher
->area
.posx
= panel
->area
.bg
->border
.width
;
171 launcher
->area
.posy
= panel
->area
.height
- panel
->area
.bg
->border
.width
- panel
->area
.paddingxlr
- launcher
->area
.height
;
175 int start
= launcher
->area
.bg
->border
.width
+ launcher
->area
.paddingy
;// +marging/2;
176 if (panel_horizontal
) {
178 posx
= launcher
->area
.bg
->border
.width
+ launcher
->area
.paddingxlr
;
182 posy
= launcher
->area
.bg
->border
.width
+ launcher
->area
.paddingxlr
;
185 for (i
=1, l
= launcher
->list_icons
; l
; i
++, l
= l
->next
) {
186 LauncherIcon
*launcherIcon
= (LauncherIcon
*)l
->data
;
188 launcherIcon
->y
= posy
;
189 launcherIcon
->x
= posx
;
190 launcherIcon
->width
= icon_size
;
191 launcherIcon
->height
= icon_size
;
192 if (panel_horizontal
) {
193 if (i
% icons_per_column
)
194 posy
+= icon_size
+ launcher
->area
.paddingx
;
197 posx
+= (icon_size
+ launcher
->area
.paddingx
);
201 if (i
% icons_per_row
)
202 posx
+= icon_size
+ launcher
->area
.paddingx
;
205 posy
+= (icon_size
+ launcher
->area
.paddingx
);
210 // resize force the redraw
211 launcher
->area
.redraw
= 1;
215 void draw_launcher(void *obj
, cairo_t
*c
)
217 Launcher
*launcher
= obj
;
219 if (launcher
->list_icons
== 0) return;
221 for (l
= launcher
->list_icons
; l
; l
= l
->next
) {
222 LauncherIcon
*launcherIcon
= (LauncherIcon
*)l
->data
;
223 int pos_x
= launcherIcon
->x
;
224 int pos_y
= launcherIcon
->y
;
225 int width
= launcherIcon
->width
;
226 int height
= launcherIcon
->height
;
227 Imlib_Image icon_scaled
;
228 if (launcherIcon
->icon
) {
229 imlib_context_set_image (launcherIcon
->icon
);
230 icon_scaled
= imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), width
, height
);
232 icon_scaled
= imlib_create_image(width
, height
);
233 imlib_context_set_image (icon_scaled
);
234 imlib_context_set_color(255, 255, 255, 255);
235 imlib_image_fill_rectangle(0, 0, width
, height
);
239 imlib_context_set_image (icon_scaled
);
240 if (server
.real_transparency
) {
241 render_image(launcher
->area
.pix
, pos_x
, pos_y
, imlib_image_get_width(), imlib_image_get_height() );
244 imlib_context_set_drawable(launcher
->area
.pix
);
245 imlib_render_image_on_drawable (pos_x
, pos_y
);
251 void launcher_action(LauncherIcon
*icon
)
253 char *cmd
= malloc(strlen(icon
->cmd
) + 10);
254 sprintf(cmd
, "(%s&)", icon
->cmd
);
This page took 0.045406 seconds and 4 git commands to generate.