]> icculus.org git repositories - mikachu/openbox.git/blob - src/XAtom.hh
no more menus, at last. woop
[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
28 #include <assert.h>
29
30 #include <vector>
31 #include <string>
32
33 class Blackbox;
34 class ScreenInfo;
35
36 class XAtom {
37 public:
38   enum Atoms {
39     // types
40     cardinal,
41     window,
42     pixmap,
43     atom,
44     string,
45     utf8_string,
46     
47 #ifdef    HAVE_GETPID
48     blackbox_pid,
49 #endif // HAVE_GETPID
50
51     // window hints
52     wm_colormap_windows,
53     wm_protocols,
54     wm_state,
55     wm_delete_window,
56     wm_take_focus,
57     wm_change_state,
58     wm_name,
59     wm_icon_name,
60     wm_class,
61     motif_wm_hints,
62     blackbox_attributes,
63     blackbox_change_attributes,
64     blackbox_hints,
65
66     // blackbox-protocol atoms (wm -> client)
67     blackbox_structure_messages,
68     blackbox_notify_startup,
69     blackbox_notify_window_add,
70     blackbox_notify_window_del,
71     blackbox_notify_window_focus,
72     blackbox_notify_current_workspace,
73     blackbox_notify_workspace_count,
74     blackbox_notify_window_raise,
75     blackbox_notify_window_lower,
76     // blackbox-protocol atoms (client -> wm)
77     blackbox_change_workspace,
78     blackbox_change_window_focus,
79     blackbox_cycle_window_focus,
80
81     openbox_show_root_menu,
82     openbox_show_workspace_menu,
83
84     // NETWM atoms
85     // root window properties
86     net_supported,
87     net_client_list,
88     net_client_list_stacking,
89     net_number_of_desktops,
90     net_desktop_geometry,
91     net_desktop_viewport,
92     net_current_desktop,
93     net_desktop_names,
94     net_active_window,
95     net_workarea,
96     net_supporting_wm_check,
97 //    net_virtual_roots,
98     // root window messages
99     net_close_window,
100     net_wm_moveresize,
101     // application window properties
102 //    net_properties,
103     net_wm_name,
104     net_wm_visible_name,
105     net_wm_icon_name,
106     net_wm_visible_icon_name,
107     net_wm_desktop,
108     net_wm_window_type,
109     net_wm_state,
110     net_wm_strut,
111 //  net_wm_icon_geometry,
112 //  net_wm_icon,
113 //  net_wm_pid,
114 //  net_wm_handled_icons,
115     net_wm_allowed_actions,
116     // application protocols
117 //    net_wm_ping,
118
119     net_wm_window_type_desktop,
120     net_wm_window_type_dock,
121     net_wm_window_type_toolbar,
122     net_wm_window_type_menu,
123     net_wm_window_type_utility,
124     net_wm_window_type_splash,
125     net_wm_window_type_dialog,
126     net_wm_window_type_normal,
127
128     net_wm_moveresize_size_topleft,
129     net_wm_moveresize_size_topright,
130     net_wm_moveresize_size_bottomleft,
131     net_wm_moveresize_size_bottomright,
132     net_wm_moveresize_move,
133
134     net_wm_action_move,
135     net_wm_action_resize,
136     net_wm_action_shade,
137     net_wm_action_maximize_horz,
138     net_wm_action_maximize_vert,
139     net_wm_action_change_desktop,
140     net_wm_action_close,
141
142     net_wm_state_modal,
143     net_wm_state_maximized_vert,
144     net_wm_state_maximized_horz,
145     net_wm_state_shaded,
146     net_wm_state_skip_taskbar,
147     net_wm_state_skip_pager,
148     net_wm_state_hidden,
149     net_wm_state_fullscreen,
150
151     kde_net_system_tray_windows,
152     kde_net_wm_system_tray_window_for,
153     kde_net_wm_window_type_override,
154  
155     // constant for how many atoms exist in the enumerator
156     NUM_ATOMS
157   };
158
159   enum StringType {
160     ansi,
161     utf8,
162     NUM_STRING_TYPE
163   };
164
165 private:
166   typedef std::vector<Window> SupportWindows;
167   
168   Display              *_display;
169   // windows used to specify support for NETWM
170   SupportWindows        _support_windows;
171   Atom                  _atoms[NUM_ATOMS];
172
173   Atom create(const char *name) const;
174
175   void setValue(Window win, Atom atom, Atom type, unsigned char *data,
176                 int size, int nelements, bool append) const;
177   bool getValue(Window win, Atom atom, Atom type,
178                 unsigned long &nelements, unsigned char **value,
179                 int size) const;
180
181   // no copying!!
182   XAtom(const XAtom &);
183   XAtom& operator=(const XAtom&);
184
185 public:
186   typedef std::vector<std::string> StringVect;
187   
188   XAtom(Display *d);
189   virtual ~XAtom();
190
191   // setup support on a screen, each screen should call this once in its
192   // constructor.
193   void setSupported(const ScreenInfo *screen);
194   
195   void setValue(Window win, Atoms atom, Atoms type, unsigned long value) const;
196   void setValue(Window win, Atoms atom, Atoms type,
197                 unsigned long value[], int elements) const;
198   void setValue(Window win, Atoms atom, StringType type,
199                 const std::string &value) const;
200   void setValue(Window win, Atoms atom, StringType type,
201                 const StringVect &strings) const;
202
203   // the 'value' is allocated inside the function and
204   // delete [] value needs to be called when you are done with it.
205   // the 'value' array returned is null terminated, and has 'nelements'
206   // elements in it plus the null.
207   // nelements must be set to the maximum number of elements to read from
208   // the property.
209   bool getValue(Window win, Atoms atom, Atoms type,
210                 unsigned long &nelements, unsigned long **value) const;
211   bool getValue(Window win, Atoms atom, Atoms type, unsigned long &value) const;
212   bool getValue(Window win, Atoms atom, StringType type,
213                 std::string &value) const;
214   bool getValue(Window win, Atoms atom, StringType type,
215                 unsigned long &nelements, StringVect &strings) const;
216   
217   void eraseValue(Window win, Atoms atom) const;
218
219   // sends a client message a window
220   void sendClientMessage(Window target, Atoms type, Window about,
221                          long data = 0, long data1 = 0, long data2 = 0,
222                          long data3 = 0, long data4 = 0) const;
223
224   // temporary function!! remove when not used in blackbox.hh anymore!!
225   inline Atom getAtom(Atoms a)
226   { assert(a >= 0 && a < NUM_ATOMS); Atom ret = _atoms[a];
227     assert(ret != 0); return ret; }
228 };
229
230 #endif // __XAtom_h