# A doubly linked list permits bidirectional traversal. container duplex-list:_elem [ value:_elem next:address:shared:duplex-list:_elem prev:address:shared:duplex-list:_elem ] # should I say in/contained-in:result, allow ingredients to refer to products? recipe push x:_elem, in:address:shared:duplex-list:_elem -> in:address:shared:duplex-list:_elem [ local-scope load-ingredients result:address:shared:duplex-list:_elem <- new {(duplex-list _elem): type} val:address:_elem <- get-address *result, value:offset *val <- copy x next:address:address:shared:duplex-list:_elem <- get-address *result, next:offset *next <- copy in { break-unless in prev:address:address:shared:duplex-list:_elem <- get-address *in, prev:offset *prev <- copy result } reply result # needed explicitly because we need to replace 'in' with 'result' ] recipe first in:address:shared:duplex-list:_elem -> result:_elem [ local-scope load-ingredients reply-unless in, 0 result <- get *in, value:offset ] recipe next in:address:shared:duplex-list:_elem -> result:address:shared:duplex-list:_elem/contained-in:in [ local-scope load-ingredients reply-unless in, 0 result <- get *in, next:offset ] recipe prev in:address:shared:duplex-list:_elem -> result:address:shared:duplex-list:_elem/contained-in:in [ local-scope load-ingredients reply-unless in, 0 result <- get *in, prev:offset reply result ] scenario duplex-list-handling [ run [ # reserve locations 0, 1 and 2 to check for missing null check 1:number <- copy 34 2:number <- copy 35 3:address:shared:duplex-list:character <- push 3, 0 3:address:shared:duplex-list:character <- push 4, 3:address:shared:duplex-list:character 3:address:shared:duplex-list:character <- push 5, 3:address:shared:duplex-list:character 4:address:shared:duplex-list:character <- copy 3:address:shared:duplex-list:character 5:character <- first 4:address:shared:duplex-list:character 4:address:shared:duplex-list:character <- next 4:address:shared:duplex-list:character 6:character <- first 4:address:shared:duplex-list:character 4:address:shared:duplex-list:character <- next 4:address:shared:duplex-list:character 7:character <- first 4:address:shared:duplex-list:character 8:address:shared:duplex-list:character <- next 4:address:shared:duplex-list:character 9:character <- first 8:address:shared:duplex-list:character 10:address:shared:duplex-list:character <- next 8:address:shared:duplex-list:character 11:address:shared:duplex-list:character <- prev 8:address:shared:duplex-list:character 4:address:shared:duplex-list:character <- prev 4:address:shared:duplex-list:character 12:character <- first 4:address:shared:duplex-list:character 4:address:shared:duplex-list:character <- prev 4:address:shared:duplex-list:character 13:character <- first 4:address:shared:duplex-list:character 14:boolean <- equal 3:address:shared:duplex-list:character, 4:address:shared:duplex-list:character ] memory-should-contain [ 0 <- 0 # no modifications to null pointers 1 <- 34 2 <- 35 5 <- 5 # scanning next 6 <- 4 7 <- 3 8 <- 0 # null 9 <- 0 # first of null 10 <- 0 # next of null 11 <- 0 # prev of null 12 <- 4 # then start scanning prev 13 <- 5 14 <- 1 # list back at start ] ] # insert 'x' after 'in' recipe insert x:_elem, in:address:shared:duplex-list:_elem -> in:address:shared:duplex-list:_elem [ local-scope load-ingredients new-node:address:shared:duplex-list:_elem <- new {(duplex-list _elem): type} val:address:_elem <- get-address *new-node, value:offset *val <- copy x next-node:address:shared:duplex-list:_elem <- get *in, next:offset # in.next = new-node y:address:address:shared:duplex-list:_elem <- get-address *in, next:offset *y <- copy new-node # new-node.prev = in y <- get-address *new-node, prev:offset *y <- copy in # new-node.next = next-node y <- get-address *new-node, next:offset *y <- copy next-node # if next-node is not null reply-unless next-node # next-node.prev = new-node y <- get-address *next-node, prev:offset *y <- copy new-node ] scenario inserting-into-duplex-list [ run [ 1:address:shared:duplex-list:character <- push 3, 0 1:address:shared:duplex-list:character <- push 4, 1:address:shared:duplex-list:character 1:address:shared:duplex-list:character <- push 5, 1:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character # 2 points inside list 2:address:shared:duplex-list:character <- insert 6, 2:address:shared:duplex-list:character # check structure like before 2:address:shared:duplex-list:character <- copy 1:address:shared:duplex-list:character 3:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character 4:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character 5:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character 6:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character 7:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character 8:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character 9:character <- first 2:address:shared:duplex-list:character 10:boolean <- equal 1:address:shared:duplex-list:character, 2:address:shared:duplex-list:character ] memory-should-contain [ 3 <- 5 # scanning next 4 <- 4 5 <- 6 # inserted element 6 <- 3 7 <- 6 # then prev 8 <- 4 9 <- 5 10 <- 1 # list back at start ] ] scenario inserting-at-end-of-duplex-list [ run [ 1:address:shared:duplex-list:character <- push 3, 0 1:address:shared:duplex-list:character <- push 4, 1:address:shared:duplex-list:character 1:address:shared:duplex-list:character <- push 5, 1:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character # 2 points inside list 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character # now at end of list 2:address:shared:duplex-list:character <- insert 6, 2:address:shared:duplex-list:character # check structure like before 2:address:shared:duplex-list:character <- copy 1:address:shared:duplex-list:character 3:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character 4:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character 5:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character 6:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character 7:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character 8:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character 9:character <- first 2:address:shared:duplex-list:character 10:boolean <- equal 1:address:shared:duplex-list:character, 2:address:shared:duplex-list:character ] memory-should-contain [ 3 <- 5 # scanning next 4 <- 4 5 <- 3 6 <- 6 # inserted element 7 <- 3 # then prev 8 <- 4 9 <- 5 10 <- 1 # list back at start ] ] scenario inserting-after-start-of-duplex-list [ run [ 1:address:shared:duplex-list:character <- push 3, 0 1:address:shared:duplex-list:character <- push 4, 1:address:shared:duplex-list:character 1:address:shared:duplex-list:character <- push 5, 1:address:shared:duplex-list:character 1:address:shared:duplex-list:character <- insert 6, 1:address:shared:duplex-list:character # check structure like before 2:address:shared:duplex-list:character <- copy 1:address:shared:duplex-list:character 3:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character 4:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character 5:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character 6:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character 7:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character 8:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character 9:character <- first 2:address:shared:duplex-list:character 10:boolean <- equal 1:address:shared:duplex-list:character, 2:address:shared:duplex-list:character ] memory-should-contain [ 3 <- 5 # scanning next 4 <- 6 # inserted element 5 <- 4 6 <- 3 7 <- 4 # then prev 8 <- 6 9 <- 5 10 <- 1 # list back at start ] ] # remove 'x' from its surrounding list 'in' # # Returns null if and only if list is empty. Beware: in that case any other # pointers to the head are now invalid. recipe remove x:address:shared:duplex-list:_elem/contained-in:in, in:address:shared:duplex-list:_elem -> in:address:shared:duplex-list:_elem [ local-scope load-ingredients # if 'x' is null, return reply-unless x next-node:address:shared:duplex-list:_elem <- get *x, next:offset prev-node:address:shared:duplex-list:_elem <- get *x, prev:offset # null x's pointers tmp:address:address:shared:duplex-list:_elem <- get-address *x, next:offset *tmp <- copy 0 tmp <- get-address *x, prev:offset *tmp <- copy 0 # if next-node is not null, set its prev pointer { break-unless next-node tmp <- get-address *next-node, prev:offset *tmp <- copy prev-node } # if prev-node is not null, set its next pointer and return { break-unless prev-node tmp <- get-address *prev-node, next:offset *tmp <- copy next-node reply } # if prev-node is null, then we removed the node at 'in' # return the new head rather than the old 'in' reply next-node ] scenario removing-from-duplex-list [ run [ 1:address:shared:duplex-list:character <- push 3, 0 1:address:shared:duplex-list:character <- push 4, 1:address:shared:duplex-list:character 1:address:shared:duplex-list:character <- push 5, 1:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character # 2 points at second element 1:address:shared:duplex-list:character <- remove 2:address:shared:duplex-list:character, 1:address:shared:duplex-list:character 3:boolean <- equal 2:address:shared:duplex-list:character, 0 # check structure like before 2:address:shared:duplex-list:character <- copy 1:address:shared:duplex-list:character 4:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character 5:character <- first 2:address:shared:duplex-list:character 6:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character 7:character <- first 2:address:shared:duplex-list:character 8:boolean <- equal 1:address:shared:duplex-list:character, 2:address:shared:duplex-list:character ] memory-should-contain [ 3 <- 0 # remove returned non-null 4 <- 5 # scanning next, skipping deleted element 5 <- 3 6 <- 0 # no more elements 7 <- 5 # prev of final element 8 <- 1 # list back at start ] ] scenario removing-from-start-of-duplex-list [ run [ 1:address:shared:duplex-list:character <- push 3, 0 1:address:shared:duplex-list:character <- push 4, 1:address:shared:duplex-list:character 1:address:shared:duplex-list:character <- push 5, 1:address:shared:duplex-list:character 1:address:shared:duplex-list:character <- remove 1:address:shared:duplex-list:character, 1:address:shared:duplex-list:character # check structure like before 2:address:shared:duplex-list:character <- copy 1:address:shared:duplex-list:character 3:character <- first 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character 4:character <- first 2:address:shared:duplex-list:character 5:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- prev 2:address:shared:duplex-list:character 6:character <- first 2:address:shared:duplex-list:character 7:boolean <- equal 1:address:shared:duplex-list:character, 2:address:shared:duplex-list:character ] memory-should-contain [ 3 <- 4 # scanning next, skipping deleted element 4 <- 3 5 <- 0 # no more elements 6 <- 4 # prev of final element 7 <- 1 # list back at start ] ] scenario removing-from-end-of-duplex-list [ run [ 1:address:shared:duplex-list:character <- push 3, 0 1:address:shared:duplex-list:character <- push 4, 1:address:shared:duplex-list:character 1:address:shared:duplex-list:character <- push 5, 1:address:shared:duplex-list:character # delete last element 2:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character 2:address:shared:duplex-list:character <- next 2:address:shared:duplex-list:character 1:address:shared:duplex-list:character <- remove 2:address:shared:dup
/*
 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
 * See LICENSE file for license details.
 */
#include "dwm.h"

#include <stdlib.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>

/* static */

typedef struct {
	unsigned long mod;
	KeySym keysym;
	void (*func)(Arg *arg);
	Arg arg;
} Key;

KEYS

static unsigned int valid_mask =  255 &  ~(NUMLOCKMASK | LockMask);

static void
movemouse(Client *c)
{
	int x1, y1, ocx, ocy, di;
	unsigned int dui;
	Window