-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from rodlie/master
rel 1.0
- Loading branch information
Showing
5 changed files
with
138 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
# powerdwarf <https://github.com/rodlie/powerdwarf> | ||
# Copyright (c) 2018, Ole-André Rodlie <[email protected]> All rights reserved. | ||
# | ||
# Available under the 3-clause BSD license | ||
# See the LICENSE file for full details | ||
*/ | ||
|
||
#include "hotplug.h" | ||
|
||
HotPlug::HotPlug(QObject *parent) : | ||
QObject(parent) | ||
, _scanning(false) | ||
{ | ||
moveToThread(&t); | ||
t.start(); | ||
} | ||
|
||
HotPlug::~HotPlug() | ||
{ | ||
_scanning = false; | ||
t.wait(); | ||
t.quit(); | ||
} | ||
|
||
void HotPlug::requestScan() | ||
{ | ||
QMetaObject::invokeMethod(this, "scan"); | ||
} | ||
|
||
void HotPlug::scan() | ||
{ | ||
if (_scanning) { return; } | ||
_scanning = true; | ||
|
||
Display *dpy; | ||
if ((dpy = XOpenDisplay(NULL)) == NULL) { return; } | ||
|
||
XRRScreenResources *sr; | ||
XRROutputInfo *info; | ||
XEvent ev; | ||
|
||
getScreens(dpy); | ||
|
||
XRRSelectInput(dpy, DefaultRootWindow(dpy), RROutputChangeNotifyMask); | ||
XSync(dpy, 0); | ||
while(_scanning) { | ||
if (!XNextEvent(dpy, &ev)) { | ||
sr = XRRGetScreenResources(OCNE(&ev)->display, OCNE(&ev)->window); | ||
if (sr == NULL) { continue; } | ||
info = XRRGetOutputInfo(OCNE(&ev)->display, sr, OCNE(&ev)->output); | ||
if (info == NULL) { | ||
XRRFreeScreenResources(sr); | ||
continue; | ||
} | ||
QString screenName = info->name; | ||
bool screenConnected = false; | ||
if (info->connection == RR_Connected) { screenConnected = true; } | ||
emit status(screenName, screenConnected); | ||
XRRFreeScreenResources(sr); | ||
XRRFreeOutputInfo(info); | ||
} | ||
} | ||
XCloseDisplay(dpy); | ||
} | ||
|
||
void HotPlug::requestSetScan(bool scanning) | ||
{ | ||
QMetaObject::invokeMethod(this, "setScan", Q_ARG(bool, scanning)); | ||
} | ||
|
||
void HotPlug::getScreens(Display *dpy) | ||
{ | ||
if (dpy == NULL) { return; } | ||
QMap<QString,bool> result = Screens::outputsDpy(dpy); | ||
emit found(result); | ||
} | ||
|
||
void HotPlug::setScan(bool scanning) | ||
{ | ||
_scanning = scanning; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
# powerdwarf <https://github.com/rodlie/powerdwarf> | ||
# Copyright (c) 2018, Ole-André Rodlie <[email protected]> All rights reserved. | ||
# | ||
# Available under the 3-clause BSD license | ||
# See the LICENSE file for full details | ||
*/ | ||
|
||
#ifndef HOTPLUG_H | ||
#define HOTPLUG_H | ||
|
||
#include <QObject> | ||
#include <QThread> | ||
#include <QMap> | ||
|
||
#include "screens.h" | ||
#include <X11/extensions/Xrandr.h> | ||
|
||
#undef Bool // fix X11 inc | ||
#define OCNE(X) ((XRROutputChangeNotifyEvent*)X) | ||
|
||
class HotPlug : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit HotPlug(QObject *parent = 0); | ||
~HotPlug(); | ||
|
||
private: | ||
QThread t; | ||
bool _scanning; | ||
|
||
signals: | ||
void status(QString display, bool connected); | ||
void found(QMap<QString,bool> devices); | ||
|
||
public slots: | ||
void requestScan(); | ||
void requestSetScan(bool scanning); | ||
private slots: | ||
void scan(); | ||
void getScreens(Display *dpy); | ||
void setScan(bool scanning); | ||
}; | ||
|
||
#endif // HOTPLUG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
# | ||
|
||
VERSION = 1.0.0 | ||
VERSION_EXTRA = "rc2" | ||
VERSION_EXTRA = "" | ||
|
||
isEmpty(PREFIX) { | ||
PREFIX = /usr/local | ||
|