Skip to content

Commit

Permalink
main commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Junker committed Jun 5, 2022
0 parents commit 0de45cd
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# StumpWM Rofi

Rofi module for StumpWM

## Requrements

- [Rofi](https://github.com/davatorium/rofi) installed

## Installation

```bash
cd ~/.stumpwm.d/modules/
git clone https://github.com/Junker/stumpwm-rofi rofi
```

```lisp
(stumpwm:add-to-load-path "~/.stumpwm.d/modules/rofi")
(load-module "rofi")
```

## Usage

```lisp
;; list of pairs '(("name" . "command"))
(defvar *my-menu*
'(("Terminal" . "exec kitty")
("Editor" . "exec featherpad")
("Krusader" . "exec krusader")
("💼 Work >" . (("Emacs" . "app-emacs")
("DBeaver" . "app-dbeaver")
("QOwnNotes" . "app-qownnotes")))
("🌍 Inet >" . (("Firefox" . "app-firefox")
("Telegram" . "app-telegram")
("Mail" . "exec thunderbird")))))
(defcommand my-menu () ()
(rofi:menu *my-menu*)
;; or with rofi arguments
(rofi:menu *my-menu* "-show-icons -theme gruvbox-dark-hard -cycle false"))
(define-key *top-map* (kbd "s-x") "my-menu")
;; windowlist
(define-key *top-map* (kbd "s-Tab") "rofi-windowlist")
;; custom list choose
(message (cdr (rofi:choose '(("1" . "one") ("2" . "two") ("3" . "three"))
"-theme fancy")))
```
6 changes: 6 additions & 0 deletions package.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;;;; package.lisp

(defpackage :rofi
(:use #:cl #:stumpwm #:alexandria)
(:export #:menu
#:choose))
11 changes: 11 additions & 0 deletions rofi.asd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
;;;; rofi.asd

(asdf:defsystem #:rofi
:description "Rofi module for StumpWM"
:author "Dmitrii Kosenkov"
:license "GPLv3"
:version "0.1.0"
:serial t
:depends-on (#:stumpwm)
:components ((:file "package")
(:file "rofi")))
41 changes: 41 additions & 0 deletions rofi.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(in-package :rofi)

(defun run (items &optional (args ""))
(uiop:run-program (format nil "echo \"~A\" | rofi -dmenu ~A"
(prepare-items items)
args)
:ignore-error-status t
:error-output '(:string :stripped t)
:output '(:string :stripped t)))


(defun choose (items args)
(multiple-value-bind (out-text err-text err-code)
(run items args)
(declare (ignore err-text))
(when (eq err-code 0)
(assoc out-text items :test #'string=))))

(defun menu (items &optional (args ""))
(when-let ((item-val (cdr (choose items args))))
(if (stringp item-val)
(run-commands item-val)
(menu item-val args))))

(defun window-name (window)
(format nil "~A (~A)"
(stumpwm::window-class window)
(stumpwm::window-name window)))

(defcommand rofi-windowlist (&optional window-list) (:rest)
(if-let ((window-list (mapcar (lambda (w) (cons (window-name w) w))
(or window-list
(stumpwm::sort-windows-by-number
(group-windows (current-group)))))))
(if-let ((window (cdr (choose window-list ""))))
(group-focus-window (current-group) window)
(throw 'error :abort))
(message "No Managed Windows")))

(defun prepare-items (items)
(format nil "~{~A~^~%~}" (mapcar #'car items)))

0 comments on commit 0de45cd

Please sign in to comment.