]> icculus.org git repositories - mikachu/openbox.git/blob - src/XAtom.hh
put webpage in the man page. Also, a couple fixes.
[mikachu/openbox.git] / src / XAtom.hh
1 // XAtom.h for Openbox
2 // Copyright (c) 2002 - 2002 Ben Janens (ben at orodu.net)
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22 #ifndef   __XAtom_h
23 #define   __XAtom_h
24
25 #include <X11/Xlib.h>
26 #include <X11/Xatom.h>
27 #include <vector>
28 #include <string>
29
30 class Blackbox;
31 class ScreenInfo;
32
33 class XAtom {
34 public:
35   enum AvailableAtoms {
36     // string type
37     utf8_string,
38     
39 #ifdef    HAVE_GETPID
40     blackbox_pid,
41 #endif // HAVE_GETPID
42
43     // window hints
44     wm_colormap_windows,
45     wm_protocols,
46     wm_state,
47     wm_delete_window,
48     wm_take_focus,
49     wm_change_state,
50     motif_wm_hints,
51     blackbox_attributes,
52     blackbox_change_attributes,
53     blackbox_hints,
54
55     // blackbox-protocol atoms (wm -> client)
56     blackbox_structure_messages,
57     blackbox_notify_startup,
58     blackbox_notify_window_add,
59     blackbox_notify_window_del,
60     blackbox_notify_window_focus,
61     blackbox_notify_current_workspace,
62     blackbox_notify_workspace_count,
63     blackbox_notify_window_raise,
64     blackbox_notify_window_lower,
65     // blackbox-protocol atoms (client -> wm)
66     blackbox_change_workspace,
67     blackbox_change_window_focus,
68     blackbox_cycle_window_focus,
69
70     // NETWM atoms
71     // root window properties
72     net_supported,
73     net_client_list,
74     net_client_list_stacking,
75     net_number_of_desktops,
76     net_desktop_geometry,
77     net_desktop_viewport,
78     net_current_desktop,
79     net_desktop_names,
80     net_active_window,
81     net_workarea,
82     net_supporting_wm_check,
83     net_virtual_roots,
84     // root window messages
85     net_close_window,
86     net_wm_moveresize,
87     // application window properties
88     net_properties,
89     net_wm_name,
90     net_wm_desktop,
91     net_wm_window_type,
92     net_wm_state,
93     net_wm_strut,
94     net_wm_icon_geometry,
95     net_wm_icon,
96     net_wm_pid,
97     net_wm_handled_icons,
98     // application protocols
99     net_wm_ping,
100
101     // constant for how many atoms exist in the enumerator
102     NUM_ATOMS
103   };
104
105   enum AtomType {
106     Type_Cardinal,
107     Type_Atom,
108     Type_Window,
109     Type_Pixmap
110   };
111
112   enum StringType {
113     Type_String,
114     Type_Utf8,
115   };
116
117 private:
118   typedef std::vector<Window> SupportWindows;
119   
120   Display              *_display;
121   // windows used to specify support for NETWM
122   SupportWindows        _support_windows;
123   Atom                  _atoms[NUM_ATOMS];
124
125   Atom create(const char *name) const;
126
127   void setValue(Window win, AvailableAtoms atom, Atom type, unsigned char *data,
128                 int size, int nelements, bool append) const;
129   bool getValue(Window win, AvailableAtoms atom, Atom type,
130                 unsigned long *nelements, unsigned char **value,
131                 int size) const;
132
133   // no copying!!
134   XAtom(const XAtom &);
135   XAtom& operator=(const XAtom&);
136
137 public:
138   XAtom(Blackbox *bb);
139   virtual ~XAtom();
140
141   // setup support on a screen, each screen should call this once in its
142   // constructor.
143   void setSupported(const ScreenInfo *screen);
144   
145   void setValue(Window win, AvailableAtoms atom, AtomType type,
146                 unsigned long value) const;
147   void setValue(Window win, AvailableAtoms atom, StringType type,
148                 const std::string &value) const;
149
150   void addValue(Window win, AvailableAtoms atom, AtomType type,
151                 unsigned long value) const;
152   void addValue(Window win, AvailableAtoms atom, StringType type,
153                 const std::string &value) const;
154
155   // the 'value' is allocated inside the function and
156   // delete [] value needs to be called when you are done with it.
157   // the 'value' array returned is null terminated, and has 'nelements'
158   // elements in it plus the null.
159   bool getValue(Window win, AvailableAtoms atom, AtomType type,
160                 unsigned long *nelements, unsigned long **value) const;
161   bool getValue(Window win, AvailableAtoms atom, StringType type,
162                 std::string &value) const;
163   
164   void eraseValue(Window win, AvailableAtoms atom) const;
165
166   // temporary function!! remove when not used in blackbox.hh anymore!!
167   inline Atom getAtom(AvailableAtoms a)
168   { Atom ret = _atoms[a]; assert(ret != 0); return ret; }
169 };
170
171 #endif // __XAtom_h