Compare commits

..

10 commits

2 changed files with 40 additions and 15 deletions

View file

@ -1,5 +1,7 @@
#+TITLE: exwm-modeline
[[https://melpa.org/#/exwm-modeline][file:https://melpa.org/packages/exwm-modeline-badge.svg]]
A modeline segment to display exwm workspaces.
Here's how it looks near the list of [[https://github.com/nex3/perspective-el][perspectives]] (the segment of the current package is to the left):
@ -13,15 +15,11 @@ Features:
- Numbers are clickable.
* Installation
As the package isn't yet available anywhere but in this repository, you can clone the repository, add it to the =load-path=, and =require= the package:
#+begin_src emacs-lisp
(require 'exwm-modeline)
#+end_src
The package is available on MELPA. Install it however you usually install packages, I use [[https://github.com/jwiegley/use-package][use-package]] and [[https://github.com/raxod502/straight.el][straight.el]]:
My preferred way is to use =use-package= with =straight=:
#+begin_src emacs-lisp
(use-package exwm-modeline
:straight (:host github :repo "SqrtMinusOne/exwm-modeline")
:straight t
:after (exwm))
#+end_src

View file

@ -1,6 +1,6 @@
;;; exwm-modeline.el --- A modeline segment for EXWM workspaces -*- lexical-binding: t -*-
;; Copyright (C) 2021 Korytov Pavel
;; Copyright (C) 2021-2023 Korytov Pavel
;; Copyright (C) 2021 Ellis Kenyő
;; Copyright (C) 2008-2020 Natalie Weizenbaum <nex342@gmail.com>
@ -8,7 +8,8 @@
;; Maintainer: Korytov Pavel <thexcloud@gmail.com>
;; Version: 0.1.3
;; Package-Requires: ((emacs "27.1") (exwm "0.26"))
;; Homepage: https://github.com/SqrtMinusOne/pomm.el
;; Homepage: https://github.com/SqrtMinusOne/exwm-modeline
;; Published-At: 2021-12-22
;; This file is NOT part of GNU Emacs.
@ -37,6 +38,8 @@
;; Take a look at `exwm-modeline-mode' for more info.
;;; Code:
(eval-when-compile
(require 'cl-lib))
(require 'exwm)
(require 'exwm-randr)
(require 'exwm-workspace)
@ -63,7 +66,8 @@ workspaces."
:type 'boolean
:set (lambda (sym value)
(set-default sym value)
(exwm-modeline-update)))
(when (bound-and-true-p exwm-modeline-mode)
(exwm-modeline-update))))
(defcustom exwm-modeline-randr t
"When set, only show workspaces on the current monitor."
@ -71,7 +75,8 @@ workspaces."
:type 'boolean
:set (lambda (sym value)
(set-default sym value)
(exwm-modeline-update)))
(when (bound-and-true-p exwm-modeline-mode)
(exwm-modeline-update))))
(defcustom exwm-modeline-display-urgent t
"When set, display the urgent status in the modeline.
@ -82,8 +87,8 @@ switch, so the number of updates is increased significantly."
:type 'boolean
:set (lambda (sym value)
(set-default sym value)
(exwm-modeline-update)
(when exwm-modeline-mode
(when (bound-and-true-p exwm-modeline-mode)
(exwm-modeline-update)
(if value
(progn
(advice-add #'exwm--update-hints :after #'exwm-modeline--urgency-advice)
@ -91,6 +96,20 @@ switch, so the number of updates is increased significantly."
(advice-remove #'exwm--update-hints #'exwm-modeline--urgency-advice)
(remove-hook 'exwm-workspace-switch-hook #'exwm-modeline--urgency-advice)))))
(defcustom exwm-modeline-workspace-index-map 'exwm-workspace-index-map
"Function for mapping a workspace index to a string for display.
If the value if 'exwm-workspace-index-map, dereference the
`exwm-workspace-index-map'variable. Otherwise, use a function."
:group 'exwm-workspace
:type '(choice
(symbol exwm-workspace-index-map :tag "Use EXWM default")
(function))
:set (lambda (sym value)
(set-default sym value)
(when (bound-and-true-p exwm-modeline-mode)
(exwm-modeline-update))))
(defface exwm-modeline-current-workspace
;; I'd rather :inherit and override warning there, but well
`((t :foreground ,(face-foreground 'warning) :weight bold))
@ -125,6 +144,14 @@ Always return nil if `exwm-modeline-display-urgent' is not set."
if (eq frame (buffer-local-value 'exwm--frame (cdr item)))
return t))
(defun exwm-modeline--workspace-index-map (i)
"Map the workspace index I to a string for display.
See `exwm-modeline-workspace-index-map' for behaviour."
(if (eq exwm-modeline-workspace-index-map 'exwm-workspace-index-map)
(funcall exwm-workspace-index-map i)
(funcall exwm-modeline-workspace-index-map i)))
(defun exwm-modeline--click (event)
"Process a click EVENT on the modeline segment."
(interactive "e")
@ -132,7 +159,7 @@ Always return nil if `exwm-modeline-display-urgent' is not set."
(target
(cl-loop with name = (format "%s" (car (posn-string (event-start event))))
for i from 0 to (1- (length exwm-workspace--list))
if (string-equal (funcall exwm-workspace-index-map i) name)
if (string-equal (exwm-modeline--workspace-index-map i) name)
return i))
(exwm-workspace-switch target)))
@ -148,8 +175,8 @@ Always return nil if `exwm-modeline-display-urgent' is not set."
WORKSPACE-LIST is the list of frames to display."
(cl-loop for frame in workspace-list
for i from 0 to (length workspace-list)
for workspace-name = (funcall exwm-workspace-index-map
(exwm-workspace--position frame))
for workspace-name = (exwm-modeline--workspace-index-map
(exwm-workspace--position frame))
with current-frame = (selected-frame)
if (= i 0) collect (nth 0 exwm-modeline-dividers)
collect