chiark / gitweb /
wip finalise
[chiark-utils.git] / cprogs / xacpi-simple.c
index 2a392b5f679ecf40ebe61fd85939ee4f2df4e70b..7324080353fb518ac1330b83d14e54133edb4f24 100644 (file)
@@ -485,6 +485,7 @@ static void initacquire(void) {
 static XrmDatabase xrm;
 static Display *disp;
 static int screen;
+static const char *parentwindow;
 
 static const char defaultresources[]=
 #define GC(g)
@@ -501,6 +502,9 @@ static const XrmOptionDescRec optiontable[]= {
   { S("-warningTime"),  S("*warningTime"),  XrmoptionSepArg },
   { S("-display"),      S("*display"),      XrmoptionSepArg },
   { S("-geometry"),     S("*geometry"),     XrmoptionSepArg },
+  { S("-into"),         S("*parentWindow"), XrmoptionSepArg },
+  { S("-iconic"),       S("*iconic"),       XrmoptionIsArg },
+  { S("-withdrawn"),    S("*withdrawn"),    XrmoptionIsArg },
 #define GC(g)
 #define C(c,u)                                                 \
   { S("-" #u "Color"),  S("*" #u "Color"),  XrmoptionSepArg }, \
@@ -527,9 +531,11 @@ static const char *getresource(const char *want) {
 }
 
 static int getresource_bool(const char *want, int def, int *cache) {
-  /* *cache should be initialised to -1 and will be set to !!value */
+  /* *cache should be initialised to -1 and will be set to !!value
+   * alternatively cache==0 is allowed */
+
+  if (cache && *cache >= 0) return *cache;
 
-  if (*cache >= 0) return *cache;
   const char *str= getresource(want);
   int result = def;
   if (str && str[0]) {
@@ -545,7 +551,9 @@ static int getresource_bool(const char *want, int def, int *cache) {
       }
     }
   }
-  return *cache= result;
+
+  if (cache) *cache= result;
+  return result;
 }
 
 static void more_resources(const char *str, const char *why) {
@@ -574,6 +582,8 @@ static void parseargs(int argc, char **argv) {
   const char *alarmlevel_string= getresource("alarmLevel");
   alarmlevel = alarmlevel_string ? atoi(alarmlevel_string) : 300;
 
+  parentwindow = getresource("parentWindow");
+
   disp= XOpenDisplay(getresource("display"));
   if (!disp) fail("could not open display");
 
@@ -742,7 +752,13 @@ static void initgraphics(int argc, char **argv) {
                 &width, &height,
                 &gravity);
 
-  win= XCreateSimpleWindow(disp,DefaultRootWindow(disp),
+  unsigned long parentwindowid;
+  if (parentwindow)
+    parentwindowid = strtoul(parentwindow,0,0);
+  else
+    parentwindowid = DefaultRootWindow(disp);
+
+  win= XCreateSimpleWindow(disp,parentwindowid,
                           pos_x,pos_y,width,height,0,0,0);
   cmap= DefaultColormap(disp,screen);
   
@@ -767,6 +783,10 @@ static void initgraphics(int argc, char **argv) {
 
   wm_hints->flags= InputHint;
   wm_hints->input= False;
+  wm_hints->initial_state=
+    (getresource_bool("withdrawn",0,0) ? WithdrawnState :
+     getresource_bool("iconic",0,0) ? IconicState
+     : NormalState);
 
   class_hint->res_name= program_name_silly;
   class_hint->res_class= program_name_silly;