|
| 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 | +} |
0 commit comments