6 #include <X11/extensions/shape.h>
15 int posx
[4]={8,17,26,35};
16 static struct tm
*clk
;
22 XSizeHints mysizehints
;
24 Pixel back_pix
,fore_pix
;
27 char *LedColor
="LightSeaGreen";
28 char *ERR_colorcells
="not enough free color cells\n";
29 typedef struct _XpmIcon
{
32 XpmAttributes attributes
;
39 #define MW_EVENTS (ExposureMask | ButtonPressMask | StructureNotifyMask)
42 static void CreatePixmap(Display
*dpy
, Window Root
, char **data
, XpmIcon
* icon
);
43 Pixel
GetColor(char *name
);
44 void RedrawWindow( XpmIcon
*v
);
47 int main(int argc
,char *argv
[])
50 unsigned int borderwidth
;
51 char *display_name
=NULL
;
52 char *wname
="asbeats";
60 if (!(dpy
= XOpenDisplay(display_name
)))
62 fprintf(stderr
,"asbeats: can't open display %s\n",
63 XDisplayName(display_name
));
66 screen
=DefaultScreen(dpy
);
67 Root
=RootWindow(dpy
,screen
);
68 d_depth
=DefaultDepth(dpy
,screen
);
69 XConnectionNumber(dpy
);
71 mysizehints
.flags
=USSize
|USPosition
;
74 back_pix
=GetColor("white");
75 fore_pix
=GetColor("black");
76 XWMGeometry(dpy
,screen
,Geometry
,NULL
,(borderwidth
=1),
77 &mysizehints
,&mysizehints
.x
,&mysizehints
.y
,
78 &mysizehints
.width
,&mysizehints
.height
,&i
);
79 mysizehints
.width
=wmclock
.attributes
.width
;
80 mysizehints
.height
=wmclock
.attributes
.height
;
81 win
=XCreateSimpleWindow(dpy
,Root
,mysizehints
.x
,mysizehints
.y
,
82 mysizehints
.width
,mysizehints
.height
,borderwidth
,
84 iconwin
=XCreateSimpleWindow(dpy
,win
,mysizehints
.x
,mysizehints
.y
,
85 mysizehints
.width
,mysizehints
.height
,borderwidth
,fore_pix
,
87 XSetWMNormalHints(dpy
,win
,&mysizehints
);
88 classHint
.res_name
="asbeats";
89 classHint
.res_class
="ASBeats";
90 XSetClassHint(dpy
,win
,&classHint
);
91 XSelectInput(dpy
,win
,MW_EVENTS
);
92 XSelectInput(dpy
,iconwin
,MW_EVENTS
);
93 if(XStringListToTextProperty(&wname
,1,&name
)==0)
95 fprintf(stderr
,"asbeats: can't allocate window name\n");
98 XSetWMName(dpy
, win
, &name
);
99 gcm
= GCForeground
|GCBackground
|GCGraphicsExposures
;
100 gcv
.foreground
= fore_pix
;
101 gcv
.background
= back_pix
;
102 gcv
.graphics_exposures
= FALSE
;
103 NormalGC
= XCreateGC(dpy
, Root
, gcm
, &gcv
);
104 pixmask
= XCreateBitmapFromData(dpy
, win
, mask_bits
, mask_width
,
106 XShapeCombineMask(dpy
, win
, ShapeBounding
, 0, 0, pixmask
, ShapeSet
);
107 XShapeCombineMask(dpy
, iconwin
, ShapeBounding
, 0, 0, pixmask
, ShapeSet
);
108 mywmhints
.initial_state
= WithdrawnState
;
109 mywmhints
.icon_window
= iconwin
;
110 mywmhints
.icon_x
= mysizehints
.x
;
111 mywmhints
.icon_y
= mysizehints
.y
;
112 mywmhints
.window_group
= win
;
113 mywmhints
.flags
= StateHint
| IconWindowHint
|
114 IconPositionHint
| WindowGroupHint
;
115 XSetWMHints(dpy
, win
, &mywmhints
);
116 XSetCommand(dpy
, win
, argv
, argc
);
119 RedrawWindow(&visible
);
122 if (actualtime
!= time(0))
125 RedrawWindow(&visible
);
128 while (XPending(dpy
))
130 XNextEvent(dpy
,&Event
);
134 if(Event
.xexpose
.count
== 0 )
135 RedrawWindow(&visible
);
150 void nocolor(char *a
, char *b
)
152 fprintf(stderr
,"asbeats: can't %s %s\n", a
,b
);
158 XWindowAttributes attributes
;
162 XGetWindowAttributes(dpy
,Root
,&attributes
);
163 if(!XParseColor(dpy
,attributes
.colormap
,LedColor
,&col
))
165 nocolor("parse",LedColor
);
167 sprintf(&led1
[0],". c #%4X%4X%4X",col
.red
,col
.green
,col
.blue
);
168 for(ret
=10;ret
<22;ret
++)
171 led_xpm
[2] = &led1
[0];
172 col
.red
=(col
.red
/10)*3;
173 col
.green
=(col
.green
/10)*3;
174 col
.blue
=(col
.blue
/10)*3;
175 sprintf(&led2
[0],"X c #%4X%4X%4X",col
.red
,col
.green
,col
.blue
);
176 for(ret
=10;ret
<22;ret
++)
180 CreatePixmap(dpy
,Root
,mask_xpm
,&wmclock
);
181 CreatePixmap(dpy
,Root
,mask_xpm
,&visible
);
182 CreatePixmap(dpy
,Root
,led_xpm
,&led
);
185 static void CreatePixmap(Display
*dpy
, Window Root
, char **data
, XpmIcon
* icon
)
188 icon
->attributes
.valuemask
|= (XpmReturnPixels
|
189 XpmReturnExtensions
| XpmExactColors
| XpmCloseness
);
190 icon
->attributes
.exactColors
=False
;
191 icon
->attributes
.closeness
=40000;
192 ret
=XpmCreatePixmapFromData(dpy
,Root
,data
,&(icon
->pixmap
),
193 &(icon
->mask
),&(icon
->attributes
));
194 if(ret
!= XpmSuccess
)
196 fprintf(stderr
,"%s",ERR_colorcells
);
201 int flush_expose (Window w
)
205 while(XCheckTypedWindowEvent(dpy
,w
,Expose
,&dummy
))
210 void RedrawWindow( XpmIcon
*v
)
212 flush_expose (iconwin
);
213 XCopyArea(dpy
,v
->pixmap
,iconwin
,NormalGC
,0,0,v
->attributes
.width
,
214 v
->attributes
.height
,0,0);
216 XCopyArea(dpy
,v
->pixmap
,win
,NormalGC
,0,0,v
->attributes
.width
,
217 v
->attributes
.height
,0,0);
220 Pixel
GetColor(char *name
)
223 XWindowAttributes attributes
;
224 XGetWindowAttributes(dpy
,Root
,&attributes
);
226 if (!XParseColor(dpy
,attributes
.colormap
,name
,&color
))
227 nocolor("parse",name
);
228 else if(!XAllocColor (dpy
,attributes
.colormap
,&color
))
229 nocolor("alloc",name
);
237 fTime
=(clk
->tm_hour
*3600+clk
->tm_min
*60+clk
->tm_sec
);
238 fTime
=fTime
+timezone
+3600;
241 fTime
=(fTime
*1000)/86400;
248 XCopyArea(dpy
,led
.pixmap
,visible
.pixmap
,NormalGC
,
249 90,0,9,11,posx
[0],15);
250 XCopyArea(dpy
,led
.pixmap
,visible
.pixmap
,NormalGC
,
251 9*(((int)fTime
)/100),0,9,11,posx
[1],15);
252 XCopyArea(dpy
,led
.pixmap
,visible
.pixmap
,NormalGC
,
253 9*((((int)fTime
) / 10) % 10),0,9,11,posx
[2],15);
254 XCopyArea(dpy
,led
.pixmap
,visible
.pixmap
,NormalGC
,
255 9*((int)fTime
% 10),0,9,11,posx
[3],15);
257 fTime
= abs(((fTime
- abs(fTime
)) * 1000) + 0.5);
259 XCopyArea(dpy
,led
.pixmap
,visible
.pixmap
,NormalGC
,
260 99,0,9,11,posx
[0],32);
261 XCopyArea(dpy
,led
.pixmap
,visible
.pixmap
,NormalGC
,
262 9*(((int)fTime
)/100),0,9,11,posx
[1],32);
263 XCopyArea(dpy
,led
.pixmap
,visible
.pixmap
,NormalGC
,
264 9*((((int)fTime
) / 10) % 10),0,9,11,posx
[2],32);
265 XCopyArea(dpy
,led
.pixmap
,visible
.pixmap
,NormalGC
,
266 9*((int)fTime
% 10),0,9,11,posx
[3],32);
274 clk
=localtime(&actualtime
);
275 XCopyArea(dpy
,wmclock
.pixmap
,visible
.pixmap
,NormalGC
,
276 0,0,mysizehints
.width
,mysizehints
.height
,0,0);