From 8028b2b02ae5a302c7781fdd958be6fbf3bc2445 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Fri, 16 Dec 2022 22:46:23 +0100 Subject: A working callback mechanism between C and Scheme code. Callbacks can be fully setup via Scheme code; the C code assumes callbacks have no args and return no values. Within Scheme we setup callbacks via some lambda functions that capture args when needed (see make-callback example). Key press handler operates on the C side using a hash map to find the callback to be called. Everything is set up on the Scheme side, which is less verbose and more convenient to read. * main.scm: Setup callbacks for keypresses * schewm.c: Callbacks hash maps for keys and buttons, handlers for keys * wm.scm: Minor reorganization (key grab also now takes the callback directly) --- main.scm | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'main.scm') diff --git a/main.scm b/main.scm index 827c911..77aedc3 100644 --- a/main.scm +++ b/main.scm @@ -19,6 +19,9 @@ "#0d131a" ; outer-color )) +(define (make-callback proc arg) + (lambda () (proc arg))) + (define wm-keybindings `((,(make-shift-key "q") . ,wm-quit) (,(make-key "q") . ,wm-focus-close) @@ -47,25 +50,25 @@ (,(make-key "z") . ,wm-toggle-bottom-left) (,(make-key "c") . ,wm-toggle-bottom-right) ;; Set current workspace - (,(make-key "1") . ,wm-set-workspace) - (,(make-key "2") . ,wm-set-workspace) - (,(make-key "3") . ,wm-set-workspace) - (,(make-key "4") . ,wm-set-workspace) - (,(make-key "5") . ,wm-set-workspace) - (,(make-key "6") . ,wm-set-workspace) - (,(make-key "7") . ,wm-set-workspace) - (,(make-key "8") . ,wm-set-workspace) - (,(make-key "9") . ,wm-set-workspace) + (,(make-key "1") . ,(make-callback wm-set-workspace 1)) + (,(make-key "2") . ,(make-callback wm-set-workspace 2)) + (,(make-key "3") . ,(make-callback wm-set-workspace 3)) + (,(make-key "4") . ,(make-callback wm-set-workspace 4)) + (,(make-key "5") . ,(make-callback wm-set-workspace 5)) + (,(make-key "6") . ,(make-callback wm-set-workspace 6)) + (,(make-key "7") . ,(make-callback wm-set-workspace 7)) + (,(make-key "8") . ,(make-callback wm-set-workspace 8)) + (,(make-key "9") . ,(make-callback wm-set-workspace 9)) ;; Send client to workspace - (,(make-shift-key "1") . ,wm-set-focused-client-workspace) - (,(make-shift-key "2") . ,wm-set-focused-client-workspace) - (,(make-shift-key "3") . ,wm-set-focused-client-workspace) - (,(make-shift-key "4") . ,wm-set-focused-client-workspace) - (,(make-shift-key "5") . ,wm-set-focused-client-workspace) - (,(make-shift-key "6") . ,wm-set-focused-client-workspace) - (,(make-shift-key "7") . ,wm-set-focused-client-workspace) - (,(make-shift-key "8") . ,wm-set-focused-client-workspace) - (,(make-shift-key "9") . ,wm-set-focused-client-workspace) + (,(make-shift-key "1") . ,(make-callback wm-set-focused-client-workspace 1)) + (,(make-shift-key "2") . ,(make-callback wm-set-focused-client-workspace 2)) + (,(make-shift-key "3") . ,(make-callback wm-set-focused-client-workspace 3)) + (,(make-shift-key "4") . ,(make-callback wm-set-focused-client-workspace 4)) + (,(make-shift-key "5") . ,(make-callback wm-set-focused-client-workspace 5)) + (,(make-shift-key "6") . ,(make-callback wm-set-focused-client-workspace 6)) + (,(make-shift-key "7") . ,(make-callback wm-set-focused-client-workspace 7)) + (,(make-shift-key "8") . ,(make-callback wm-set-focused-client-workspace 8)) + (,(make-shift-key "9") . ,(make-callback wm-set-focused-client-workspace 9)) ;; Send client to monitor (,(make-shift-key "i") . ,wm-client-monitor-prev) (,(make-shift-key "o") . ,wm-client-monitor-next))) @@ -76,5 +79,4 @@ (lambda (mod keysym) (display (list mod keysym)) (newline))) - (wm-run) - (wm-quit)) + (wm-run)) -- cgit v1.2.3