tChange atomx to handle queries on multiple windows - wmutils - X windows manipulation utilities
 (HTM) git clone git://z3bra.org/wmutils
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 8cfe9a4781ee3bd152be04ecd48ef3a6fbe7d0a2
 (DIR) parent 6131b2b8fe4244fe8b26364c7a293ff1590c62ff
 (HTM) Author: Willy Goiffon <dev@z3bra.org>
       Date:   Sun, 24 Nov 2019 17:33:03 +0100
       
       Change atomx to handle queries on multiple windows
       
       Diffstat:
         M atomx.c                             |      46 ++++++++++++++-----------------
         M man/atomx.1                         |      25 ++++++++++++++++---------
       
       2 files changed, 37 insertions(+), 34 deletions(-)
       ---
 (DIR) diff --git a/atomx.c b/atomx.c
       t@@ -17,7 +17,7 @@ static xcb_connection_t *conn;
        void
        usage(char *name)
        {
       -        fprintf(stderr, "%s [-ds] wid atom [value]\n", name);
       +        fprintf(stderr, "%s [-d] atom[=value] wid\n", name);
        }
        
        xcb_atom_t
       t@@ -86,7 +86,7 @@ get_atom(xcb_window_t wid, xcb_atom_t atom, xcb_atom_t type, char *data, size_t 
        int
        main(int argc, char **argv)
        {
       -        int dflag = 0, sflag = 0;
       +        int i, dflag = 0;
                char *key, *val, *argv0;
                char data[MAXLEN];
                xcb_window_t wid;
       t@@ -96,40 +96,36 @@ main(int argc, char **argv)
                case 'd':
                        dflag = 1;
                        break;
       -        case 's':
       -                sflag = 1;
       -                break;
                default:
                        usage(argv0);
                        return -1;
                } ARGEND;
        
       -        if (argc < 2 + sflag)
       -                return -1;
       -
       -        wid = strtoul(argv[0], NULL, 16);
       -        key = argv[1];
       -        if (sflag)
       -                val = argv[2];
       +        key = strtok(argv[0], "=");
       +        val = strtok(NULL, "=");
        
                init_xcb(&conn);
        
       -        /* retrieve atom ID from server */
       -        atom = add_atom(XCB_ATOM_STRING, key, strlen(key));
       -        if (!atom)
       -                return -1;
       +        for (i = 0; i < argc - 1; i++) {
       +                wid = strtoul(argv[i+1], NULL, 16);
       +
       +                /* retrieve atom ID from server */
       +                atom = add_atom(XCB_ATOM_STRING, key, strlen(key));
       +                if (!atom)
       +                        return -1;
        
       -        /* remove property from window */
       -        if (dflag)
       -                xcb_delete_property(conn, wid, atom);
       +                /* set property on window (must be a string) */
       +                if (val)
       +                        set_atom(wid, atom, XCB_ATOM_STRING, strlen(val), val);
        
       -        /* set property on window (must be a string) */
       -        if (sflag)
       -                set_atom(wid, atom, XCB_ATOM_STRING, strlen(val), val);
       +                /* remove property from window */
       +                if (dflag)
       +                        xcb_delete_property(conn, wid, atom);
        
       -        /* retrieve and print atom value to stdout */
       -        if (!get_atom(wid, atom, XCB_ATOM_STRING, data, MAXLEN))
       -                printf("%s\n", data);
       +                /* retrieve and print atom value to stdout */
       +                if (!get_atom(wid, atom, XCB_ATOM_STRING, data, MAXLEN))
       +                        printf("%s=%s\n", key, data);
       +        }
        
                kill_xcb(&conn);
        
 (DIR) diff --git a/man/atomx.1 b/man/atomx.1
       t@@ -6,9 +6,10 @@
        .Nd manage X atoms on a window
        .Sh SYNOPSIS
        .Nm atomx
       -.Op Fl sd
       -.Ar wid atom
       -.Op Ar value
       +.Op Fl d
       +.Ar atom
       +.Op Ar =value
       +.Ar wid
        .Sh DESCRIPTION
        .Nm
        will print, add, change and remove X atoms on the window with ID
       t@@ -18,19 +19,25 @@ By default
        will print the value of the atom
        .Ar atom
        if it exists.
       +.Pp
       +To set an atom on a window, you must specify it as
       +.Ar atom=value .
        .Bl -tag -width Ds
        .It Fl d
        Delete atom
        .Ar atom
        from the window.
       -.It Fl s
       -Set atom
       -.Ar atom
       -value to
       -.Ar value .
       -Any existing atom with the same name will be overwritten.
        .Sh ENVIRONMENT
        .Nm
        acts on the X display specified by the
        .Ev DISPLAY
        variable.
       +.Sh EXAMPLES
       +Print value of property "WM_CLASS"
       +.Dl $ atomx WM_CLASS 0x00e00005
       +.Pp
       +Change window name to "atomx"
       +.Dl $ atomx WM_NAME=atomx 0x00e00005
       +.Pp
       +Delete property "IS_FULLSCREEN" on a window
       +.Dl $ atomx -d IS_FULLSCREEN 0x00e00005