]>
Dogcows Code - chaz/tint2/blob - src/launcher/launcher.c
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
._resize
= resize_launcher
;
60 launcher
->area
.resize
= 1;
61 launcher
->area
.redraw
= 1;
62 launcher
->area
.on_screen
= 1;
64 if (panel_horizontal
) {
65 // panel horizonal => fixed height and posy
66 launcher
->area
.posy
= panel
->area
.bg
->border
.width
+ panel
->area
.paddingy
;
67 launcher
->area
.height
= panel
->area
.height
- (2 * launcher
->area
.posy
);
70 // panel vertical => fixed width, height, posy and posx
71 launcher
->area
.posx
= panel
->area
.bg
->border
.width
+ panel
->area
.paddingxlr
;
72 launcher
->area
.width
= panel
->area
.width
- (2 * panel
->area
.bg
->border
.width
) - (2 * panel
->area
.paddingy
);
77 GSList
* path
= launcher
->list_icon_paths
;
78 GSList
* cmd
= launcher
->list_cmds
;
79 while (path
!= NULL
&& cmd
!= NULL
)
81 LauncherIcon
*launcherIcon
= malloc(sizeof(LauncherIcon
));
82 launcherIcon
->icon
= imlib_load_image(path
->data
);
83 launcherIcon
->cmd
= strdup(cmd
->data
);
84 launcher
->list_icons
= g_slist_append(launcher
->list_icons
, launcherIcon
);
85 path
= g_slist_next(path
);
86 cmd
= g_slist_next(cmd
);
92 void cleanup_launcher()
96 for (i
= 0 ; i
< nb_panel
; i
++) {
97 Panel
*panel
= &panel1
[i
];
98 Launcher
*launcher
= &panel
->launcher
;
99 free_area(&launcher
->area
);
101 for (l
= launcher
->list_icons
; l
; l
= l
->next
) {
102 LauncherIcon
*launcherIcon
= (LauncherIcon
*)l
->data
;
103 if (launcherIcon
&& launcherIcon
->icon
) {
104 imlib_context_set_image (launcherIcon
->icon
);
107 free(launcherIcon
->cmd
);
110 g_slist_free(launcher
->list_icons
);
111 for (l
= launcher
->list_icon_paths
; l
; l
= l
->next
) {
114 g_slist_free(launcher
->list_icon_paths
);
115 for (l
= launcher
->list_cmds
; l
; l
= l
->next
) {
118 g_slist_free(launcher
->list_cmds
);
120 launcher_enabled
= 0;
123 void resize_launcher(void *obj
)
125 Launcher
*launcher
= obj
;
126 Panel
*panel
= launcher
->area
.panel
;
128 int count
, icon_size
;
129 int icons_per_column
=1, icons_per_row
=1, marging
=0;
131 if (panel_horizontal
)
132 icon_size
= launcher
->area
.height
;
134 icon_size
= launcher
->area
.width
;
135 icon_size
= icon_size
- (2 * launcher
->area
.bg
->border
.width
) - (2 * launcher
->area
.paddingy
);
136 if (launcher_max_icon_size
> 0 && icon_size
> launcher_max_icon_size
)
137 icon_size
= launcher_max_icon_size
;
140 for (l
= launcher
->list_icons
; l
; l
= l
->next
) {
144 if (panel_horizontal
) {
145 if (!count
) launcher
->area
.width
= 0;
147 int height
= launcher
->area
.height
- 2*launcher
->area
.bg
->border
.width
- 2*launcher
->area
.paddingy
;
148 // here icons_per_column always higher than 0
149 icons_per_column
= (height
+launcher
->area
.paddingx
) / (icon_size
+launcher
->area
.paddingx
);
150 marging
= height
- (icons_per_column
-1)*(icon_size
+launcher
->area
.paddingx
) - icon_size
;
151 icons_per_row
= count
/ icons_per_column
+ (count%icons_per_column
!= 0);
152 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
);
155 launcher
->area
.posx
= panel
->area
.bg
->border
.width
+ panel
->area
.paddingxlr
;
156 launcher
->area
.posy
= panel
->area
.bg
->border
.width
;
159 if (!count
) launcher
->area
.height
= 0;
161 int width
= launcher
->area
.width
- 2*launcher
->area
.bg
->border
.width
- 2*launcher
->area
.paddingy
;
162 // here icons_per_row always higher than 0
163 icons_per_row
= (width
+launcher
->area
.paddingx
) / (icon_size
+launcher
->area
.paddingx
);
164 marging
= width
- (icons_per_row
-1)*(icon_size
+launcher
->area
.paddingx
) - icon_size
;
165 icons_per_column
= count
/ icons_per_row
+ (count%icons_per_row
!= 0);
166 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
);
169 launcher
->area
.posx
= panel
->area
.bg
->border
.width
;
170 launcher
->area
.posy
= panel
->area
.height
- panel
->area
.bg
->border
.width
- panel
->area
.paddingxlr
- launcher
->area
.height
;
174 int start
= launcher
->area
.bg
->border
.width
+ launcher
->area
.paddingy
;// +marging/2;
175 if (panel_horizontal
) {
177 posx
= launcher
->area
.bg
->border
.width
+ launcher
->area
.paddingxlr
;
181 posy
= launcher
->area
.bg
->border
.width
+ launcher
->area
.paddingxlr
;
184 for (i
=1, l
= launcher
->list_icons
; l
; i
++, l
= l
->next
) {
185 LauncherIcon
*launcherIcon
= (LauncherIcon
*)l
->data
;
187 launcherIcon
->y
= posy
;
188 launcherIcon
->x
= posx
;
189 launcherIcon
->width
= icon_size
;
190 launcherIcon
->height
= icon_size
;
191 if (panel_horizontal
) {
192 if (i
% icons_per_column
)
193 posy
+= icon_size
+ launcher
->area
.paddingx
;
196 posx
+= (icon_size
+ launcher
->area
.paddingx
);
200 if (i
% icons_per_row
)
201 posx
+= icon_size
+ launcher
->area
.paddingx
;
204 posy
+= (icon_size
+ launcher
->area
.paddingx
);
209 // resize force the redraw
210 launcher
->area
.redraw
= 1;
214 void draw_launcher(void *obj
, cairo_t
*c
)
216 Launcher
*launcher
= obj
;
218 if (launcher
->list_icons
== 0) return;
220 for (l
= launcher
->list_icons
; l
; l
= l
->next
) {
221 LauncherIcon
*launcherIcon
= (LauncherIcon
*)l
->data
;
222 int pos_x
= launcherIcon
->x
;
223 int pos_y
= launcherIcon
->y
;
224 int width
= launcherIcon
->width
;
225 int height
= launcherIcon
->height
;
226 Imlib_Image icon_scaled
;
227 if (launcherIcon
->icon
) {
228 imlib_context_set_image (launcherIcon
->icon
);
229 icon_scaled
= imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), width
, height
);
231 icon_scaled
= imlib_create_image(width
, height
);
232 imlib_context_set_image (icon_scaled
);
233 imlib_context_set_color(255, 255, 255, 255);
234 imlib_image_fill_rectangle(0, 0, width
, height
);
238 imlib_context_set_image (icon_scaled
);
239 if (server
.real_transparency
) {
240 render_image(launcher
->area
.pix
, pos_x
, pos_y
, imlib_image_get_width(), imlib_image_get_height() );
243 imlib_context_set_drawable(launcher
->area
.pix
);
244 imlib_render_image_on_drawable (pos_x
, pos_y
);
250 void launcher_action(LauncherIcon
*icon
)
252 char *cmd
= malloc(strlen(icon
->cmd
) + 10);
253 sprintf(cmd
, "(%s&)", icon
->cmd
);
258 // change for the fork the signal mask
260 // sigprocmask(SIG_SETMASK, &sigset, 0);
261 // sigprocmask(SIG_UNBLOCK, &sigset, 0);
263 execl("/bin/sh", "/bin/sh", "-c", cmd
, NULL
);
This page took 0.046198 seconds and 5 git commands to generate.