[StumpWM] Dedicated threads for potentially blocking commands
Sometimes StumpWM hangs because of blocking commands. Instead of making StumpWM completely hang, only its dedicated thread will.
This commit is contained in:
parent
f92904cdb0
commit
143161387a
@ -261,41 +261,43 @@ running and an instance is launched, or one already is and we are
|
|||||||
brought to it. This is done like so:
|
brought to it. This is done like so:
|
||||||
#+begin_src lisp
|
#+begin_src lisp
|
||||||
(defcommand firefox () ()
|
(defcommand firefox () ()
|
||||||
"Run or raise Firefox."
|
"Run or raise Firefox."
|
||||||
(run-or-raise "firefox" '(:class "Firefox") t nil))
|
(sb-thread:make-thread (lambda () (run-or-raise "firefox" '(:class "Firefox") t nil))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
Next, this command will not only close the current window, but it will
|
Next, this command will not only close the current window, but it will
|
||||||
also close the current frame.
|
also close the current frame.
|
||||||
#+begin_src lisp
|
#+begin_src lisp
|
||||||
(defcommand delete-window-and-frame () ()
|
(defcommand delete-window-and-frame () ()
|
||||||
"Delete the current frame with its window."
|
"Delete the current frame with its window."
|
||||||
(delete-window)
|
(delete-window)
|
||||||
(remove-split))
|
(remove-split))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
The two following commands will create a new frame to the right and
|
The two following commands will create a new frame to the right and
|
||||||
below the current frame respectively, then focus it.
|
below the current frame respectively, then focus it.
|
||||||
#+begin_src lisp
|
#+begin_src lisp
|
||||||
(defcommand hsplit-and-focus () ()
|
(defcommand hsplit-and-focus () ()
|
||||||
"Create a new frame on the right and focus it."
|
"Create a new frame on the right and focus it."
|
||||||
(hsplit)
|
(hsplit)
|
||||||
(move-focus :right))
|
(move-focus :right))
|
||||||
|
|
||||||
(defcommand vsplit-and-focus () ()
|
(defcommand vsplit-and-focus () ()
|
||||||
"Create a new frame below and move focus to it."
|
"Create a new frame below and move focus to it."
|
||||||
(vsplit)
|
(vsplit)
|
||||||
(move-focus :down))
|
(move-focus :down))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
Now, let’s create a command for invoking the terminal, optionally with
|
Now, let’s create a command for invoking the terminal, optionally with
|
||||||
a program.
|
a program.
|
||||||
#+begin_src lisp
|
#+begin_src lisp
|
||||||
(defcommand term (&optional program) ()
|
(defcommand term (&optional program) ()
|
||||||
"Invoke a terminal, possibly with a @arg{program}."
|
"Invoke a terminal, possibly with a @arg{program}."
|
||||||
(run-shell-command (if program
|
(sb-thread:make-thread
|
||||||
(format nil "kitty ~A" program)
|
(lambda ()
|
||||||
"kitty")))
|
(run-shell-command (if program
|
||||||
|
(format nil "kitty ~A" program)
|
||||||
|
"kitty")))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
And done! Next!
|
And done! Next!
|
||||||
@ -559,9 +561,11 @@ It is then easy to define a command that can call this function and
|
|||||||
set this variable so we can sort of reload the mode-line.
|
set this variable so we can sort of reload the mode-line.
|
||||||
#+begin_src lisp
|
#+begin_src lisp
|
||||||
(defcommand reload-modeline () ()
|
(defcommand reload-modeline () ()
|
||||||
"Reload modeline."
|
"Reload modeline."
|
||||||
(setf *screen-mode-line-format*
|
(sb-thread:make-thread
|
||||||
(cdr (generate-modeline *mode-line-formatter-list*))))
|
(lambda ()
|
||||||
|
(setf *screen-mode-line-format*
|
||||||
|
(cdr (generate-modeline *mode-line-formatter-list*))))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
And actually, let’s reload the modeline immediately.
|
And actually, let’s reload the modeline immediately.
|
||||||
@ -1684,15 +1688,17 @@ This part is easy. Now that we can call our bluetooth commands easily,
|
|||||||
we can easily define how to turn on bluetooth.
|
we can easily define how to turn on bluetooth.
|
||||||
#+begin_src lisp
|
#+begin_src lisp
|
||||||
(defcommand bluetooth-turn-on () ()
|
(defcommand bluetooth-turn-on () ()
|
||||||
"Turn on bluetooth."
|
"Turn on bluetooth."
|
||||||
(bluetooth-message-command "power" "on"))
|
(sb-thread:make-thread
|
||||||
|
(lambda () (bluetooth-message-command "power" "on"))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
And how to power it off.
|
And how to power it off.
|
||||||
#+begin_src lisp
|
#+begin_src lisp
|
||||||
(defcommand bluetooth-turn-off () ()
|
(defcommand bluetooth-turn-off () ()
|
||||||
"Turn off bluetooth."
|
"Turn off bluetooth."
|
||||||
(bluetooth-message-command "power" "off"))
|
(sb-thread:make-thread
|
||||||
|
(lambda () (bluetooth-message-command "power" "off"))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
*** Bluetooth Devices
|
*** Bluetooth Devices
|
||||||
@ -1756,13 +1762,15 @@ collected bluetooth device and the user only has to select it. It will
|
|||||||
then attempt to connect to it.
|
then attempt to connect to it.
|
||||||
#+begin_src lisp
|
#+begin_src lisp
|
||||||
(defcommand bluetooth-connect () ()
|
(defcommand bluetooth-connect () ()
|
||||||
(let* ((devices (bluetooth-get-devices))
|
(sb-thread:make-thread
|
||||||
(choice (cdr (stumpwm:select-from-menu
|
(lambda ()
|
||||||
(stumpwm:current-screen)
|
(let* ((devices (bluetooth-get-devices))
|
||||||
(mapcar (lambda (device)
|
(choice (cdr (stumpwm:select-from-menu
|
||||||
`(,(bluetooth-device-full-name device) . ,device))
|
(stumpwm:current-screen)
|
||||||
devices)))))
|
(mapcar (lambda (device)
|
||||||
(bluetooth-connect-device choice)))
|
`(,(bluetooth-device-full-name device) . ,device))
|
||||||
|
devices)))))
|
||||||
|
(bluetooth-connect-device choice)))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
*** Keybinds
|
*** Keybinds
|
||||||
@ -1848,11 +1856,11 @@ run all the time, just when I need it.
|
|||||||
#+begin_src lisp
|
#+begin_src lisp
|
||||||
(stumpwm:defcommand sly-start-server () ()
|
(stumpwm:defcommand sly-start-server () ()
|
||||||
"Start a slynk server for sly."
|
"Start a slynk server for sly."
|
||||||
(slynk:create-server :dont-close t))
|
(sb-thread:make-thread (lambda () (slynk:create-server :dont-close t))))
|
||||||
|
|
||||||
(stumpwm:defcommand sly-stop-server () ()
|
(stumpwm:defcommand sly-stop-server () ()
|
||||||
"Stop current slynk server for sly."
|
"Stop current slynk server for sly."
|
||||||
(slynk:stop-server 4005))
|
(sb-thread:make-thread (lambda () (slynk:stop-server 4005))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
** ~swm-ssh~
|
** ~swm-ssh~
|
||||||
|
Loading…
Reference in New Issue
Block a user