1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // -- Netclient.h --
3 // Copyright (c) 2001 - 2003 Jason 'vanRijn' Kasper <vR at movingparts dot net>
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22 
23 // E_O_H_VR
24 
25 #ifndef  NETCLIENT_HH
26 #define  NETCLIENT_HH
27 
28 extern "C" {
29 #include <X11/Xlib.h>
30 #include <X11/Xatom.h>
31 }
32 
33 #include <assert.h>
34 
35 #include <vector>
36 #include <string>
37 #include <algorithm>
38 
39 // blackbox lib
40 #include <EWMH.hh>
41 
42 class Netclient : public bt::EWMH
43 {
44 
45 private:
46   const bt::Display &_display;
47 
48   Atom xa_wm_colormap_windows, xa_wm_protocols, xa_wm_state,
49     xa_wm_delete_window, xa_wm_take_focus, xa_wm_change_state,
50     motif_wm_hints, xa_wm_name, xa_wm_class;
51 
52   Atom openbox_show_root_menu, openbox_show_workspace_menu;
53 
54   Atom blackbox_attributes, blackbox_change_attributes, blackbox_hints;
55 
56   Atom enlightenment_desktop, net_virtual_roots;
57 
58   bool getValue(Window win, Atom atom, Atom type,
59                 unsigned long &nelements, unsigned char **value,
60                 int size) const;
61 
62   void init_icccm(void);
63   void init_extras(void);
64   void init_blackbox(void);
65 
66 public:
67 
68   Netclient (const bt::Display &display);
69   ~Netclient () ;
70 
71   // various value accessors...
72   std::string getWindowTitle(Window win) const;
73   unsigned int getDesktop(Window win) const;
74 
75   bool isAtomSupported(Window win, Atom atom) const;
76 
77   Window * getNetVirtualRootList(Window win);
78 
79 
80   // atoms EWMH doesn't provide
81 
82   // icccm first
xaWmColormapWindows(void)83   inline Atom xaWmColormapWindows(void) const {return xa_wm_colormap_windows;}
xaWmProtocols(void)84   inline Atom xaWmProtocols(void) const {return xa_wm_protocols;}
xaWmState(void)85   inline Atom xaWmState(void) const {return xa_wm_state;}
xaWmClass(void)86   inline Atom xaWmClass(void) const {return xa_wm_class;}
xaWmName(void)87   inline Atom xaWmName(void) const {return xa_wm_name;}
xaWmDeleteWindow(void)88   inline Atom xaWmDeleteWindow(void) const {return xa_wm_delete_window;}
xaWmTakeFocus(void)89   inline Atom xaWmTakeFocus(void) const {return xa_wm_take_focus;}
xaWmChangeState(void)90   inline Atom xaWmChangeState(void) const {return xa_wm_change_state;}
xaMotifWmHints(void)91   inline Atom xaMotifWmHints(void) const {return motif_wm_hints;}
92 
93   // extra goodies next
xaOpenboxShowRootMenu(void)94   inline Atom xaOpenboxShowRootMenu(void) const {return openbox_show_root_menu;}
xaOpenboxShowWorkspaceMenu(void)95   inline Atom xaOpenboxShowWorkspaceMenu(void) const
96     {return openbox_show_workspace_menu;}
97 
98   // old blackbox atoms
xaBlackboxAttributes(void)99   inline Atom xaBlackboxAttributes(void) const {return blackbox_attributes;}
xaBlackboxChangeAttributes(void)100   inline Atom xaBlackboxChangeAttributes(void) const {return blackbox_change_attributes;}
xaBlackboxHints(void)101   inline Atom xaBlackboxHints(void) const {return blackbox_hints;}
102 
103   // other things we might have to deal with
xaEnlightenmentDesktop(void)104   inline Atom xaEnlightenmentDesktop(void) const {return enlightenment_desktop;}
xaNetVirtualRoots(void)105   inline Atom xaNetVirtualRoots(void) const {return net_virtual_roots;}
106 
107   enum StringType {
108     ansi,
109     utf8,
110     NUM_STRING_TYPE
111   };
112 
113   typedef std::vector<std::string> StringVect;
114 
115   bool getValue(Window win, Atom atom, Atom type,
116                 unsigned long &nelements, unsigned long **value) const;
117   bool getValue(Window win, Atom atom, Atom type, unsigned long &value) const;
118   bool getValue(Window win, Atom atom, StringType type,
119                 std::string &value) const;
120   bool getValue(Window win, Atom atom, StringType type,
121                 unsigned long &nelements, StringVect &strings) const;
122 
123   void eraseValue(Window win, Atom atom) const;
124 
125   // sends a client message a window
126   void sendClientMessage(Window target, Atom type, Window about,
127                          long data = 0, long data1 = 0, long data2 = 0,
128                          long data3 = 0, long data4 = 0) const;
129 
130 
131 };
132 #endif
133