Skip to content

Commit

Permalink
Merge pull request #21 from rodlie/master
Browse files Browse the repository at this point in the history
rel 1.0
  • Loading branch information
rodlie authored Apr 4, 2019
2 parents a50621a + 711c3af commit 8b4ec65
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 6 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.0.0 - 20190404
* Re-added hotplug function (for use by other apps)

## 1.0.0rc2 - 20181103
* Added more configuration options
* Added option to bundle failsafe icons
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ powerkit requires the following dependencies to work:
* [X11](https://www.x.org)
* [Xss](https://www.x.org/archive//X11R7.7/doc/man/man3/Xss.3.xhtml)
* [Xrandr](https://www.x.org/wiki/libraries/libxrandr/)
* [QtDBus](https://qt.io)
* [QtGui](https://qt.io)
* [QtCore](https://qt.io)
* [QtDBus](https://qt.io) 4.8+
* [QtGui](https://qt.io) 4.8+
* [QtCore](https://qt.io) 4.8+

### Run-time dependencies

Expand Down Expand Up @@ -140,7 +140,7 @@ First make sure you have the required dependencies installed, then review the bu

```
mkdir build && cd build
qmake CONFIG+=release .. && make
qmake .. && make
```

Then just run ``app/powerkit`` or ``app/powerkit --config``, or install with:
Expand All @@ -152,7 +152,7 @@ sudo make install
### Package application

```
qmake CONFIG+=release PREFIX=/usr
qmake PREFIX=/usr
make
make INSTALL_ROOT=pkg_path install
```
Expand Down
82 changes: 82 additions & 0 deletions lib/hotplug.cpp
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;
}
47 changes: 47 additions & 0 deletions lib/hotplug.h
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
2 changes: 1 addition & 1 deletion powerkit.pri
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#

VERSION = 1.0.0
VERSION_EXTRA = "rc2"
VERSION_EXTRA = ""

isEmpty(PREFIX) {
PREFIX = /usr/local
Expand Down

0 comments on commit 8b4ec65

Please sign in to comment.