Skip to content

Commit 66dcec6

Browse files
committed
[WIP] preliminary i3 support
1 parent f67cee8 commit 66dcec6

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed

cmake/filelists.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ list(APPEND libdspdfviewer_SRCS
3030
desktopsupportfactory.cpp
3131
desktopsupportexceptions.cpp
3232
desktopsupport/generic.cpp
33+
desktopsupport/i3.cpp
3334
)
3435

3536
if(UseQtFive)

desktopsupport/i3.cpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#include "i3.h"
2+
#include "../debug.h"
3+
#include <boost/throw_exception.hpp>
4+
#include <stdio.h>
5+
#include <sstream>
6+
#include <iostream>
7+
#include <thread>
8+
#include <chrono>
9+
#include <QApplication>
10+
11+
namespace {
12+
typedef std::unique_ptr<
13+
FILE,
14+
decltype(&pclose)
15+
> FILEptr;
16+
}
17+
18+
using namespace std;
19+
20+
DesktopEnvironmentHandlerQuality i3DesktopSupport::quality() const {
21+
/** Check return code of i3 --get-socketpath
22+
* to check verify whether we are on i3
23+
*/
24+
DEBUGOUT << "Checking if we are on i3...";
25+
if ( ! getSocketpath().empty() ) {
26+
return DesktopEnvironmentHandlerQuality::
27+
DesktopEnvironmentSpecificHandler;
28+
} else {
29+
return DesktopEnvironmentHandlerQuality::
30+
NotMyEnvironment;
31+
}
32+
}
33+
34+
i3OutputHandle::i3OutputHandle(const string& name, bool prim):
35+
xrandrName(name), primary(prim)
36+
{
37+
}
38+
39+
const std::string i3OutputHandle::name() const {
40+
return xrandrName;
41+
}
42+
43+
OutputList i3DesktopSupport::getOutputs() const {
44+
/** FIXME: Dummy code */
45+
OutputList list;
46+
list.emplace_back( new i3OutputHandle("DVI-I-1", true) );
47+
list.emplace_back( new i3OutputHandle("VGA-0", false) );
48+
return list;
49+
}
50+
51+
void i3DesktopSupport::moveWindow(QWidget& w, OutputHandle& hnd) const {
52+
i3OutputHandle& h = dynamic_cast<i3OutputHandle&>( hnd );
53+
ostringstream command;
54+
command << "i3-msg "
55+
<< "[id=" << w.winId() << "] "
56+
<< "fullscreen disable, "
57+
<< "move to output " << h.xrandrName;
58+
cerr << "Trying to run " << command.str() << endl;
59+
system( command.str().c_str() );
60+
QApplication::processEvents();
61+
}
62+
63+
void i3DesktopSupport::makeFullscreen(QWidget& w) const {
64+
ostringstream command;
65+
command << "i3-msg "
66+
<< "[id=" << w.winId() << "] "
67+
<< "fullscreen enable";
68+
cerr << "Trying to run " << command.str() << endl;
69+
system( command.str().c_str() );
70+
QApplication::processEvents();
71+
}
72+
73+
74+
const string i3DesktopSupport::getSocketpath() {
75+
/** Cache for the socket path */
76+
static string spath;
77+
if ( ! spath.empty() ) {
78+
return spath;
79+
}
80+
/** Socketpath not cached */
81+
82+
/** FIXME: Port this to boost or similar */
83+
FILEptr fd( popen("i3 --get-socketpath", "r"), pclose );
84+
85+
86+
return "/run/user/1000/i3/ipc-socket.1468";
87+
}

desktopsupport/i3.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include "../desktopsupport.h"
4+
5+
struct i3OutputHandle: public OutputHandle {
6+
const std::string xrandrName;
7+
const std::string name() const override;
8+
const bool primary;
9+
bool isPrimary() const { return primary; }
10+
11+
i3OutputHandle(const std::string&, bool);
12+
};
13+
14+
class i3DesktopSupport: public DesktopSupport {
15+
DesktopEnvironmentHandlerQuality quality() const override;
16+
std::string const name() const override {
17+
return "i3 desktop support via i3 IPC";
18+
}
19+
OutputList getOutputs() const override;
20+
void moveWindow(QWidget&, OutputHandle&) const override;
21+
void makeFullscreen(QWidget&) const override;
22+
private:
23+
static const std::string getSocketpath();
24+
};

desktopsupportfactory.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "desktopsupport/generic.h"
55
#include "desktopsupport/win32.h"
6+
#include "desktopsupport/i3.h"
7+
68
#include <algorithm>
79
#include <stdexcept>
810

@@ -36,6 +38,8 @@ DesktopSupportPtr DesktopSupportFactory::getDesktopSupport() {
3638
allImpls.emplace_back( new Win32DesktopSupport() );
3739
#endif
3840

41+
allImpls.emplace_back( new i3DesktopSupport() );
42+
3943
auto maxElemIt = max_element(
4044
allImpls.begin(),
4145
allImpls.end(),

0 commit comments

Comments
 (0)