xtools

Check-in [189ff1e73a]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Auto-detect vt number; fallback to .xirc if no WM provided
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:189ff1e73a25bdb2f73a43f792b645b884d234b27e0d1fb27bdd6f49f2a43337
User & Date: jmcclure 2018-01-04 03:03:07
Context
2018-01-04
03:15
Added links to current files check-in: 8a7c808dd8 user: jmcclure tags: trunk
03:03
Auto-detect vt number; fallback to .xirc if no WM provided check-in: 189ff1e73a user: jmcclure tags: trunk
2018-01-03
21:15
Added info check-in: 00626f0bb2 user: jmcclure tags: trunk
Changes

Changes to xi.c.

     1      1   /* xi.c
     2      2    * ----
     3      3    * Minimalist Xinit replacement
     4         - * USAGE: xi $XDG_VTNR /path/to/wm
            4  + * USAGE: xi /path/to/wm
     5      5    * ----
     6      6    *
     7      7    * Copyright (c) 2017 Jesse McClure <code@jessemcclure.org>
     8      8    *
     9      9    * Permission to use, copy, modify, and distribute this software for any
    10     10    * purpose with or without fee is hereby granted, provided that the above
    11     11    * copyright notice and this permission notice appear in all copies.
................................................................................
    19     19    * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    20     20    */
    21     21   
    22     22   #include <stdlib.h>
    23     23   #include <stdio.h>
    24     24   #include <signal.h>
    25     25   #include <unistd.h>
           26  +#include <sys/ioctl.h>
    26     27   #include <sys/wait.h>
    27     28   #include <linux/limits.h>
           29  +#include <linux/vt.h>
    28     30   
    29     31   static volatile int xrunning = 0;
    30     32   
    31     33   void handler(int sig) {
    32     34   	if (sig == SIGUSR1) xrunning = 1;
    33     35   	if (sig == SIGCHLD || sig == SIGTERM) xrunning = 0;
    34     36   }
................................................................................
    54     56   	setenv("XAUTHORITY", xauth, 1);
    55     57   	setenv("DISPLAY", dpy, 1);
    56     58   	execlp(wm, wm, NULL);
    57     59   	_exit(4);
    58     60   }
    59     61   
    60     62   int main(int argc, const char **argv) {
    61         -	if (argc != 3 || argv[1][0] < '1' || argv[1][0] > '9') {
    62         -		fprintf(stderr,"USAGE: %s vt wm\n", argv[0]);
           63  +	struct vt_stat vtstat;
           64  +	if (ioctl(0, VT_GETSTATE, &vtstat)) {
           65  +		perror("get_vt");
    63     66   		return 1;
    64     67   	}
    65         -	char dpy[] = ":1";
    66         -	char tty[] = "vt1";
    67         -	dpy[1] = argv[1][0];
    68         -	tty[2] = argv[1][0];
           68  +	char dpy[] = { ':', '0' + vtstat.v_active, 0 };
           69  +	char tty[] = { 'v', 't', '0' + vtstat.v_active, 0 };
    69     70   
    70     71   	struct sigaction sa = { 0, 0, 0, 0, 0 };
    71     72   	sa.sa_handler = handler;
    72     73   	sigemptyset(&sa.sa_mask);
    73     74   	sa.sa_flags = 0;
    74     75   	sigaction(SIGUSR1, &sa, NULL);
    75     76   	sigaction(SIGCHLD, &sa, NULL);
    76     77   	sigaction(SIGTERM, &sa, NULL);
    77     78   
    78     79   	int xpid = server(dpy, tty);
    79     80   	while (!xrunning) pause();
    80         -	int cpid = client(dpy, argv[2]);
           81  +	int cpid = client(dpy, (argc > 1 ? argv[1] : ".xirc" ));
    81     82   	while (xrunning) pause();
    82     83   
    83     84   	kill(cpid, SIGTERM);
    84     85   	waitpid(cpid, NULL, 0);
    85     86   	kill(xpid, SIGTERM);
    86     87   	waitpid(xpid, NULL, 0);
    87     88   	return 0;
    88     89   }
    89     90