mirror of
https://github.com/ebeem/guile-swayer.git
synced 2024-11-16 07:47:32 +01:00
handle cases where current workspace is unknown
This commit is contained in:
parent
ee8513ebec
commit
11b12dbd9f
1 changed files with 9 additions and 8 deletions
|
@ -64,31 +64,32 @@ This means 3x2x2= 12 workspaces should be provided.
|
||||||
(else (get-active-workspace-name (cdr workspaces)))))
|
(else (get-active-workspace-name (cdr workspaces)))))
|
||||||
|
|
||||||
(define* (get-output-index workspace-name #:optional (workspaces WORKSPACES) (index 0))
|
(define* (get-output-index workspace-name #:optional (workspaces WORKSPACES) (index 0))
|
||||||
"Return output index of target workspace name (workspace-name)"
|
"Return output index of target workspace name"
|
||||||
(cond
|
(cond
|
||||||
((null? workspaces) #f)
|
((null? workspace-name) 0)
|
||||||
|
((null? workspaces) 0)
|
||||||
((member workspace-name (car workspaces)) index)
|
((member workspace-name (car workspaces)) index)
|
||||||
(else (get-output-index workspace-name (cdr workspaces) (+ index 1)))))
|
(else (get-output-index workspace-name (cdr workspaces) (+ index 1)))))
|
||||||
|
|
||||||
(define* (get-workspace-index workspace-name #:optional
|
(define* (get-workspace-index workspace-name #:optional
|
||||||
(workspaces
|
(workspaces
|
||||||
(list-ref WORKSPACES (get-output-index workspace-name))))
|
(list-ref WORKSPACES (get-output-index workspace-name))))
|
||||||
"Return index of target workspace name (workspace-name)."
|
"Return index of target workspace name."
|
||||||
(let* ((memberls (member workspace-name workspaces)))
|
(let* ((memberls (member workspace-name workspaces)))
|
||||||
(if memberls (- (length workspaces) (length memberls)))))
|
(if memberls (- (length workspaces) (length memberls)) 0)))
|
||||||
|
|
||||||
(define (get-active-workspace-index)
|
(define (get-active-workspace-index)
|
||||||
"Return index of active/focused workspace."
|
"Return index of active/focused workspace."
|
||||||
(let* ((workspace (get-active-workspace-name)))
|
(let* ((workspace (get-active-workspace-name (sway-get-workspaces))))
|
||||||
(get-workspace-index workspace)))
|
(if workspace (get-workspace-index workspace) 0)))
|
||||||
|
|
||||||
;; available directions, up, right, down, left
|
;; available directions, up, right, down, left
|
||||||
(define* (get-workspace-direction direction #:optional (index -1))
|
(define* (get-workspace-direction direction #:optional index)
|
||||||
"Return the index the target workspace after applying the given direction.
|
"Return the index the target workspace after applying the given direction.
|
||||||
Parameters:
|
Parameters:
|
||||||
- direction: can be one of \"up\", \"right\", \"down\", \"left\".
|
- direction: can be one of \"up\", \"right\", \"down\", \"left\".
|
||||||
- index: the index of the workspace to get the direction from (current by default)."
|
- index: the index of the workspace to get the direction from (current by default)."
|
||||||
(let* ((index (if (< index 0) (get-active-workspace-index) index))
|
(let* ((index (or index (get-active-workspace-index)))
|
||||||
(current-row (floor (/ index COLUMNS)))
|
(current-row (floor (/ index COLUMNS)))
|
||||||
(current-column (modulo index COLUMNS))
|
(current-column (modulo index COLUMNS))
|
||||||
(target-row
|
(target-row
|
||||||
|
|
Loading…
Reference in a new issue