3 #include "arg_parser.h"
6 static int offset_w
, offset_h
;
9 static int day
, month
, year
;
10 static Pixmap
*background_pixmap
;
12 void free_resources() {
13 XFreeGC(display
, gc_core
);
14 XFreeGC(display
, gc_border
);
19 printf("\nThank you for using wmframepic\n");
24 void draw_screen_with_mask() {
25 XNextEvent(display
, &event
);
27 while(event
.type
!= Expose
)
30 XCopyArea(display
, *background_pixmap
, iconwin
, gc_border
, 0, 0, 64, 64, offset_w
, offset_h
);
31 XCopyArea(display
, pic_pixmap
, iconwin
, gc_core
, 0, 0, 64, 64, offset_w
, offset_h
);
37 XButtonPressedEvent
*bevent
;
39 XNextEvent(display
, &event
);
42 XCopyArea(display
, *background_pixmap
, iconwin
, gc_border
, 0, 0, 64, 64, offset_w
, offset_h
);
43 XCopyArea(display
, pic_pixmap
, iconwin
, gc_core
, 0, 0, 64, 64, offset_w
, offset_h
);
46 bevent
= (XButtonPressedEvent
*) &event
;
47 switch (bevent
->button
& 0xff) {
52 XCopyArea(display
, pic_pixmap
, iconwin
, gc_core
, 0, 0, 64, 64, offset_w
, offset_h
);
56 draw_text(name
, 3, 8, False
);
57 char **phrases
= get_phrases(day
, month
, year
);
59 for(i
= 0; i
< NUMBER_OF_ROWS
; i
++) {
60 draw_text(phrases
[i
], 3, 23 + 10 * i
, False
);
63 clear_phrases(phrases
);
79 int main(int argc
, char **argv
) {
83 Bool dockapp_iswindowed
= False
;
86 XClassHint
*classHint
;
88 if(signal(SIGINT
, sig_int
) == SIG_ERR
)
89 fprintf(stderr
, "signal error\n");
91 error
= get_values_from_command_line(argc
, argv
, name
, &file
, &day
, &month
, &year
);
93 if(COMMAND_LINE_FAIL
== error
|| COMMAND_LINE_HELP
== error
) {
99 if( ( display
= XOpenDisplay(NULL
) ) == NULL
){
100 fprintf(stderr
, "Error: XOpenDisplay\n");
104 root
= RootWindow(display
, screen
= DefaultScreen(display
));
106 values
.foreground
= BlackPixel(display
, screen
);
107 values
.background
= WhitePixel(display
, screen
);
111 Pixmap pixmask_border
= XCreateBitmapFromData(display
, root
, frame_mask_bits
,
115 gc_border
= XCreateGC(display
, root
, GCForeground
| GCBackground
, &values
);
116 XSetClipMask(display
, gc_border
, pixmask_border
);
118 Pixmap pixmask_core
= XCreateBitmapFromData(display
, root
, core_mask_bits
,
123 gc_core
= XCreateGC(display
, root
, GCForeground
| GCBackground
, &values
);
124 XSetClipMask(display
, gc_core
, pixmask_core
);
126 XFreePixmap(display
, pixmask_border
);
127 XFreePixmap(display
, pixmask_core
);
129 if (dockapp_iswindowed
) {
130 offset_w
= (WINDOWED_SIZE_W
- w
) / 2;
131 offset_h
= (WINDOWED_SIZE_H
- h
) / 2;
132 ww
= WINDOWED_SIZE_W
;
133 wh
= WINDOWED_SIZE_H
;
135 offset_w
= offset_h
= 0;
140 sizehints
.flags
= USSize
| USPosition
;
141 if (!dockapp_iswindowed
) {
142 sizehints
.flags
|= USPosition
;
143 sizehints
.x
= sizehints
.y
= 0;
145 sizehints
.flags
|= PMinSize
| PMaxSize
;
146 sizehints
.min_width
= sizehints
.max_width
= WINDOWED_SIZE_W
;
147 sizehints
.min_height
= sizehints
.max_height
= WINDOWED_SIZE_H
;
149 sizehints
.width
= ww
;
150 sizehints
.height
= wh
;
152 win
= XCreateSimpleWindow(display
, root
, 0, 0, ww
, wh
, depth
, values
.foreground
,
155 iconwin
= XCreateSimpleWindow(display
, root
, 0, 0, ww
, wh
, depth
, values
.foreground
,
160 XSetWMNormalHints(display
, win
, &sizehints
);
162 wmHints
= XAllocWMHints();
163 if (wmHints
== NULL
) {
164 fprintf(stderr
, "%s: can't allocate memory for wm hints!\n", argv
[0]);
168 wmHints
->initial_state
= WithdrawnState
;
169 wmHints
->icon_window
= iconwin
;
170 wmHints
->icon_x
= sizehints
.x
;
171 wmHints
->icon_y
= sizehints
.y
;
172 wmHints
->window_group
= win
;
173 wmHints
->flags
= StateHint
|IconWindowHint
|IconPositionHint
|WindowGroupHint
;
174 XSetWMHints(display
, win
, wmHints
);
177 classHint
= XAllocClassHint();
178 if (classHint
== NULL
) {
179 fprintf(stderr
, "%s: can't allocate memory for wm hints!\n", argv
[0]);
183 classHint
->res_name
= argv
[0];
184 classHint
->res_class
= argv
[0];
185 XSetClassHint(display
, win
, classHint
);
187 // Let the window manager know about the link of commands
188 XSetCommand(display
, win
, argv
, argc
);
190 //XpmCreatePixmapFromData(display, root, kid_xpm, &pic_pixmap,NULL,NULL);
191 char **xpm_file_data
;
192 if(-1 == XpmReadFileToData(file
, &xpm_file_data
)) {
193 printf("could not read from file %s\nplease check file path\n", file
);
197 XpmCreatePixmapFromData(display
, root
, xpm_file_data
, &pic_pixmap
,NULL
,NULL
);
198 XSelectInput(display
, win
, eventmask
);
199 XSelectInput(display
,iconwin
, eventmask
);
200 XMapWindow(display
, win
);
202 init_variables(display
, gc_core
, iconwin
, offset_w
, offset_h
, &background_pixmap
);
204 draw_screen_with_mask();