From cc7cb82debabb98b6cca375f53fe29da7ae4fad4 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Thu, 16 May 2002 15:50:41 +0000 Subject: [PATCH] adding new X base classes which encapsulate all X server interation --- src/XAtom.cc | 334 ++++++++++++++++++++++++++++++++++++++++++++++++ src/XAtom.h | 227 ++++++++++++++++++++++++++++++++ src/XDisplay.cc | 89 +++++++++++++ src/XDisplay.h | 77 +++++++++++ src/XScreen.cc | 67 ++++++++++ src/XScreen.h | 56 ++++++++ 6 files changed, 850 insertions(+) create mode 100644 src/XAtom.cc create mode 100644 src/XAtom.h create mode 100644 src/XDisplay.cc create mode 100644 src/XDisplay.h create mode 100644 src/XScreen.cc create mode 100644 src/XScreen.h diff --git a/src/XAtom.cc b/src/XAtom.cc new file mode 100644 index 00000000..febb9dbc --- /dev/null +++ b/src/XAtom.cc @@ -0,0 +1,334 @@ +// XAtom.cc for Openbox +// Copyright (c) 2002 - 2002 Ben Jansens (xor at orodu.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +#include "XAtom.h" +#include "XDisplay.h" + +XAtom::XAtom(XDisplay *display) { + _display = display->_display; + + wm_colormap_windows = getAtom("WM_COLORMAP_WINDOWS"); + wm_protocols = getAtom("WM_PROTOCOLS"); + wm_state = getAtom("WM_STATE"); + wm_change_state = getAtom("WM_CHANGE_STATE"); + wm_delete_window = getAtom("WM_DELETE_WINDOW"); + wm_take_focus = getAtom("WM_TAKE_FOCUS") + motif_wm_hints = getAtom("_MOTIF_WM_HINTS"); + openbox_hints = getAtom("_BLACKBOX_HINTS"); + openbox_attributes = getAtom("_BLACKBOX_ATTRIBUTES"); + openbox_change_attributes = getAtom("_BLACKBOX_CHANGE_ATTRIBUTES"); + + openbox_structure_messages = getAtom("_BLACKBOX_STRUCTURE_MESSAGES"); + openbox_notify_startup = getAtom("_BLACKBOX_NOTIFY_STARTUP"); + openbox_notify_window_add = getAtom("_BLACKBOX_NOTIFY_WINDOW_ADD"); + openbox_notify_window_del = getAtom("_BLACKBOX_NOTIFY_WINDOW_DEL"); + openbox_notify_current_workspace = + getAtom("_BLACKBOX_NOTIFY_CURRENT_WORKSPACE"); + openbox_notify_workspace_count = getAtom("_BLACKBOX_NOTIFY_WORKSPACE_COUNT"); + openbox_notify_window_focus = getAtom("_BLACKBOX_NOTIFY_WINDOW_FOCUS"); + openbox_notify_window_raise = getAtom("_BLACKBOX_NOTIFY_WINDOW_RAISE"); + openbox_notify_window_lower = getAtom("_BLACKBOX_NOTIFY_WINDOW_LOWER"); + + openbox_change_workspace = getAtom("_BLACKBOX_CHANGE_WORKSPACE"); + openbox_change_window_focus = getAtom("_BLACKBOX_CHANGE_WINDOW_FOCUS"); + openbox_cycle_window_focus = getAtom("_BLACKBOX_CYCLE_WINDOW_FOCUS"); + + net_supported = getAtom("_NET_SUPPORTED"); + net_client_list = getAtom("_NET_CLIENT_LIST"); + net_client_list_stacking = getAtom("_NET_CLIENT_LIST_STACKING"); + net_number_of_desktops = getAtom("_NET_NUMBER_OF_DESKTOPS"); + net_desktop_geometry = getAtom("_NET_DESKTOP_GEOMETRY"); + net_desktop_viewport = getAtom("_NET_DESKTOP_VIEWPORT"); + net_current_desktop = getAtom("_NET_CURRENT_DESKTOP"); + net_desktop_names = getAtom("_NET_DESKTOP_NAMES"); + net_active_window = getAtom("_NET_ACTIVE_WINDOW"); + net_workarea = getAtom("_NET_WORKAREA"); + net_supporting_wm_check = getAtom("_NET_SUPPORTING_WM_CHECK"); + net_virtual_roots = getAtom("_NET_VIRTUAL_ROOTS"); + + net_close_window = getAtom("_NET_CLOSE_WINDOW"); + net_wm_moveresize = getAtom("_NET_WM_MOVERESIZE"); + + net_properties = getAtom("_NET_PROPERTIES"); + net_wm_name = getAtom("_NET_WM_NAME"); + net_wm_desktop = getAtom("_NET_WM_DESKTOP"); + net_wm_window_type = getAtom("_NET_WM_WINDOW_TYPE"); + net_wm_state = getAtom("_NET_WM_STATE"); + net_wm_strut = getAtom("_NET_WM_STRUT"); + net_wm_icon_geometry = getAtom("_NET_WM_ICON_GEOMETRY"); + net_wm_icon = getAtom("_NET_WM_ICON"); + net_wm_pid = getAtom("_NET_WM_PID"); + net_wm_handled_icons = getAtom("_NET_WM_HANDLED_ICONS"); + + net_wm_ping = getAtom("_NET_WM_PING"); + + for (int s = 0, c = display->screenCount(); s < c; ++s) + setSupported(display->screen(s)); +} + + +/* + * clean up the class' members + */ +XAtom::~XAtom() { + while (!_support_windows.empty()) { + Window w = _support_windows.pop_back(); + ASSERT(w != None); // make sure we aren't fucking with this somewhere + XDestroyWindow(_display, w); + } +} + + +/* + * Returns an atom from the Xserver, creating it if necessary. + */ +Atom XAtom::getAtom(const char *name) const { + return XInternAtom(_display, name, False); +} + + +/* + * Sets which atoms are supported for NETWM, by Openbox, on the root window. + */ +void XAtom::setSupported(const XScreen *screen) { + // create the netwm support window + Window w = XCreateSimpleWindow(_display, screen->rootWindow(), + 0, 0, 1, 1, 0, 0, 0) + ASSERT(w != None); + _support_windows.push_back(w); + + // we don't support any yet.. +} + + +/* + * Internal setValue used by all typed setValue functions. + * Sets a window property on a window, optionally appending to the existing + * value. + */ +void XAtom::setValue(Window win, Atom atom, Atom type, unsigned char* data, + int size, int nelements, bool append) { + ASSERT(win != None); ASSERT(atom != None); ASSERT(type != None); + ASSERT(data != (unsigned char *) 0); + ASSERT(size == 8 || size == 16 || size == 32); + ASSERT(nelements > 0); + XChangeProperty(_display, win, atom, type, size, + (append ? PropModeAppend : PropModeReplace), + data, nelements); +} + + +/* + * Set a 32-bit CARDINAL property value on a window. + */ +void XAtom::setValue(Window win, Atom atom, long value) const { + setValue(win, atom, XA_CARDINAL, static_cast(&value), + sizeof(long), 1, false); +} + + +/* + * Set an Atom property value on a window. + */ +void XAtom::setValue(Window win, Atom atom, Atom value) { + setValue(win, atom, XA_ATOM, static_cast(&value), + sizeof(Atom), 1, false); +} + + +/* + * Set a Window property value on a window. + */ +void XAtom::setValue(Window win, Atom atom, Window value) { + setValue(win, atom, XA_WINDOW, static_cast(&value), + sizeof(Window), 1, false); +} + + +/* + * Set a Pixmap property value on a window. + */ +void XAtom::setValue(Window win, Atom atom, Pixmap value) { + setValue(win, atom, XA_PIXMAP, static_cast(&value), + sizeof(Pixmap), 1, false); +} + + +/* + * Set a string property value on a window. + */ +void XAtom::setValue(Window win, Atom atom, std::string &value) { + setValue(win, atom, XA_STRING, static_cast(value.c_str()), + 8, value.size(), false); +} + + +/* + * Add elements to a 32-bit CARDINAL property value on a window. + */ +void XAtom::addValue(Window win, Atom atom, long value) const { + setValue(win, atom, XA_CARDINAL, static_cast(&value), + sizeof(long), 1, true); +} + + +/* + * Add elements to an Atom property value on a window. + */ +void XAtom::addValue(Window win, Atom atom, Atom value) const { + setValue(win, atom, XA_ATOM, static_cast(&value), + sizeof(Atom), 1, true); +} + + +/* + * Add elements to a Window property value on a window. + */ +void XAtom::addValue(Window win, Atom atom, Window value) const { + setValue(win, atom, XA_WINDOW, static_cast(&value), + sizeof(Window), 1, true); +} + + +/* + * Add elements to a Pixmap property value on a window. + */ +void XAtom::addValue(Window win, Atom atom, Pixmap value) const { + setValue(win, atom, XA_PIXMAP, static_cast(&value), + sizeof(Pixmap), 1, true); +} + + +/* + * Add characters to a string property value on a window. + */ +void XAtom::addValue(Window win, Atom atom, std::string &value) const { + setValue(win, atom, XA_STRING, static_cast(value.c_str()), + 8, value.size(), true); +} + + +/* + * 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 + * property did not exist on the window, or has a different type/size format + * than the user tried to retrieve. + */ +bool XAtom::getValue(Window win, Atom atom, Atom type, unsigned long *nelements, + unsigned char **value, int size) const { + unsigned char *c_val; // value alloc'd with c malloc + Atom ret_type; + int ret_size; + unsigned long ret_bytes; + XGetWindowProperty(_display, win, atom, 0l, 1l, False, AnyPropertyType, + &ret_type, &ret_size, nelements, &ret_bytes, + &c_val); // try get the first element + if (ret_type == None) + // the property does not exist on the window + return false; + if (ret_type != type || ret_size != size) { + // wrong data in property + XFree(c_val); + return false; + } + // the data is correct, now, is there more than 1 element? + if (ret_bytes == 0) { + // we got the whole property's value + *value = new unsigned char[*nelements * size/8 + 1]; + memcpy(*value, c_val, *nelements * size/8 + 1); + XFree(c_val); + return true; + } + // get the entire property since it is larger than one long + free(c_val); + // the number of longs that need to be retreived to get the property's entire + // value. The last + 1 is the first long that we retrieved above. + const int remain = (ret_bytes - 1)/sizeof(long) + 1 + 1; + XGetWindowProperty(_display, win, atom, 0l, remain, False, type, &ret_type, + &ret_size, nelements, &ret_bytes, &c_val); + 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; +} + + +/* + * Gets a 32-bit Cardinal property's value from a window. + */ +bool XAtom::getValue(Window win, Atom atom, unsigned long *nelements, + long **value) const { + return XAtom::getValue(win, atom, XA_CARDINAL, nelements, + static_cast(value), sizeof(long)); +} + + +/* + * Gets an Atom property's value from a window. + */ +bool XAtom::getValue(Window win, Atom atom, unsigned long *nelements, + Atom **value) const { + return XAtom::getValue(win, atom, XA_ATOM, nelements, + static_cast(value), sizeof(Atom)); +} + + +/* + * Gets an Window property's value from a window. + */ +bool XAtom::getValue(Window win, Atom atom, unsigned long *nelements, + Window **value) const { + return XAtom::getValue(win, atom, XA_WINDOW, nelements, + static_cast(value), sizeof(Window)); +} + + +/* + * Gets an Pixmap property's value from a window. + */ +bool XAtom::getValue(Window win, Atom atom, unsigned long *nelements, + Pixmap **value) const { + return XAtom::getValue(win, atom, XA_PIXMAP, nelements, + static_cast(value), sizeof(Pixmap)); +} + + +/* + * Gets an string property's value from a window. + */ +bool XAtom::getValue(Window win, Atom atom, unsigned long *nelements, + std::string &value) const { + unsigned char *data; + bool ret = XAtom::getValue(win, atom, XA_STRING, nelements, &data, 8); + if (ret) + value = data; + return ret; +} + + +/* + * Removes a property entirely from a window. + */ +void XAtom::eraseValue(Window win, Atom atom) const { + XDeleteProperty(_display, win, atom); +} diff --git a/src/XAtom.h b/src/XAtom.h new file mode 100644 index 00000000..92291f69 --- /dev/null +++ b/src/XAtom.h @@ -0,0 +1,227 @@ +// XAtom.h for Openbox +// Copyright (c) 2002 - 2002 Ben Janens (ben at orodu.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +#ifndef __XAtom_h +#define __XAtom_h + +#include +#include +#include + +class XDisplay; + +class XAtom { + typedef std::vector SupportWindows; + + Display *_display; + // windows used to specify support for NETWM + SupportWindows _support_windows; + + Atom + // window hints + wm_colormap_windows, + wm_protocols, + wm_state, + wm_delete_window, + wm_take_focus, + wm_change_state, + motif_wm_hints, + openbox_attributes, + openbox_change_attributes, + openbox_hints; + + // blackbox-protocol atoms (wm -> client) + openbox_structure_messages, + openbox_notify_startup, + openbox_notify_window_add, + openbox_notify_window_del, + openbox_notify_window_focus, + openbox_notify_current_workspace, + openbox_notify_workspace_count, + openbox_notify_window_raise, + openbox_notify_window_lower; + // blackbox-protocol atoms (client -> wm) + openbox_change_workspace, + openbox_change_window_focus, + openbox_cycle_window_focus, + + // NETWM atoms + // root window properties + net_supported, + net_client_list, + net_client_list_stacking, + net_number_of_desktops, + net_desktop_geometry, + net_desktop_viewport, + net_current_desktop, + net_desktop_names, + net_active_window, + net_workarea, + net_supporting_wm_check, + net_virtual_roots, + // root window messages + net_close_window, + net_wm_moveresize, + // application window properties + net_properties, + net_wm_name, + net_wm_desktop, + net_wm_window_type, + net_wm_state, + net_wm_strut, + net_wm_icon_geometry, + net_wm_icon, + net_wm_pid, + net_wm_handled_icons, + // application protocols + net_wm_ping; + + Atom getAtom(const char *name) const; + void setSupported(const XScreen *screen) const; + + void setValue(Window win, Atom atom, Atom type, unsigned char *data, int size, + int nelements, bool append); + bool getValue(Window win, Atom atom, Atom type, unsigned long *nelements, + unsigned char **value, int size) const; + + // no copying!! + XAtom(const XAtom &); + XAtom& operator=(const XAtom&); + +public: + XAtom(XDisplay *display); + virtual ~XAtom(); + + void setValue(Window win, Atom atom, long value) const; // a 32-bit CARDINAL + void setValue(Window win, Atom atom, Atom value) const; + void setValue(Window win, Atom atom, Window value) const; + void setValue(Window win, Atom atom, Pixmap value) const; + void setValue(Window win, Atom atom, std::string &value) const; + + void addValue(Window win, Atom atom, long value) const; // a 32-bit CARDINAL + void addValue(Window win, Atom atom, Atom value) const; + void addValue(Window win, Atom atom, Window value) const; + void addValue(Window win, Atom atom, Pixmap value) const; + void addValue(Window win, Atom atom, std::string &value) const; + + // the 'value' is allocated inside the function and + // delete [] value needs to be called when you are done with it. + // teh 'value' array returned is null terminated, and has 'nelements' + // elements in it plus the null. + bool getValue(Window win, Atom atom, unsigned long *nelements, + long **value) const; // a 32-bit CARDINAL + bool getValue(Window win, Atom atom, unsigned long *nelements, + Atom **value) const; + bool getValue(Window win, Atom atom, unsigned long *nelements, + Window **value) const; + bool getValue(Window win, Atom atom, unsigned long *nelements, + Pixmap **value) const; + bool getValue(Window win, Atom atom, unsigned long *nelements, + std::string &value) const; + + void eraseValue(Window win, Atom atom) const; + + inline Atom wmChangeState() const { return wm_change_state; } + inline Atom wmState() const { return wm_state; } + inline Atom wmDelete() const { return wm_delete_window; } + inline Atom wmProtocols() const { return wm_protocols; } + inline Atom wmTakeFocus() const { return wm_take_focus; } + inline Atom wmColormap() const { return wm_colormap_windows; } + inline Atom motifWMHints() const { return motif_wm_hints; } + + // this atom is for normal app->WM hints about decorations, stacking, + // starting workspace etc... + inline Atom openboxHints() const { return openbox_hints;} + + // these atoms are for normal app->WM interaction beyond the scope of the + // ICCCM... + inline Atom openboxAttributes() const { return openbox_attributes; } + inline Atom openboxChangeAttributes() const + { return openbox_change_attributes; } + + // these atoms are for window->WM interaction, with more control and + // information on window "structure"... common examples are + // notifying apps when windows are raised/lowered... when the user changes + // workspaces... i.e. "pager talk" + inline Atom openboxStructureMessages() const + { return openbox_structure_messages; } + + inline Atom openboxNotifyStartup() const + { return openbox_notify_startup; } + inline Atom openboxNotifyWindowAdd() const + { return openbox_notify_window_add; } + inline Atom openboxNotifyWindowDel() const + { return openbox_notify_window_del; } + inline Atom openboxNotifyWindowFocus() const + { return openbox_notify_window_focus; } + inline Atom openboxNotifyCurrentWorkspace() const + { return openbox_notify_current_workspace; } + inline Atom openboxNotifyWorkspaceCount() const + { return openbox_notify_workspace_count; } + inline Atom openboxNotifyWindowRaise() const + { return openbox_notify_window_raise; } + inline Atom openboxNotifyWindowLower() const + { return openbox_notify_window_lower; } + + // atoms to change that request changes to the desktop environment during + // runtime... these messages can be sent by any client... as the sending + // client window id is not included in the ClientMessage event... + inline Atom openboxChangeWorkspace() const + { return openbox_change_workspace; } + inline Atom openboxChangeWindowFocus() const + { return openbox_change_window_focus; } + inline Atom openboxCycleWindowFocus() const + { return openbox_cycle_window_focus; } + + // root window properties + inline Atom netClientList() const { return net_client_list; } + inline Atom netClientListStacking() const { return net_client_list_stacking; } + inline Atom netNumberOfDesktops() const { return net_number_of_desktops; } + inline Atom netDesktopGeometry() const { return net_desktop_geometry; } + inline Atom netDesktopViewport() const { return net_desktop_viewport; } + inline Atom netCurrentDesktop() const { return net_current_desktop; } + inline Atom netDesktopNames() const { return net_desktop_names; } + inline Atom netActiveWindow() const { return net_active_window; } + inline Atom netWorkarea() const { return net_workarea; } + inline Atom netSupportingWMCheck() const { return net_supporting_wm_check; } + inline Atom netVirtualRoots() const { return net_virtual_roots; } + + // root window messages + inline Atom netCloseWindow() const { return net_close_window; } + inline Atom netWMMoveResize() const { return net_wm_moveresize; } + + // application window properties + inline Atom netProperties() const { return net_properties; } + inline Atom netWMName() const { return net_wm_name; } + inline Atom netWMDesktop() const { return net_wm_desktop; } + inline Atom netWMWindowType() const { return net_wm_window_type; } + inline Atom netWMState() const { return net_wm_state; } + inline Atom netWMStrut() const { return net_wm_strut; } + inline Atom netWMIconGeometry() const { return net_wm_icon_geometry; } + inline Atom netWMIcon() const { return net_wm_icon; } + inline Atom netWMPid() const { return net_wm_pid; } + inline Atom netWMHandledIcons() const { return net_wm_handled_icons; } + + // application protocols + inline Atom netWMPing() const { return net_wm_ping; } +}; + +#endif // __XAtom_h diff --git a/src/XDisplay.cc b/src/XDisplay.cc new file mode 100644 index 00000000..48f19d76 --- /dev/null +++ b/src/XDisplay.cc @@ -0,0 +1,89 @@ +// XDisplay.cc for Openbox +// Copyright (c) 2002 - 2002 Ben Janens (ben at orodu.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +#include "Xdisplay.h" +#include "XScreen.h" +#include "Util.h" +#include +#include + +using std::cerr; + +Xdisplay::Xdisplay(const char *dpyname) { + _grabs = 0; + _hasshape = false; + + _display = XOpenDisplay(dpy_name); + if (_display == NULL) { + cerr << "Could not open display. Connection to X server failed.\n"; + ::exit(2); + } + if (-1 == fcntl(ConnectionNumber(display), F_SETFD, 1)) { + cerr << "Could not mark display connection as close-on-exec.\n"; + ::exit(2); + } + _name = XDisplayName(dpyname); + + XSetErrorHandler(XErrorHandler); + +#ifdef SHAPE + int waste; + _hasshape = XShapeQueryExtension(_display, &_shape_event_base, &waste); +#endif // SHAPE + + const unsigned int scount = ScreenCount(_display); + _screens.reserve(scount); + for (unsigned int s = 0; s < scount; s++) + _screens.push_back(new XScreen(_display, s)); +} + + +Xdisplay::~Xdisplay() { + std::for_each(_screens.begin(), _screens.end(), PointerAssassin()); + XCloseDisplay(_display); +} + + +/* + * Return information about a screen. + */ +XScreen *Xdisplay::screen(unsigned int s) const { + ASSERT(s < _screens.size()); + return _screens[s]; +} + + +/* + * Grab the X server + */ +void XDisplay::grab() { + if (_grabs++ == 0) + XGrabServer(_display); +} + + +/* + * Release the X server from a grab + */ +void XDisplay::ungrab() { + if (--_grabs == 0) + XUngrabServer(_display); +} diff --git a/src/XDisplay.h b/src/XDisplay.h new file mode 100644 index 00000000..b65d94c6 --- /dev/null +++ b/src/XDisplay.h @@ -0,0 +1,77 @@ +// XDisplay.h for Openbox +// Copyright (c) 2002 - 2002 Ben Janens (ben at orodu.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +#ifndef __XDisplay_h +#define __XDisplay_h + +#include +#include +#include + +class Xdisplay { + friend XAtom::XAtom(); + //friend class XAtom; + +private: + Display *_display; + std::string _name; + unsigned int _grabs; + bool _hasshape; + int _shape_event_base; + + typedef std::vector XScreenList; + XScreenList _screens; + + int XErrorHandler(Display *d, XErrorEvent *e); + + // no copying!! + XDisplay(const XDisplay &); + XDisplay& operator=(const XDisplay&); + +protected: + virtual void process_event(XEvent *) = 0; + +public: + Xdisplay(const char *dpyname = 0); + virtual ~Xdisplay(); + + XScreen *screen(unsigned int s) const; + inline unsigned int screenCount() const { return _screens.size(); } + + inline bool hasShape() const { return _hasshape; } + inline int shapeEventBase() const { return shape.event_basep; } + + //inline Display *display() const { return _display; } + + inline std::string name() const { return name; } + + // these belong in Xwindow + //const bool validateWindow(Window); + //void grabButton(unsigned int, unsigned int, Window, Bool, unsigned int, int, + // int, Window, Cursor) const; + //void ungrabButton(unsigned int button, unsigned int modifiers, + // Window grab_window) const; + + void grab(); + void ungrab(); +}; + +#endif // _XDisplay_h diff --git a/src/XScreen.cc b/src/XScreen.cc new file mode 100644 index 00000000..dbc48705 --- /dev/null +++ b/src/XScreen.cc @@ -0,0 +1,67 @@ +// XScreen.cc for Openbox +// Copyright (c) 2002 - 2002 Ben Janens (ben at orodu.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +#include "XScreen.h" +#include "Geometry.h" + +XScreen::XScreen(const Display *display, const unsigned int number) { + _display = display; + _number = number; + + _root = RootWindow(_display, _number); + _size = Size(WidthOfScreen(ScreenOfDisplay(_display, _number)), + HeightOfScreen(ScreenOfDisplay(_display, _number))); + setColorData(); +} + + +/* + * This sets up the _depth, _visual, and _colormap properties. + */ +void XScreen::setColorData() { + _depth = DefaultDepth(_display, _number); + _visual = (Visual *) 0; + + // search for a TrueColor Visual. If we can't find one, use the default + // visual for the screen + XVisualInfo vinfo_template, *vinfo_return; + int vinfo_nitems; + + vinfo_template.screen = _number; + vinfo_template.c_class = TrueColor; + + vinfo_return = XGetVisualInfo(_display, VisualScreenMask | VisualClassMask, + &vinfo_template, &vinfo_nitems); + if (vinfo_return && vinfo_nitems > 0) { + for (int i = 0; i < vinfo_nitems; i++) + if (_depth < (vinfo_return + i)->depth) { + _depth = (vinfo_return + i)->depth; + _visual = (vinfo_return + i)->visual; + } + XFree(vinfo_return); + } + if (visual) + _colormap = XCreateColormap(_display, _root, _visual, AllocNone); + else { + _visual = DefaultVisual(_display, _number); + _colormap = DefaultColormap(_display, _number); + } +} diff --git a/src/XScreen.h b/src/XScreen.h new file mode 100644 index 00000000..8626d9d7 --- /dev/null +++ b/src/XScreen.h @@ -0,0 +1,56 @@ +// XScreen.h for Openbox +// Copyright (c) 2002 - 2002 Ben Janens (ben at orodu.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +#ifndef __XScreen_h +#define __XScreen_h + +#include + +class Size; + +class XScreen { +private: + Display *_display; + unsigned int _number; + Visual *_visual; + Window _root; + Colormap _colormap; + unsigned int _depth; + Size _size; + + void setColorData(); + + // no copying!! + XScreen(const XScreen &); + XScreen& operator=(const XScreen&); + +public: + XScreen(const Display *display, const unsigned int number); + + inline Visual *visual() const { return _visual; } + inline Window rootWindow() const { return _root; } + inline Colormap colormap() const { return _colormap; } + inline unsigned int depth() const { return _depth; } + inline unsigned int number() const { return _number; } + inline const Size &size() const { return _size; } +}; + +#endif // __XScreen_h -- 2.45.2