diff options
author | Peter Hutterer <peter@cs.unisa.edu.au> | 2007-03-20 12:50:45 +1030 |
---|---|---|
committer | Peter Hutterer <peter@cs.unisa.edu.au> | 2007-03-20 12:50:45 +1030 |
commit | 9b344863f39fa557fa55298566634e8f8428d65f (patch) | |
tree | 68967d39e26c50f5903b06e8d879fcc0432ee633 | |
parent | a1be07ff7602f80762258872d63ff6ffce775870 (diff) |
o Make dock buttons listen to device button presses.
o Pair devices on button press on a keyboard in the dock.
-rw-r--r-- | Changelog | 4 | ||||
-rw-r--r-- | src/Config.h | 2 | ||||
-rw-r--r-- | src/Dock.cpp | 104 | ||||
-rw-r--r-- | src/Dock.h | 4 | ||||
-rw-r--r-- | src/DockApp.cpp | 2 | ||||
-rw-r--r-- | src/DockApp.h | 4 | ||||
-rw-r--r-- | src/DockItem.h | 5 | ||||
-rw-r--r-- | src/DockKeyboard.cpp | 5 | ||||
-rw-r--r-- | src/DockKeyboard.h | 4 | ||||
-rw-r--r-- | src/DockProcess.cpp | 2 | ||||
-rw-r--r-- | src/DockProcess.h | 4 | ||||
-rw-r--r-- | src/KeyboardDevice.h | 1 | ||||
-rw-r--r-- | src/Manager.cpp | 13 | ||||
-rw-r--r-- | src/Manager.h | 1 | ||||
-rw-r--r-- | src/PointerDevice.cpp | 6 | ||||
-rw-r--r-- | src/PointerDevice.h | 2 |
16 files changed, 117 insertions, 46 deletions
@@ -1,3 +1,7 @@ +20.03.2007 +o Make dock buttons listen to device button presses. +o Pair devices on button press on a keyboard in the dock. + 16.03.2007 o expand dock as new keyboards are plugged in. diff --git a/src/Config.h b/src/Config.h index 1e78b08..d6f0732 100644 --- a/src/Config.h +++ b/src/Config.h @@ -18,6 +18,8 @@ using namespace std; #define IMAGEPATH "../images/" #endif +class DockApp; + class Config { private: diff --git a/src/Dock.cpp b/src/Dock.cpp index 8ad8b56..2a7a6e6 100644 --- a/src/Dock.cpp +++ b/src/Dock.cpp @@ -136,41 +136,6 @@ void Dock::handleExpose(XExposeEvent* ev) return; } -void Dock::handleButtonEvent(XButtonEvent* ev) -{ - if (ev->window == dock) - return; - - vector<DockApp*>::const_iterator it = apps.begin(); - - while(it != apps.end()) - { - if ((*it)->hasWindow(ev->window)) - { - (*it)->handleButtonEvent(ev); - return; - } - it++; - } - - vector<DockProcess*>::iterator it2 = processes.begin(); - while (it2 != processes.end()) - { - if ((*it2)->hasWindow(ev->window)) - { - DockProcess *dp = *it2; - dp->handleButtonEvent(ev); - processes.erase(it2); - removeProcess(dp); - delete dp; - return; - } - it2++; - } - - return; -} - /* * A process has been minimized and needs to be appended to the GUI. */ @@ -270,3 +235,72 @@ void Dock::repaint() cairo_fill(cr); cairo_destroy(cr); } + +void Dock::setPointerEvents(vector<PointerDevice*>* pointers) +{ + vector<DockKeyboard*>::const_iterator kit = keyboards.begin(); + vector<PointerDevice*>::const_iterator it; + while(kit != keyboards.end()) + { + it = pointers->begin(); + while(it != pointers->end()) + { + (*it)->setDockEvents((*kit)->getButton()); + it++; + } + kit++; + } + + vector<DockApp*>::const_iterator appit = apps.begin(); + while(appit != apps.end()) + { + it = pointers->begin(); + while(it != pointers->end()) + { + (*it)->setDockEvents((*appit)->getButton()); + it++; + } + appit++; + } + + vector<DockProcess*>::const_iterator prit = processes.begin(); + while(prit != processes.end()) + { + it = pointers->begin(); + while(it != pointers->end()) + { + (*it)->setDockEvents((*prit)->getButton()); + it++; + } + prit++; + } +} + +DockItem* Dock::getDockItem(Window win) +{ + vector<DockApp*>::const_iterator appit = apps.begin(); + while(appit != apps.end()) + { + if ((*appit)->getButton() == win) + return (*appit); + appit++; + } + + vector<DockProcess*>::const_iterator prit = processes.begin(); + while(prit != processes.end()) + { + if ((*prit)->getButton() == win) + return (*prit); + prit++; + } + + vector<DockKeyboard*>::const_iterator kit = keyboards.begin(); + while(kit != keyboards.end()) + { + if ((*kit)->getButton() == win) + return (*kit); + kit++; + } + + return NULL; +} @@ -26,6 +26,7 @@ const int DOCK_HEIGHT_EXTENDED = 5; class DockProcess; class DockApp; +class PointerDevice; class Dock { @@ -50,10 +51,11 @@ class Dock ~Dock(); bool hasWindow(Window win); void handleExpose(XExposeEvent* ev); - void handleButtonEvent(XButtonEvent *ev); void appendProcess(WMWindow* win); void appendKeyboard(KeyboardDevice* kbd); void removeProcess(DockProcess* dp); + void setPointerEvents(vector<PointerDevice*>* pointers); + DockItem* getDockItem(Window win); private: void repaint(); diff --git a/src/DockApp.cpp b/src/DockApp.cpp index 2c9c43b..4d5391a 100644 --- a/src/DockApp.cpp +++ b/src/DockApp.cpp @@ -35,7 +35,7 @@ void DockApp::setup() XFlush(x11->dpy); } -void DockApp::handleButtonEvent(XButtonEvent* ev) +void DockApp::handleButtonEvent(PointerDevice* ptr, XDeviceButtonEvent* ev) { system(app); } diff --git a/src/DockApp.h b/src/DockApp.h index a3c2bb5..92e9633 100644 --- a/src/DockApp.h +++ b/src/DockApp.h @@ -4,8 +4,10 @@ #define __DOCKAPP_H__ #include <X11/Xlib.h> +#include <X11/extensions/XInput.h> #include "XConn.h" #include "DockItem.h" +#include "PointerDevice.h" class DockApp : public DockItem { @@ -15,7 +17,7 @@ class DockApp : public DockItem public: DockApp(XConn* x11, const char* app, char* imgfile); - void handleButtonEvent(XButtonEvent* ev); + void handleButtonEvent(PointerDevice* ptr, XDeviceButtonEvent* ev); void setup(); }; diff --git a/src/DockItem.h b/src/DockItem.h index 59d3cc9..cb57212 100644 --- a/src/DockItem.h +++ b/src/DockItem.h @@ -4,8 +4,10 @@ #define __DOCKITEM_H__ #include <X11/Xlib.h> +#include <X11/extensions/XInput.h> #include "XConn.h" +class PointerDevice; class DockItem { protected: @@ -19,9 +21,10 @@ class DockItem void initGUI(Window parent, int x, int y, int width, int height); bool hasWindow(Window win); void handleExpose(XExposeEvent *ev); - virtual void handleButtonEvent(XButtonEvent* ev) = 0; + virtual void handleButtonEvent(PointerDevice* ptr, XDeviceButtonEvent* ev) = 0; virtual void setup() = 0; virtual ~DockItem(); + Window getButton() { return button; } void move(int x, int y); diff --git a/src/DockKeyboard.cpp b/src/DockKeyboard.cpp index 2a7852d..ac25c54 100644 --- a/src/DockKeyboard.cpp +++ b/src/DockKeyboard.cpp @@ -30,6 +30,9 @@ void DockKeyboard::setup() XFlush(x11->dpy); } -void DockKeyboard::handleButtonEvent(XButtonEvent* ev) +void DockKeyboard::handleButtonEvent(PointerDevice* ptr, + XDeviceButtonEvent* ev) { + TRACE("Pairing %s with %s\n", ptr->getName().c_str(), kbd->getName().c_str()); + XChangePointerKeyboardPairing(x11->dpy, ptr->getDevice(), kbd->getDevice()); } diff --git a/src/DockKeyboard.h b/src/DockKeyboard.h index dbd4014..cb9497f 100644 --- a/src/DockKeyboard.h +++ b/src/DockKeyboard.h @@ -6,6 +6,8 @@ #include "DockItem.h" #include "KeyboardDevice.h" +class PointerDevice; + class DockKeyboard : public DockItem { private: @@ -13,7 +15,7 @@ class DockKeyboard : public DockItem public: DockKeyboard(XConn* x11, KeyboardDevice* kbd); - void handleButtonEvent(XButtonEvent* ev); + void handleButtonEvent(PointerDevice* ptr, XDeviceButtonEvent* ev); void setup(); }; diff --git a/src/DockProcess.cpp b/src/DockProcess.cpp index f0234f4..510b1c1 100644 --- a/src/DockProcess.cpp +++ b/src/DockProcess.cpp @@ -36,7 +36,7 @@ void DockProcess::setup() XFlush(x11->dpy); } -void DockProcess::handleButtonEvent(XButtonEvent* ev) +void DockProcess::handleButtonEvent(PointerDevice* ptr, XDeviceButtonEvent* ev) { client->setMinimize(false); } diff --git a/src/DockProcess.h b/src/DockProcess.h index a286409..76f375d 100644 --- a/src/DockProcess.h +++ b/src/DockProcess.h @@ -9,6 +9,8 @@ #include "WMWindow.h" class WMWindow; +class PointerDevice; + /* An app that was minimized into the dock */ class DockProcess : public DockItem { @@ -17,7 +19,7 @@ class DockProcess : public DockItem public: DockProcess(XConn* x11, WMWindow* client); - void handleButtonEvent(XButtonEvent* ev); + void handleButtonEvent(PointerDevice* ptr, XDeviceButtonEvent* ev); void setup(); }; diff --git a/src/KeyboardDevice.h b/src/KeyboardDevice.h index be51a43..845a0b6 100644 --- a/src/KeyboardDevice.h +++ b/src/KeyboardDevice.h @@ -28,6 +28,7 @@ class KeyboardDevice KeyboardDevice(XDeviceInfo* device, XConn* x11, Manager* manager); int getID() { return id; } string getName() { return name; } + XDevice* getDevice() { return dev; } }; #endif diff --git a/src/Manager.cpp b/src/Manager.cpp index 45b04ee..27c697d 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -148,6 +148,7 @@ void Manager::initXi() } } + dock->setPointerEvents(&pointers); XFreeDeviceList(devices); if (!XGrabAccessControl(x11->dpy)) @@ -327,9 +328,6 @@ void Manager::loop() case PropertyNotify: handlePropertyNotify(&(ev.xproperty)); break; - case ButtonPress: - dock->handleButtonEvent(&(ev.xbutton)); - break; /* XInput device events */ default: handleOtherEvents(&ev); @@ -604,6 +602,13 @@ void Manager::handleButtonPress(XDeviceButtonEvent* bev) TRACE("DeviceButtonPress for device %s on %d/%d\n", dev->getName().c_str(), bev->x_root, bev->y_root); + DockItem* di = dock->getDockItem(bev->window); + if (di) + { + di->handleButtonEvent(dev, bev); + return; + } + WMWindow* wmwindow = windowToWMWindow(bev->window); if (!wmwindow) @@ -758,6 +763,7 @@ void Manager::handlePresenceNotify(XDevicePresenceNotifyEvent* ev) it++; } + dock->setPointerEvents(&pointers); } catch (DeviceError* e) { ERR("%s\n", e->message.c_str()); @@ -774,6 +780,7 @@ void Manager::handlePresenceNotify(XDevicePresenceNotifyEvent* ev) KeyboardDevice *k = new KeyboardDevice(current, x11, this); keyboards.push_back(k); dock->appendKeyboard(k); + dock->setPointerEvents(&pointers); } catch (DeviceError* e) { ERR("%s\n", e->message.c_str()); diff --git a/src/Manager.h b/src/Manager.h index b0288e8..bf0ea76 100644 --- a/src/Manager.h +++ b/src/Manager.h @@ -28,6 +28,7 @@ using namespace std; class WMWindow; class PointerDevice; class Dock; +class Config; int MPWM_ErrorHandler(Display* dpy, XErrorEvent* ev); diff --git a/src/PointerDevice.cpp b/src/PointerDevice.cpp index d277cae..23c6de8 100644 --- a/src/PointerDevice.cpp +++ b/src/PointerDevice.cpp @@ -211,6 +211,12 @@ void PointerDevice::setWMEvents(WMWindow* window) XSelectExtensionEvent(x11->dpy, window->getResizeBtSW(), &classes[1], 1); } +void PointerDevice::setDockEvents(Window win) +{ + XEventClass evclass = evclasses[XI_ButtonPress]; + XSelectExtensionEvent(x11->dpy, win, &evclass, 1); +} + /** * Sets the ButtonPressEvent mask for the given window. */ diff --git a/src/PointerDevice.h b/src/PointerDevice.h index 5bf4069..2182314 100644 --- a/src/PointerDevice.h +++ b/src/PointerDevice.h @@ -52,6 +52,7 @@ class PointerDevice void raise(); int getID() { return id; } string getName() { return name; } + XDevice* getDevice() { return dev; } bool isDragging(); bool dragOn(WMWindow* win, int x, int y); @@ -64,6 +65,7 @@ class PointerDevice void resizeTo(int x, int y); void setWMEvents(WMWindow* client); + void setDockEvents(Window win); long getColor() { return color; } void setButtonPressEventMask(Window win); |