4 #include <X11/extensions/shape.h>
13 int posx
[4]={8,17,26,35};
14 static struct tm
*clk
;
20 XSizeHints mysizehints
;
22 Pixel back_pix
,fore_pix
;
25 char *LedColor
="LightSeaGreen";
26 char *ERR_colorcells
="not enough free color cells\n";
27 typedef struct _XpmIcon
{
30 XpmAttributes attributes
;
37 #define MW_EVENTS (ExposureMask | ButtonPressMask | StructureNotifyMask)
40 static void CreatePixmap(Display
*dpy
, Window Root
, char **data
, XpmIcon
* icon
);
41 Pixel
GetColor(char *name
);
42 void RedrawWindow( XpmIcon
*v
);
45 int main(int argc
,char *argv
[])
48 unsigned int borderwidth
;
49 char *display_name
=NULL
;
50 char *wname
="asbeats";
58 if (!(dpy
= XOpenDisplay(display_name
)))
60 fprintf(stderr
,"asbeats: can't open display %s\n",
61 XDisplayName(display_name
));
64 screen
=DefaultScreen(dpy
);
65 Root
=RootWindow(dpy
,screen
);
66 d_depth
=DefaultDepth(dpy
,screen
);
67 XConnectionNumber(dpy
);
69 mysizehints
.flags
=USSize
|USPosition
;
72 back_pix
=GetColor("white");
73 fore_pix
=GetColor("black");
74 XWMGeometry(dpy
,screen
,Geometry
,NULL
,(borderwidth
=1),
75 &mysizehints
,&mysizehints
.x
,&mysizehints
.y
,
76 &mysizehints
.width
,&mysizehints
.height
,&i
);
77 mysizehints
.width
=wmclock
.attributes
.width
;
78 mysizehints
.height
=wmclock
.attributes
.height
;
79 win
=XCreateSimpleWindow(dpy
,Root
,mysizehints
.x
,mysizehints
.y
,
80 mysizehints
.width
,mysizehints
.height
,borderwidth
,
82 iconwin
=XCreateSimpleWindow(dpy
,win
,mysizehints
.x
,mysizehints
.y
,
83 mysizehints
.width
,mysizehints
.height
,borderwidth
,fore_pix
,
85 XSetWMNormalHints(dpy
,win
,&mysizehints
);
86 classHint
.res_name
="asbeats";
87 classHint
.res_class
="ASBeats";
88 XSetClassHint(dpy
,win
,&classHint
);
89 XSelectInput(dpy
,win
,MW_EVENTS
);
90 XSelectInput(dpy
,iconwin
,MW_EVENTS
);
91 if(XStringListToTextProperty(&wname
,1,&name
)==0)
93 fprintf(stderr
,"asbeats: can't allocate window name\n");
96 XSetWMName(dpy
, win
, &name
);
97 gcm
= GCForeground
|GCBackground
|GCGraphicsExposures
;
98 gcv
.foreground
= fore_pix
;
99 gcv
.background
= back_pix
;
100 gcv
.graphics_exposures
= FALSE
;
101 NormalGC
= XCreateGC(dpy
, Root
, gcm
, &gcv
);
102 pixmask
= XCreateBitmapFromData(dpy
, win
, mask_bits
, mask_width
,
104 XShapeCombineMask(dpy
, win
, ShapeBounding
, 0, 0, pixmask
, ShapeSet
);
105 XShapeCombineMask(dpy
, iconwin
, ShapeBounding
, 0, 0, pixmask
, ShapeSet
);
106 mywmhints
.initial_state
= WithdrawnState
;
107 mywmhints
.icon_window
= iconwin
;
108 mywmhints
.icon_x
= mysizehints
.x
;
109 mywmhints
.icon_y
= mysizehints
.y
;
110 mywmhints
.window_group
= win
;
111 mywmhints
.flags
= StateHint
| IconWindowHint
|
112 IconPositionHint
| WindowGroupHint
;
113 XSetWMHints(dpy
, win
, &mywmhints
);
114 XSetCommand(dpy
, win
, argv
, argc
);
117 RedrawWindow(&visible
);
120 if (actualtime
!= time(0))
123 RedrawWindow(&visible
);
126 while (XPending(dpy
))
128 XNextEvent(dpy
,&Event
);
132 if(Event
.xexpose
.count
== 0 )
133 RedrawWindow(&visible
);
148 void nocolor(char *a
, char *b
)
150 fprintf(stderr
,"asbeats: can't %s %s\n", a
,b
);
156 XWindowAttributes attributes
;
160 XGetWindowAttributes(dpy
,Root
,&attributes
);
161 if(!XParseColor(dpy
,attributes
.colormap
,LedColor
,&col
))
163 nocolor("parse",LedColor
);
165 sprintf(&led1
[0],". c #%4X%4X%4X",col
.red
,col
.green
,col
.blue
);
166 for(ret
=10;ret
<22;ret
++)
169 led_xpm
[2] = &led1
[0];
170 col
.red
=(col
.red
/10)*3;
171 col
.green
=(col
.green
/10)*3;
172 col
.blue
=(col
.blue
/10)*3;
173 sprintf(&led2
[0],"X c #%4X%4X%4X",col
.red
,col
.green
,col
.blue
);
174 for(ret
=10;ret
<22;ret
++)
178 CreatePixmap(dpy
,Root
,mask_xpm
,&wmclock
);
179 CreatePixmap(dpy
,Root
,mask_xpm
,&visible
);
180 CreatePixmap(dpy
,Root
,led_xpm
,&led
);
183 static void CreatePixmap(Display
*dpy
, Window Root
, char **data
, XpmIcon
* icon
)
186 icon
->attributes
.valuemask
|= (XpmReturnPixels
|
187 XpmReturnExtensions
| XpmExactColors
| XpmCloseness
);
188 icon
->attributes
.exactColors
=False
;
189 icon
->attributes
.closeness
=40000;
190 ret
=XpmCreatePixmapFromData(dpy
,Root
,data
,&(icon
->pixmap
),
191 &(icon
->mask
),&(icon
->attributes
));
192 if(ret
!= XpmSuccess
)
194 fprintf(stderr
,ERR_colorcells
);
199 int flush_expose (Window w
)
203 while(XCheckTypedWindowEvent(dpy
,w
,Expose
,&dummy
))
208 void RedrawWindow( XpmIcon
*v
)
210 flush_expose (iconwin
);
211 XCopyArea(dpy
,v
->pixmap
,iconwin
,NormalGC
,0,0,v
->attributes
.width
,
212 v
->attributes
.height
,0,0);
214 XCopyArea(dpy
,v
->pixmap
,win
,NormalGC
,0,0,v
->attributes
.width
,
215 v
->attributes
.height
,0,0);
218 Pixel
GetColor(char *name
)
221 XWindowAttributes attributes
;
222 XGetWindowAttributes(dpy
,Root
,&attributes
);
224 if (!XParseColor(dpy
,attributes
.colormap
,name
,&color
))
225 nocolor("parse",name
);
226 else if(!XAllocColor (dpy
,attributes
.colormap
,&color
))
227 nocolor("alloc",name
);
235 fTime
=(clk
->tm_hour
*3600+clk
->tm_min
*60+clk
->tm_sec
);
236 fTime
=fTime
+timezone
+3600;
239 fTime
=(fTime
*1000)/86400;
246 XCopyArea(dpy
,led
.pixmap
,visible
.pixmap
,NormalGC
,
247 90,0,9,11,posx
[0],15);
248 XCopyArea(dpy
,led
.pixmap
,visible
.pixmap
,NormalGC
,
249 9*(((int)fTime
)/100),0,9,11,posx
[1],15);
250 XCopyArea(dpy
,led
.pixmap
,visible
.pixmap
,NormalGC
,
251 9*((((int)fTime
) / 10) % 10),0,9,11,posx
[2],15);
252 XCopyArea(dpy
,led
.pixmap
,visible
.pixmap
,NormalGC
,
253 9*((int)fTime
% 10),0,9,11,posx
[3],15);
255 fTime
= abs(((fTime
- abs(fTime
)) * 1000) + 0.5);
257 XCopyArea(dpy
,led
.pixmap
,visible
.pixmap
,NormalGC
,
258 99,0,9,11,posx
[0],32);
259 XCopyArea(dpy
,led
.pixmap
,visible
.pixmap
,NormalGC
,
260 9*(((int)fTime
)/100),0,9,11,posx
[1],32);
261 XCopyArea(dpy
,led
.pixmap
,visible
.pixmap
,NormalGC
,
262 9*((((int)fTime
) / 10) % 10),0,9,11,posx
[2],32);
263 XCopyArea(dpy
,led
.pixmap
,visible
.pixmap
,NormalGC
,
264 9*((int)fTime
% 10),0,9,11,posx
[3],32);
272 clk
=localtime(&actualtime
);
273 XCopyArea(dpy
,wmclock
.pixmap
,visible
.pixmap
,NormalGC
,
274 0,0,mysizehints
.width
,mysizehints
.height
,0,0);