]> Dogcows Code - chaz/openbox/blobdiff - src/XAtom.cc
Added missing header for clearShape, which was breaking compilation
[chaz/openbox] / src / XAtom.cc
index 545739ab0390f5cbb659180717ff2c7ebbe14ab9..27912abdeee02145bfedcdee907410695862d415 100644 (file)
@@ -52,6 +52,7 @@ XAtom::XAtom(Display *d) {
   _atoms[wm_take_focus] = create("WM_TAKE_FOCUS");
   _atoms[wm_name] = create("WM_NAME");
   _atoms[wm_icon_name] = create("WM_ICON_NAME");
+  _atoms[wm_class] = create("WM_CLASS");
   _atoms[motif_wm_hints] = create("_MOTIF_WM_HINTS");
   _atoms[blackbox_hints] = create("_BLACKBOX_HINTS");
   _atoms[blackbox_attributes] = create("_BLACKBOX_ATTRIBUTES");
@@ -76,6 +77,9 @@ XAtom::XAtom(Display *d) {
     create("_BLACKBOX_CHANGE_WINDOW_FOCUS");
   _atoms[blackbox_cycle_window_focus] = create("_BLACKBOX_CYCLE_WINDOW_FOCUS");
 
+  _atoms[openbox_show_root_menu] = create("_OPENBOX_SHOW_ROOT_MENU");
+  _atoms[openbox_show_workspace_menu] = create("_OPENBOX_SHOW_WORKSPACE_MENU");
+
   _atoms[net_supported] = create("_NET_SUPPORTED");
   _atoms[net_client_list] = create("_NET_CLIENT_LIST");
   _atoms[net_client_list_stacking] = create("_NET_CLIENT_LIST_STACKING");
@@ -150,6 +154,8 @@ XAtom::XAtom(Display *d) {
   _atoms[kde_net_system_tray_windows] = create("_KDE_NET_SYSTEM_TRAY_WINDOWS");
   _atoms[kde_net_wm_system_tray_window_for] =
     create("_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR");
+  _atoms[kde_net_wm_window_type_override] =
+    create("_KDE_NET_WM_WINDOW_TYPE_OVERRIDE");
 }
 
 
@@ -276,7 +282,7 @@ void XAtom::setValue(Window win, Atoms atom, Atoms type,
   assert(atom >= 0 && atom < NUM_ATOMS);
   assert(type >= 0 && type < NUM_ATOMS);
   setValue(win, _atoms[atom], _atoms[type],
-           reinterpret_cast<unsigned char*>(&value), 32, 1, false);
+           reinterpret_cast<unsigned char*>(&value), 32, 1, False);
 }
 
 
@@ -288,7 +294,7 @@ void XAtom::setValue(Window win, Atoms atom, Atoms type,
   assert(atom >= 0 && atom < NUM_ATOMS);
   assert(type >= 0 && type < NUM_ATOMS);
   setValue(win, _atoms[atom], _atoms[type],
-           reinterpret_cast<unsigned char*>(value), 32, elements, false);
+           reinterpret_cast<unsigned char*>(value), 32, elements, False);
 }
 
 
@@ -304,11 +310,11 @@ void XAtom::setValue(Window win, Atoms atom, StringType type,
   switch (type) {
   case ansi: t = _atoms[string]; break;
   case utf8: t = _atoms[utf8_string]; break;
-  default: assert(false); // unhandled StringType
+  default: assert(False); return; // unhandled StringType
   }
   setValue(win, _atoms[atom], t,
            reinterpret_cast<unsigned char *>(const_cast<char *>(value.c_str())),
-           8, value.size() + 1, false); // add 1 to the size to include the null
+           8, value.size() + 1, False); // add 1 to the size to include the null
 }
 
 
@@ -324,7 +330,7 @@ void XAtom::setValue(Window win, Atoms atom, StringType type,
   switch (type) {
   case ansi: t = _atoms[string]; break;
   case utf8: t = _atoms[utf8_string]; break;
-  default: assert(false); // unhandled StringType
+  default: assert(False); return; // unhandled StringType
   }
 
   std::string value;
@@ -336,14 +342,14 @@ void XAtom::setValue(Window win, Atoms atom, StringType type,
 
   setValue(win, _atoms[atom], t,
            reinterpret_cast<unsigned char *>(const_cast<char *>(value.c_str())),
-           8, value.size(), false);
+           8, value.size(), False);
 }
 
 
 /*
  * Internal getValue function used by all of the typed getValue functions.
  * Gets an property's value from a window.
- * Returns true if the property was successfully retrieved; false if the
+ * Returns True if the property was successfully retrieved; False if the
  * property did not exist on the window, or has a different type/size format
  * than the user tried to retrieve.
  */
@@ -353,21 +359,22 @@ bool XAtom::getValue(Window win, Atom atom, Atom type,
   assert(win != None); assert(atom != None); assert(type != None);
   assert(size == 8 || size == 16 || size == 32);
   assert(nelements > 0);
-  unsigned char *c_val;        // value alloc'd with c malloc
+  unsigned char *c_val = 0;        // value alloc'd in Xlib, must be XFree()d
   Atom ret_type;
   int ret_size;
   unsigned long ret_bytes;
+  int result;
   const unsigned long maxread = nelements;
   // try get the first element
-  XGetWindowProperty(_display, win, atom, 0l, 1l, False, AnyPropertyType,
-                     &ret_type, &ret_size, &nelements, &ret_bytes, &c_val);
-  if (ret_type == None || nelements < 1)
-    // the property does not exist on the window or is empty
-    return false;
-  if (ret_type != type || ret_size != size) {
-    // wrong data in property
-    XFree(c_val);
-    return false;
+  result = XGetWindowProperty(_display, win, atom, 0l, 1l, False,
+                              AnyPropertyType, &ret_type, &ret_size,
+                              &nelements, &ret_bytes, &c_val);
+  if (result != Success || ret_type != type || ret_size != size ||
+      nelements < 1) {
+    // an error occured, the property does not exist on the window, or is empty,
+    // or the wrong data is in property for the request
+    if (c_val) XFree(c_val);
+    return False;
   }
   // the data is correct, now, is there more elements left?
   if (ret_bytes == 0 || maxread <= nelements) {
@@ -375,7 +382,7 @@ bool XAtom::getValue(Window win, Atom atom, Atom type,
     *value = new unsigned char[nelements * size/8 + 1];
     memcpy(*value, c_val, nelements * size/8 + 1);
     XFree(c_val);
-    return true;    
+    return True;    
   }
   // get the entire property since it is larger than one long
   XFree(c_val);
@@ -384,13 +391,15 @@ bool XAtom::getValue(Window win, Atom atom, Atom type,
   int remain = (ret_bytes - 1)/sizeof(long) + 1 + 1;
   if (remain > size/8 * (signed)maxread) // dont get more than the max
     remain = size/8 * (signed)maxread;
-  XGetWindowProperty(_display, win, atom, 0l, remain, False, type, &ret_type,
-                     &ret_size, &nelements, &ret_bytes, &c_val);
+  result = XGetWindowProperty(_display, win, atom, 0l, remain, False, type,
+                              &ret_type, &ret_size, &nelements, &ret_bytes,
+                              &c_val);
+  assert(result == Success);
   assert(ret_bytes == 0);
   *value = new unsigned char[nelements * size/8 + 1];
   memcpy(*value, c_val, nelements * size/8 + 1);
   XFree(c_val);
-  return true;    
+  return True;    
 }
 
 
@@ -418,10 +427,10 @@ bool XAtom::getValue(Window win, Atoms atom, Atoms type,
   unsigned long num = 1;
   if (! getValue(win, _atoms[atom], _atoms[type], num,
                  reinterpret_cast<unsigned char **>(&temp), 32))
-    return false;
+    return False;
   value = temp[0];
   delete [] temp;
-  return true;
+  return True;
 }
 
 
@@ -430,18 +439,18 @@ bool XAtom::getValue(Window win, Atoms atom, Atoms type,
  */
 bool XAtom::getValue(Window win, Atoms atom, StringType type,
                      std::string &value) const {
-  int n = 1;
+  unsigned long n = 1;
   StringVect s;
   if (getValue(win, atom, type, n, s)) {
     value = s[0];
-    return true;
+    return True;
   }
-  return false;
+  return False;
 }
 
 
-bool XAtom::getValue(Window win, Atoms atom, StringType type, int &nelements,
-                     StringVect &strings) const {
+bool XAtom::getValue(Window win, Atoms atom, StringType type,
+                     unsigned long &nelements, StringVect &strings) const {
   assert(atom >= 0 && atom < NUM_ATOMS);
   assert(type >= 0 && type < NUM_STRING_TYPE);
   assert(win != None); assert(_atoms[atom] != None);
@@ -451,32 +460,32 @@ bool XAtom::getValue(Window win, Atoms atom, StringType type, int &nelements,
   switch (type) {
   case ansi: t = _atoms[string]; break;
   case utf8: t = _atoms[utf8_string]; break;
-  default: assert(false); // unhandled StringType
+  default: assert(False); return False; // unhandled StringType
   }
   
   unsigned char *value;
   unsigned long elements = (unsigned) -1;
   if (!getValue(win, _atoms[atom], t, elements, &value, 8) || elements < 1)
-    return false;
+    return False;
 
-  std::string s(reinterpret_cast<char *>(value));
+  std::string s(reinterpret_cast<char *>(value), elements);
   delete [] value;
 
   std::string::const_iterator it = s.begin(), end = s.end();
-  int num = 0;
+  unsigned long num = 0;
   while(num < nelements) {
     std::string::const_iterator tmp = it; // current string.begin()
     it = std::find(tmp, end, '\0');       // look for null between tmp and end
     strings.push_back(std::string(tmp, it));   // s[tmp:it)
-    if (it == end)
-      break;
-    ++it;
     ++num;
+    if (it == end) break;
+    ++it;
+    if (it == end) break;
   }
 
-  nelements = elements;
+  nelements = num;
 
-  return true;
+  return True;
 }
 
 
@@ -487,3 +496,26 @@ void XAtom::eraseValue(Window win, Atoms atom) const {
   assert(atom >= 0 && atom < NUM_ATOMS);
   XDeleteProperty(_display, win, _atoms[atom]);
 }
+
+
+void XAtom::sendClientMessage(Window target, Atoms type, Window about,
+                              long data, long data1, long data2,
+                              long data3, long data4) const {
+  assert(atom >= 0 && atom < NUM_ATOMS);
+  assert(target != None);
+
+  XEvent e;
+  e.xclient.type = ClientMessage;
+  e.xclient.format = 32;
+  e.xclient.message_type = _atoms[type];
+  e.xclient.window = about;
+  e.xclient.data.l[0] = data;
+  e.xclient.data.l[1] = data1;
+  e.xclient.data.l[2] = data2;
+  e.xclient.data.l[3] = data3;
+  e.xclient.data.l[4] = data4;
+
+  XSendEvent(_display, target, False,
+             SubstructureRedirectMask | SubstructureNotifyMask,
+             &e);
+}
This page took 0.03266 seconds and 4 git commands to generate.