summaryrefslogtreecommitdiff
path: root/main.scm
diff options
context:
space:
mode:
authorSamuel Fadel <samuel@nihil.ws>2022-12-16 22:46:23 +0100
committerSamuel Fadel <samuel@nihil.ws>2022-12-16 22:46:23 +0100
commit8028b2b02ae5a302c7781fdd958be6fbf3bc2445 (patch)
treec29ee034abbd2eda2361fd45a2392a1d65ffc01f /main.scm
parent99b00bcb3b2803bde4d24f9273a6b81909df5f47 (diff)
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)
Diffstat (limited to 'main.scm')
-rw-r--r--main.scm42
1 files changed, 22 insertions, 20 deletions
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))