3 * Copyright (C) Renan Vedovato Traba 2012 <rvt10@inf.ufpr.br>
5 ButtonMaker is free software: you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 ButtonMaker is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include <sys/timeb.h>
32 #include "wmgeneral.h"
39 static void print_usage(char *);
40 static void ParseCMDLine(int argc
, char *argv
[]);
42 static void print_usage(char * pname
)
44 printf("%s version: %s\n", pname
, VERSION
);
45 printf("By Renan Vedovato Traba <rvt10@inf.ufpr.br>\n\n");
46 printf("\t-c, --command [CMD]\t which command will be called \n");
47 printf("\t-i, --icon [ICON]\t icon displayed\n");
48 printf("\t-s, --size [SIZE]\t size of the icon\n");
49 printf("\tdouble click to run CMD\n");
50 printf("\tright click to exit\n");
51 printf("\neg:\n%s -c sudo apt-get update -i TerminalGNUstep.tiff -s 32\n", pname
);
54 static void ParseCMDLine(int argc
, char *argv
[])
57 for (i
=1; i
< argc
; i
++) {
58 if (!strcmp(argv
[i
], "-display")) {
60 } else if ( ((!strcmp(argv
[i
], "--icon")) || (!strcmp(argv
[i
], "-i"))) && (i
+1 < argc
) ) {
62 } else if ( ((!strcmp(argv
[i
], "--size")) || (!strcmp(argv
[i
], "-s"))) && (i
+1 < argc
) ) {
63 isize
= atoi(argv
[++i
]);
64 } else if ( ((!strcmp(argv
[i
], "--command")) || (!strcmp(argv
[i
], "-c"))) && (i
+1 < argc
) ) {
65 for (j
=i
+1; j
< argc
; j
++) {
66 if (argv
[j
][0] == '-') {
69 size
+=1+strlen(argv
[j
]);
72 cmd
= (char *) malloc((size
)*sizeof(char));
73 for (k
=i
+1; k
< j
; k
++) {
84 if ((argc
< 3) || (!cmd
)) {
90 int main(int argc
, char *argv
[])
95 extern Window iconwin
, win
;
103 ParseCMDLine(argc
, argv
);
104 openXwindow(argc
, argv
, xpm_master
, xpm_mask_bits
, xpm_mask_width
, xpm_mask_height
);
106 xpm
= XCreatePixmap(display
, win
, 64, 64, d_depth
);
107 XFillRectangle(display
, xpm
, NormalGC
, 0, 0, 64, 64);
110 visual
= DefaultVisual(display
, DefaultScreen(display
));
112 imlib_context_set_dither(1);
113 imlib_context_set_display(display
);
114 imlib_context_set_visual(visual
);
116 image
= imlib_load_image(fname
);
117 imlib_context_set_image(image
);
118 imlib_context_set_drawable(xpm
);
119 imlib_render_image_on_drawable_at_size(0, 0, isize
, isize
);
124 /* Process any pending X events. */
125 while (XPending(display
)) {
126 XNextEvent(display
, &event
);
127 switch (event
.type
) {
130 XCopyArea(display
, xpm
, iconwin
, NormalGC
, 0, 0, isize
, isize
, b
, b
);
135 /*printf("ButtonPress\n");*/
138 if (event
.xbutton
.button
== Button1
) {
139 if (event
.xbutton
.time
- lastTime
< 250) {
140 if (system(cmd
) == -1) {
141 fprintf(stdout
, "Failed to run command:%s\n", cmd
);
145 lastTime
= event
.xbutton
.time
;
147 } else if (event
.xbutton
.button
== Button3
) {
150 /*printf("ButtonRelease\n");*/
156 /* we should never get here */