Plan 9 from Bell Labs’s /usr/web/sources/contrib/lejatorn/rio/key.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


/* Copyright (c) 2005 Russ Cox, see README for licence details */
#include <stdio.h>
#include <stdlib.h>
#include <X11/X.h>
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/extensions/shape.h>
#include "dat.h"
#include "fns.h"
#include "patchlevel.h"

enum
{
	GrabAltTab,
	GrabAltAny
};

/*static int tabcode = 0x17; */
/*static int altcode = 0x40; */
/*static int pgupcode = 0x63; */
/*static int pgdowncode = 0x69; */

static void alttab(int shift);

void
keysetup(void)
{
	int i;
	int tabcode = XKeysymToKeycode(dpy, XK_Tab);
	int prev = XKeysymToKeycode(dpy, XK_1);
	int next = XKeysymToKeycode(dpy, XK_2);

	for(i=0; i<num_screens; i++){
		XGrabKey(dpy, tabcode, Mod1Mask, screens[i].root, 0, GrabModeSync, GrabModeAsync);
		XGrabKey(dpy, tabcode, Mod1Mask|ShiftMask, screens[i].root, 0, GrabModeSync, GrabModeAsync);
		XGrabKey(dpy, prev, Mod1Mask, screens[i].root, 0, GrabModeSync, GrabModeAsync);
		XGrabKey(dpy, next, Mod1Mask, screens[i].root, 0, GrabModeSync, GrabModeAsync);
	}
}

void
keypress(XKeyEvent *e)
{
	/*
	 * process key press here
	 */
	int tabcode = XKeysymToKeycode(dpy, XK_Tab);
	int prev = XKeysymToKeycode(dpy, XK_1);
	int next = XKeysymToKeycode(dpy, XK_2);
	if ((e->state&Mod1Mask) == Mod1Mask){
		if(e->keycode == tabcode)
			alttab(e->state&ShiftMask);
		else{
			if(e->keycode == prev){
				if(numvirtuals > 1 && virt > 0)
					switch_to(virt - 1);
			} else { 
				if(e->keycode == next){
					if(numvirtuals > 1 && virt < numvirtuals - 1)
						switch_to(virt + 1);
				}
			}
		}
	}
	XAllowEvents(dpy, SyncKeyboard, e->time);
}

void
keyrelease(XKeyEvent *e)
{
	XAllowEvents(dpy, SyncKeyboard, e->time);
}

static void
alttab(int shift)
{
	shuffle(shift);
/*	fprintf(stderr, "%sTab\n", shift ? "Back" : ""); */
}


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.