Skip to content

Instantly share code, notes, and snippets.

@richese
Last active October 27, 2015 05:59
Show Gist options
  • Save richese/8576ec80051ac1b1eedb to your computer and use it in GitHub Desktop.
Save richese/8576ec80051ac1b1eedb to your computer and use it in GitHub Desktop.
Shinjiru: Linux windowwatcher
commit 635e0e53614ad9f901f19327b67b00d954a39e32
Author: Lukáš Mandák <lukas.mandak@yandex.com>
Date: Tue Oct 27 06:54:29 2015 +0100
Added Linux support for automatic list updating by using 'xwininfo'
diff --git a/src/lib/windowwatcher.cpp b/src/lib/windowwatcher.cpp
index 60fb096..5792ee0 100644
--- a/src/lib/windowwatcher.cpp
+++ b/src/lib/windowwatcher.cpp
@@ -92,6 +92,34 @@ void WindowWatcher::timeOut() {
m_window_list = s.split(',');
#endif
+#ifdef Q_OS_LINUX
+ QProcess p;
+ p.setProcessChannelMode(QProcess::MergedChannels);
+
+ QEventLoop event;
+ connect(&p, SIGNAL(finished(int)), &event, SLOT(quit()));
+ connect(&p, SIGNAL(error(QProcess::ProcessError)), &event, SLOT(quit()));
+
+ p.start("xwininfo", QStringList() << "-root" << "-tree");
+ event.exec();
+ if (p.error() != QProcess::UnknownError)
+ return;
+
+ QString out = QString(p.readAll());
+ QStringList xwininfo_lines = out.split("\n");
+
+ QRegExp window_line_pattern = QRegExp("\".+\": \\(.+\\)");
+ QStringList windows = xwininfo_lines.filter(window_line_pattern);
+
+ QStringList xorg_window_list;
+ for (int i = 0; i < windows.length(); i++) {
+ QString line = windows.at(i);
+ QString title = line.section("\":", 0, 0).section(" \"", 1, -1);
+ xorg_window_list << title;
+ }
+ m_window_list = xorg_window_list;
+#endif
+
parseWindowList();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment