Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Add xdo_get_desktop_viewport and xdo_set_desktop_viewport.

- Add xdotool get_desktop_viewport and set_desktop_viewport. This is for
  solving desktop movement on window managers like Compiz Fusion that have one
  giant desktop with a 'viewport' for each desktop.


git-svn-id: https://semicomplete.googlecode.com/svn/xdotool@2962 66067f73-fe4c-0410-82e9-b9c6d0c95a22
  • Loading branch information...
commit 56e66a1fcd20151848d6b9d6c74617b44cb43ef3 1 parent 77dca9a
@jordansissel authored
View
3  Makefile
@@ -41,7 +41,8 @@ CMDOBJS= cmd_click.o cmd_mousemove.o cmd_mousemove_relative.o cmd_mousedown.o \
cmd_getwindowfocus.o cmd_getwindowpid.o cmd_getactivewindow.o \
cmd_windowmap.o cmd_windowunmap.o cmd_set_num_desktops.o \
cmd_get_num_desktops.o cmd_set_desktop.o cmd_get_desktop.o \
- cmd_set_desktop_for_window.o cmd_get_desktop_for_window.o
+ cmd_set_desktop_for_window.o cmd_get_desktop_for_window.o \
+ cmd_get_desktop_viewport.o cmd_set_desktop_viewport.o
.PHONY: all
all: xdotool.1 libxdo.$(LIBSUFFIX) libxdo.$(VERLIBSUFFIX) xdotool
View
46 cmd_get_desktop_viewport.c
@@ -0,0 +1,46 @@
+#include "xdo_cmd.h"
+
+int cmd_get_desktop_viewport(context_t *context) {
+ int ret = 0;
+ char *cmd = context->argv[0];
+ int shell_output = 0;
+
+ int c;
+ static struct option longopts[] = {
+ { "help", no_argument, NULL, 'h' },
+ { "shell", no_argument, NULL, 's' },
+ { 0, 0, 0, 0 },
+ };
+ static const char *usage = "Usage: %s\n";
+ int option_index;
+
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
+ longopts, &option_index)) != -1) {
+ switch (c) {
+ case 'h':
+ printf(usage, cmd);
+ consume_args(context, context->argc);
+ return EXIT_SUCCESS;
+ break;
+ case 's':
+ shell_output = 1;
+ break;
+ default:
+ fprintf(stderr, usage, cmd);
+ return EXIT_FAILURE;
+ }
+ }
+
+ int x, y;
+ consume_args(context, optind);
+ ret = xdo_get_desktop_viewport(context->xdo, &x, &y);
+
+ if (shell_output) {
+ printf("X=%d\n", x);
+ printf("Y=%d\n", y);
+ } else {
+ printf("%d,%d\n", x, y);
+ }
+
+ return ret;
+}
View
44 cmd_set_desktop_viewport.c
@@ -0,0 +1,44 @@
+#include "xdo_cmd.h"
+
+int cmd_set_desktop_viewport(context_t *context) {
+ int ret = 0;
+ char *cmd = context->argv[0];
+
+ int c;
+ static struct option longopts[] = {
+ { "help", no_argument, NULL, 'h' },
+ { 0, 0, 0, 0 },
+ };
+ static const char *usage = "Usage: %s x y\n";
+ int option_index;
+
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
+ longopts, &option_index)) != -1) {
+ switch (c) {
+ case 'h':
+ printf(usage, cmd);
+ consume_args(context, context->argc);
+ return EXIT_SUCCESS;
+ break;
+ default:
+ fprintf(stderr, usage, cmd);
+ return EXIT_FAILURE;
+ }
+ }
+
+ consume_args(context, optind);
+ int x, y;
+
+ if (context->argc < 2) {
+ fprintf(stderr, "Not enough arguments given.\n");
+ fprintf(stderr, usage, cmd);
+ return EXIT_FAILURE;
+ }
+
+ x = atoi(context->argv[0]);
+ y = atoi(context->argv[1]);
+ consume_args(context, 2);
+
+ ret = xdo_set_desktop_viewport(context->xdo, x, y);
+ return ret;
+}
View
63 xdo.c
@@ -312,7 +312,7 @@ int xdo_window_wait_for_size(const xdo_t *xdo, Window window, unsigned int width
if (flags & SIZE_USEHINTS) {
xdo_window_translate_with_sizehint(xdo, window, width, height,
- &width, &height);
+ (int *)&width, (int *)&height);
}
xdo_get_window_size(xdo, window, (unsigned int *)&cur_width,
@@ -1639,3 +1639,64 @@ int xdo_mouse_wait_for_move_to(const xdo_t *xdo, int dest_x, int dest_y) {
return ret;
}
+
+int xdo_get_desktop_viewport(const xdo_t *xdo, int *x_ret, int *y_ret) {
+ if (_xdo_ewmh_is_supported(xdo, "_NET_DESKTOP_VIEWPORT") == False) {
+ fprintf(stderr,
+ "Your windowmanager claims not to support _NET_DESKTOP_VIEWPORT, "
+ "so I cannot tell you the viewport position.\n");
+ return XDO_ERROR;
+ }
+
+ Atom type;
+ int size;
+ long nitems;
+ unsigned char *data;
+ Atom request = XInternAtom(xdo->xdpy, "_NET_DESKTOP_VIEWPORT", False);
+ Window root = RootWindow(xdo->xdpy, 0);
+ data = xdo_getwinprop(xdo, root, request, &nitems, &type, &size);
+
+ if (type != XA_CARDINAL) {
+ fprintf(stderr,
+ "Got unexpected type returned from _NET_DESKTOP_VIEWPORT."
+ " Expected CARDINAL, got %s\n",
+ XGetAtomName(xdo->xdpy, type));
+ return XDO_ERROR;
+ }
+
+ if (nitems != 2) {
+ fprintf(stderr, "Expected 2 items for _NET_DESKTOP_VIEWPORT, got %ld\n",
+ nitems);
+ return XDO_ERROR;
+ }
+
+ int *viewport_data = (int *)data;
+ *x_ret = viewport_data[0];
+ *y_ret = viewport_data[1];
+
+ return XDO_SUCCESS;
+}
+
+
+int xdo_set_desktop_viewport(const xdo_t *xdo, int x, int y) {
+ XEvent xev;
+ int ret;
+ Window root = RootWindow(xdo->xdpy, 0);
+
+ memset(&xev, 0, sizeof(xev));
+ xev.type = ClientMessage;
+ xev.xclient.display = xdo->xdpy;
+ xev.xclient.window = root;
+ xev.xclient.message_type = XInternAtom(xdo->xdpy, "_NET_DESKTOP_VIEWPORT",
+ False);
+ xev.xclient.format = 32;
+ xev.xclient.data.l[0] = x;
+ xev.xclient.data.l[1] = y;
+
+ ret = XSendEvent(xdo->xdpy, root, False,
+ SubstructureNotifyMask | SubstructureRedirectMask, &xev);
+
+ /* XXX: XSendEvent returns 0 on conversion failure, nonzero otherwise.
+ * Manpage says it will only generate BadWindow or BadValue errors */
+ return _is_success("XSendEvent[EWMH:_NET_DESKTOP_VIEWPORT]", ret == 0);
+}
View
15 xdo.h
@@ -719,4 +719,19 @@ int xdo_set_active_modifiers(const xdo_t *xdo, Window window,
*/
void xdo_free_active_modifiers(xdo_active_mods_t *active_mods);
+/**
+ * Get the position of the current viewport.
+ *
+ * This is only relevant if your window manager supports
+ * _NET_DESKTOP_VIEWPORT
+ */
+int xdo_get_desktop_viewport(const xdo_t *xdo, int *x_ret, int *y_ret);
+
+/**
+ * Set the position of the current viewport.
+ *
+ * This is only relevant if your window manager supports
+ * _NET_DESKTOP_VIEWPORT
+ */
+int xdo_set_desktop_viewport(const xdo_t *xdo, int x, int y);
#endif /* ifndef _XDO_H_ */
View
3  xdotool.c
@@ -242,6 +242,9 @@ struct dispatch {
{ "get_desktop", cmd_get_desktop, },
{ "set_desktop_for_window", cmd_set_desktop_for_window, },
{ "get_desktop_for_window", cmd_get_desktop_for_window, },
+ { "get_desktop_viewport", cmd_get_desktop_viewport, },
+ { "set_desktop_viewport", cmd_set_desktop_viewport, },
+
{ NULL, NULL, },
};
View
2  xdotool.h
@@ -59,5 +59,7 @@ int cmd_set_desktop(context_t *context);
int cmd_get_desktop(context_t *context);
int cmd_set_desktop_for_window(context_t *context);
int cmd_get_desktop_for_window(context_t *context);
+int cmd_set_desktop_viewport(context_t *context);
+int cmd_get_desktop_viewport(context_t *context);
#endif /* _XDOTOOL_H_ */
Please sign in to comment.
Something went wrong with that request. Please try again.