summaryrefslogtreecommitdiff
path: root/decorations.c
diff options
context:
space:
mode:
authorJon TURNEY <jon.turney@dronecode.org.uk>2012-11-07 21:01:31 +0000
committerJon TURNEY <jon.turney@dronecode.org.uk>2012-11-07 22:00:29 +0000
commit45f7e04bb0f53223a5d05d93aa42b3faa6a97d76 (patch)
tree92e837e579092ffd55c0affb96a5f63d91a65ea8 /decorations.c
testcases
Diffstat (limited to 'decorations.c')
-rw-r--r--decorations.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/decorations.c b/decorations.c
new file mode 100644
index 0000000..cd3e711
--- /dev/null
+++ b/decorations.c
@@ -0,0 +1,81 @@
+/* from https://bugs.kde.org/show_bug.cgi?id=201523 */
+
+#include <stdio.h>
+#include <string.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+/* Compile with "gcc -o decorations -Wall decorations.c -lX11" */
+
+/* Set the decorations part of a window's _MOTIF_WM_HINTS property to
+ * enable or disable window decorations. */
+static void SetMotifDecorationsHint(
+ Display* display, Window win, int show_decorations) {
+ fprintf(stderr, "Setting hint to %s decorations on 0x%x\n",
+ (show_decorations ? "show" : "hide"), win);
+ int values[3] = {
+ 1 << 1, /* flags */
+ 0, /* functions */
+ show_decorations
+ };
+ Atom atom = XInternAtom(display, "_MOTIF_WM_HINTS", False);
+ XChangeProperty(
+ display,
+ win,
+ atom, /* property */
+ atom, /* type */
+ 32, /* format */
+ PropModeReplace,
+ (unsigned char*) values,
+ 3); /* nelements */
+}
+
+int main(int argc, char** argv) {
+ if (argc != 2 || strcmp(argv[1], "-h") == 0) {
+ fprintf(stderr, "Usage: %s [show_decorations]\n", argv[0]);
+ return 1;
+ }
+
+ Display* display = XOpenDisplay(NULL);
+ if (!display) {
+ fprintf(stderr, "Couldn't open display\n");
+ return 1;
+ }
+ int screen = DefaultScreen(display);
+
+ const int width = 300, height = 200;
+
+ unsigned long black = BlackPixel(display, screen);
+ unsigned long white = WhitePixel(display, screen);
+
+ Window win = XCreateSimpleWindow(display,
+ RootWindow(display, screen),
+ 0, /* x */
+ 0, /* y */
+ width,
+ height,
+ 0, /* border_width */
+ black, /* border */
+ white); /* background */
+
+ int showing_decorations = (strcmp(argv[1], "0") != 0);
+ SetMotifDecorationsHint(display, win, showing_decorations);
+
+ XSelectInput(display, win, ButtonPressMask);
+ XMapWindow(display, win);
+
+ while (1) {
+ XEvent event;
+ XNextEvent(display, &event);
+
+ if (event.type == ButtonPress) {
+ XButtonEvent be = event.xbutton;
+ if (be.button == 2) {
+ showing_decorations = !showing_decorations;
+ SetMotifDecorationsHint(display, win, showing_decorations);
+ }
+ }
+ }
+
+ return 0;
+}