Use integer tags, provide macros for pleasant handlers
This commit is contained in:
@@ -26,6 +26,12 @@
|
||||
R:input
|
||||
R:map
|
||||
R:keyboard-group
|
||||
handle-exit
|
||||
handle-idle
|
||||
handle-layout-demand
|
||||
handle-user-command
|
||||
handle-new-output
|
||||
; Provided by C, injected into this module
|
||||
riverctl
|
||||
install-handler
|
||||
seat
|
||||
@@ -39,6 +45,7 @@
|
||||
seat-focused-view-title
|
||||
seat-mode
|
||||
))
|
||||
(use-modules (srfi srfi-1))
|
||||
|
||||
(define (stringify x)
|
||||
(cond ((string? x) x)
|
||||
@@ -79,3 +86,36 @@
|
||||
(riverctl "keyboard-group-add" N d))
|
||||
D)))))
|
||||
|
||||
(define-syntax handle-exit
|
||||
(syntax-rules ()
|
||||
((_ body body* ...)
|
||||
(install-handler 'exit (lambda () body body* ...)))))
|
||||
|
||||
(define-syntax handle-idle
|
||||
(syntax-rules ()
|
||||
((_ tag (event) body body* ...)
|
||||
(install-handler tag (lambda (event) body body* ...)))))
|
||||
|
||||
(define-syntax handle-layout-demand
|
||||
(syntax-rules ()
|
||||
((_ (views width height tags output) body body* ...)
|
||||
(install-handler 'layout-demand (lambda (views width height tags out)
|
||||
(let ((output (find (lambda (x) (eq? (output-name x) out)) (outputs))))
|
||||
body body* ...
|
||||
))))))
|
||||
|
||||
(define-syntax handle-user-command
|
||||
(syntax-rules ()
|
||||
((_ (command tags output) body body* ...)
|
||||
(install-handler 'user-command (lambda (command tags out)
|
||||
(let ((output (find (lambda (x) (eq? (output-name x) out)) (outputs))))
|
||||
body body* ...
|
||||
))))))
|
||||
|
||||
(define-syntax handle-new-output
|
||||
(syntax-rules ()
|
||||
((_ (output) body body* ...)
|
||||
(install-handler 'new-output (lambda (out)
|
||||
(let ((output (find (lambda (x) (eq? (output-name x) out)) (outputs))))
|
||||
body body* ...
|
||||
))))))
|
||||
|
||||
@@ -265,26 +265,17 @@ static SCM scm_str(const char *chars) {
|
||||
return scm_from_utf8_string("");
|
||||
}
|
||||
|
||||
static SCM bitvector_tags(uint32_t tags) {
|
||||
SCM bitvector = scm_c_make_bitvector(32, SCM_BOOL_F);
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if ((tags & (1 << i)) != 0)
|
||||
scm_c_bitvector_set_bit_x(bitvector, i);
|
||||
}
|
||||
return bitvector;
|
||||
}
|
||||
|
||||
static SCM output_for(struct Output *output) {
|
||||
SCM output_scm = scm_make_foreign_object_0(output_t);
|
||||
scm_foreign_object_set_x(output_scm, 0, scm_from_int(output->name));
|
||||
scm_foreign_object_set_x(output_scm, 0, scm_from_uint32(output->name));
|
||||
scm_foreign_object_set_x(output_scm, 1,
|
||||
bitvector_tags(output->tags.focused_tags));
|
||||
scm_from_uint32(output->tags.focused_tags));
|
||||
SCM view_tags = SCM_EOL;
|
||||
for (ssize_t i = output->tags.view_tags_len - 1; i >= 0; i--)
|
||||
view_tags = scm_cons(bitvector_tags(*(output->tags.view_tags + i)), view_tags);
|
||||
view_tags = scm_cons(scm_from_uint32(*(output->tags.view_tags + i)), view_tags);
|
||||
scm_foreign_object_set_x(output_scm, 2, view_tags);
|
||||
scm_foreign_object_set_x(output_scm, 3,
|
||||
bitvector_tags(output->tags.urgent_tags));
|
||||
scm_from_uint32(output->tags.urgent_tags));
|
||||
scm_foreign_object_set_x(output_scm, 4, scm_str(output->tags.layout_name));
|
||||
return output_scm;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user