chiark / gitweb /
tries to set geometry but only works for size it seems
authorianmdlvl <ianmdlvl>
Sun, 12 Dec 2004 03:18:25 +0000 (03:18 +0000)
committerianmdlvl <ianmdlvl>
Sun, 12 Dec 2004 03:18:25 +0000 (03:18 +0000)
cprogs/xacpi-simple.c

index 671ad6a..157ed59 100644 (file)
@@ -36,6 +36,8 @@
 
 #define TIMEOUT 5000 /* milliseconds */
 
+static const char program_name[]= "xacpi-simple";
+
 /*---------- general utility stuff and declarations ----------*/
 
 static void fail(const char *m) {
@@ -202,10 +204,6 @@ static int readbattery(void) { /* 0=>ok, -1=>couldn't */
     batfile= 0;
   }
 
-  r= chdir("..");
-  if (r) return batfaile("chdir","..");
-  batdirname= 0;
-
   if (!(thisbat_alarm_present==0 ||
        thisbat_info_present==0 ||
        thisbat_state_present==0)) {
@@ -224,6 +222,10 @@ static int readbattery(void) { /* 0=>ok, -1=>couldn't */
     if (missing) return -1;
   }
 
+  r= chdir("..");
+  if (r) return batfaile("chdir","..");
+  batdirname= 0;
+
   return 0;
 }   
 
@@ -435,15 +437,40 @@ static void colour(unsigned long *pix_r, const char *name) {
   *pix_r= xc.pixel;
 }
 
-static void initgraphics(void) {
+static void initgraphics(int argc, char **argv) {
   int r;
   XTextProperty tp;
-  const char *program_name= "xacpi-simple";
+  const char *geom_string;
+  XSizeHints *normal_hints;
+  XWMHints *wm_hints;
+  XClassHint *class_hint;
+  int pos_x, pos_y, gravity;
+  char *program_name_silly;
   
-  disp= XOpenDisplay(0); if (!disp) fail("could not open display");
+  program_name_silly= (char*)program_name;
+
+  disp= XOpenDisplay(0);
+  if (!disp) fail("could not open display");
 
   screen= DefaultScreen(disp);
-  win= XCreateSimpleWindow(disp,DefaultRootWindow(disp),0,0,100,20,0,0,0);
+
+  normal_hints= XAllocSizeHints();
+  wm_hints= XAllocWMHints();
+  class_hint= XAllocClassHint();
+
+  if (!normal_hints || !wm_hints || !class_hint)
+    fail("could not alloc hint(s)");
+
+  geom_string= argc>=2 ? argv[1] : 0;
+
+  r= XWMGeometry(disp,screen, geom_string,"128x32", 0,
+                normal_hints,
+                &pos_x, &pos_y,
+                &width, &height,
+                &gravity);
+
+  win= XCreateSimpleWindow(disp,DefaultRootWindow(disp),
+                          pos_x,pos_y,width,height,0,0,0);
   cmap= DefaultColormap(disp,screen);
   
 #define C(c) colour(&pix_##c, #c);
@@ -456,10 +483,21 @@ static void initgraphics(void) {
   if (!r) fail("init set background");
   lastbackground= pix_dimgrey;
 
-  r= XStringListToTextProperty((char**)&program_name, 1, &tp);
-  if (!r) fail("XStringListtoTextProperty");
-  XSetWMName(disp,win,&tp);
-  
+  normal_hints->flags= PWinGravity;
+  normal_hints->win_gravity= gravity;
+
+  wm_hints->flags= InputHint;
+  wm_hints->input= False;
+
+  class_hint->res_name= program_name_silly;
+  class_hint->res_class= program_name_silly;
+
+  /*r= XStringListToTextProperty(&program_name_silly, 1, &tp);
+    if (!r) fail("XStringListtoTextProperty");*/
+
+  XmbSetWMProperties(disp,win, program_name,program_name,
+                    argv,argc, normal_hints, wm_hints, class_hint);
+
   XSelectInput(disp,win, ExposureMask|StructureNotifyMask);
   XMapWindow(disp,win);
 }
@@ -505,12 +543,12 @@ static void eventloop(void) {
   }
 }
 
-int main(int argc, const char *const *argv) {
-  if (!argv[0] || argv[1])
+int main(int argc, char **argv) {
+  if (argc<1 || argc>2)
     badusage();
 
   initacquire();
-  initgraphics();
+  initgraphics(argc,argv);
   eventloop();
   return 0;
 }