From 4a93b046e954892edf3356bcd5745c612232fe15 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 12 Jul 2020 00:12:55 +0200 Subject: x11: add option to make window appear on a specific workspace Mess this into the --geometry option, because I like to be irresponsible. I considered adding a separate option, but at least this allows me to defer the question how the hell this should work as property (geometry simply and inherently does not). Tested on IceWM only. Option equality test and string output not tested. --- DOCS/man/options.rst | 11 +++++++---- options/m_option.c | 15 +++++++++++++-- options/m_option.h | 1 + video/out/x11_common.c | 5 +++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index f554186f04..b85b67c991 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -2936,7 +2936,7 @@ Window (X11 only) Show the video window on all virtual desktops. -``--geometry=<[W[xH]][+-x+-y]>``, ``--geometry=`` +``--geometry=<[W[xH]][+-x+-y][/WS]>``, ``--geometry=`` Adjust the initial window position or size. ``W`` and ``H`` set the window size in pixels. ``x`` and ``y`` set the window position, measured in pixels from the top-left corner of the screen to the top-left corner of the image @@ -2945,7 +2945,9 @@ Window Positions are specified similar to the standard X11 ``--geometry`` option format, in which e.g. +10-50 means "place 10 pixels from the left border and 50 pixels from the lower border" and "--20+-10" means "place 20 pixels - beyond the right and 10 pixels beyond the top border". + beyond the right and 10 pixels beyond the top border". A trailing ``/`` + followed by an integer denotes on which workspace (virtual desktop) the + window should appear (X11 only). If an external window is specified using the ``--wid`` option, this option is ignored. @@ -2982,9 +2984,10 @@ Window Forces the window width and height to half the screen width and height. Will show black borders to compensate for the video aspect ratio (with most VOs and without ``--no-keepaspect``). - ``50%+10+10`` + ``50%+10+10/2`` Sets the window to half the screen widths, and positions it 10 - pixels below/left of the top left corner of the screen. + pixels below/left of the top left corner of the screen, on the + second workspace. See also ``--autofit`` and ``--autofit-larger`` for fitting the window into a given size without changing aspect ratio. diff --git a/options/m_option.c b/options/m_option.c index 51e3c38801..9b0fd82779 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -2145,7 +2145,7 @@ static bool parse_geometry_str(struct m_geometry *gm, bstr s) if (s.len == 0) return true; // Approximate grammar: - // [[W][xH]][{+-}X{+-}Y] | [X:Y] + // [[W][xH]][{+-}X{+-}Y][/WS] | [X:Y] // (meaning: [optional] {one character of} one|alternative) // Every number can be followed by '%' int num; @@ -2181,6 +2181,14 @@ static bool parse_geometry_str(struct m_geometry *gm, bstr s) READ_SIGN(y_sign); READ_NUM(y, y_per); } + if (bstr_eatstart0(&s, "/")) { + bstr rest; + long long v = bstrtoll(s, &rest, 10); + if (s.len == rest.len || v < 1 || v > INT_MAX) + goto error; + s = rest; + gm->ws = v; + } } else { gm->xy_valid = true; READ_NUM(x, x_per); @@ -2217,6 +2225,8 @@ static char *print_geometry(const m_option_t *opt, const void *val) res = talloc_asprintf_append(res, gm->y_sign ? "-" : "+"); APPEND_PER(y, y_per); } + if (gm->ws > 0) + res = talloc_asprintf_append(res, "/%d", gm->ws); } return res; } @@ -2301,7 +2311,8 @@ static bool geometry_equal(const m_option_t *opt, void *a, void *b) ga->xy_valid == gb->xy_valid && ga->wh_valid == gb->wh_valid && ga->w_per == gb->w_per && ga->h_per == gb->h_per && ga->x_per == gb->x_per && ga->y_per == gb->y_per && - ga->x_sign == gb->x_sign && ga->y_sign == gb->y_sign; + ga->x_sign == gb->x_sign && ga->y_sign == gb->y_sign && + ga->ws == gb->ws; } const m_option_type_t m_option_type_geometry = { diff --git a/options/m_option.h b/options/m_option.h index f51ca95fa8..25dc212482 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -98,6 +98,7 @@ struct m_geometry { bool xy_valid : 1, wh_valid : 1; bool w_per : 1, h_per : 1; bool x_sign : 1, y_sign : 1, x_per : 1, y_per : 1; + int ws; // workspace; valid if !=0 }; void m_geometry_apply(int *xpos, int *ypos, int *widw, int *widh, diff --git a/video/out/x11_common.c b/video/out/x11_common.c index 40228903b9..461ff378d0 100644 --- a/video/out/x11_common.c +++ b/video/out/x11_common.c @@ -1498,8 +1498,9 @@ static void vo_x11_map_window(struct vo *vo, struct mp_rect rc) x11_send_ewmh_msg(x11, "_NET_WM_FULLSCREEN_MONITORS", params); } - if (x11->opts->all_workspaces) { - long v = 0xFFFFFFFF; + if (x11->opts->all_workspaces || x11->opts->geometry.ws > 0) { + long v = x11->opts->all_workspaces + ? 0xFFFFFFFF : x11->opts->geometry.ws - 1; XChangeProperty(x11->display, x11->window, XA(x11, _NET_WM_DESKTOP), XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&v, 1); } -- cgit v1.2.3