summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2017-07-04 07:31:28 +0100
committerFrediano Ziglio <fziglio@redhat.com>2018-07-03 11:12:18 +0100
commit6a1fc8be2462046bdb846c8bdb8875c266abe539 (patch)
tree9a17540e6411c6a64f4208af41004b2ae010a094
parent57ddf89c8f6271f243eb6ecebfddc6cb97ce7e1d (diff)
Add file with utilities for Xorg
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r--src/Makefile.am2
-rw-r--r--src/spice-streaming-agent.cpp1
-rw-r--r--src/xorg-utils.cpp40
-rw-r--r--src/xorg-utils.hpp13
4 files changed, 56 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index fead680..2be6bc2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -56,6 +56,8 @@ spice_streaming_agent_SOURCES = \
error.hpp \
frame-log.cpp \
frame-log.hpp \
+ xorg-utils.cpp \
+ xorg-utils.hpp \
mjpeg-fallback.cpp \
mjpeg-fallback.hpp \
jpeg.cpp \
diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp
index 2a34853..126a2f4 100644
--- a/src/spice-streaming-agent.cpp
+++ b/src/spice-streaming-agent.cpp
@@ -9,6 +9,7 @@
#include "frame-log.hpp"
#include "stream-port.hpp"
#include "error.hpp"
+#include "xorg-utils.hpp"
#include <spice/stream-device.h>
#include <spice/enums.h>
diff --git a/src/xorg-utils.cpp b/src/xorg-utils.cpp
new file mode 100644
index 0000000..e03a51e
--- /dev/null
+++ b/src/xorg-utils.cpp
@@ -0,0 +1,40 @@
+/* Utilities dealing with Xorg server
+ *
+ * \copyright
+ * Copyright 2018 Red Hat Inc. All rights reserved.
+ */
+
+#include <config.h>
+#include "xorg-utils.hpp"
+
+#include <exception>
+#include <stdexcept>
+#include <X11/Xatom.h>
+
+int
+get_win_prop_int(Display *display, Window win, Atom atom)
+{
+ int status;
+ unsigned char *prop;
+ unsigned long bytes_after, nitems;
+ int actual_format;
+ Atom actual_type;
+
+ status = XGetWindowProperty(display, win, atom, 0, 64,
+ False, XA_INTEGER, &actual_type,
+ &actual_format, &nitems, &bytes_after,
+ &prop);
+ if (status == Success && nitems > 0) {
+ switch (actual_format) {
+ case 8:
+ return *(const signed char *)prop;
+ case 16:
+ return *(const short *)prop;
+ case 32:
+ // although format is 32 is represented always as a long which
+ // could be 64 bit
+ return *(const long *)prop;
+ }
+ }
+ throw std::runtime_error("error getting property");
+}
diff --git a/src/xorg-utils.hpp b/src/xorg-utils.hpp
new file mode 100644
index 0000000..91ee930
--- /dev/null
+++ b/src/xorg-utils.hpp
@@ -0,0 +1,13 @@
+/* Utilities dealing with Xorg server
+ *
+ * \copyright
+ * Copyright 2018 Red Hat Inc. All rights reserved.
+ */
+#ifndef STREAMING_AGENT_XORG_UTILS_HPP
+#define STREAMING_AGENT_XORG_UTILS_HPP
+
+#include <X11/Xlib.h>
+
+int get_win_prop_int(Display *display, Window win, Atom atom);
+
+#endif // STREAMING_AGENT_XORG_UTILS_HPP