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