I showed you my source code, pls respond
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
5.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #+TITLE: Desktop
  2. #+AUTHOR: Christopher James Hayward
  3. #+EMAIL: chris@chrishayward.xyz
  4. #+PROPERTY: header-args:emacs-lisp :tangle desktop.el :comments org
  5. #+PROPERTY: header-args :results silent :eval no-export :comments org
  6. #+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  7. #+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  8. #+ATTR_ORG: :width 420px
  9. #+ATTR_HTML: :width 420px
  10. #+ATTR_LATEX: :width 420px
  11. [[../docs/images/modules-desktop.png]]
  12. I use Emacs as a Desktop Environment with the *EXWM*[fn:1] package. It allows Emacs to function as a complete tiling window manager for *X11*[fn:2].
  13. * Initialization
  14. :PROPERTIES:
  15. :header-args: :tangle ../config/xinitrc :comments org
  16. :END:
  17. My workflow includes launching the window manager with *Xinit*[fn:3], without the use of a display manager, controlling *everything* within Emacs. In addition, compton is used as a display compositor, and slock for a screen lock.
  18. #+begin_src conf
  19. compton &
  20. xss-lock -- slock &
  21. # FIXME! https://github.com/ch11ng/exwm/issues/210#issuecomment-350044271
  22. exec dbus-launch --exit-with-session emacs -mm --debug-init
  23. #+end_src
  24. ** Create a symbolic link(s)
  25. *Xinit*[fn:3] reads its configuration from ~~/.xinitrc~. Override this location with a link to the custom configuration.
  26. #+begin_src emacs-lisp
  27. (dotfiles/symlink "~/.emacs.d/config/xinitrc"
  28. "~/.xinitrc")
  29. #+end_src
  30. ** Desktop environment
  31. Use the *desktop-environment* package to automatically bind well-known programs for controlling the volume, brightness, media playback, and many other XF86 functionality bindings.
  32. #+begin_src emacs-lisp
  33. (use-package desktop-environment
  34. :after exwm
  35. :custom (desktop-environment-brightness-small-increment "2%+")
  36. (desktop-environment-brightness-small-decrement "2%-")
  37. (desktop-environment-brightness-normal-decrement "5%-")
  38. (desktop-environment-brightness-normal-decrement "5%-")
  39. :config (desktop-environment-mode))
  40. #+end_src
  41. ** Keyboard tweaks
  42. :PROPERTIES:
  43. :header-args: conf :tangle ../config/xmodmap
  44. :END:
  45. Use *XModmap* to swap CapsLock and Ctrl to keep common bindings on the home row.
  46. #+begin_src conf
  47. clear lock
  48. clear control
  49. keycode 66 = Control_L
  50. add control = Control_L
  51. add Lock = Control_R
  52. #+end_src
  53. #+begin_src emacs-lisp
  54. (dotfiles/symlink "~/.emacs.d/config/xmodmap"
  55. "~/.Xmodmap")
  56. #+end_src
  57. #+RESULTS:
  58. * Browser integration
  59. Write out the ~$BROWSER~ variable so other applications can pick up the custom browser.
  60. + Place custom keybindings for browsing behind =SPC b=
  61. + URL with =u=
  62. + URL at point with =p=
  63. + URL at cursor with =c=
  64. #+begin_src emacs-lisp
  65. (setenv "BROWSER" dotfiles/browser)
  66. (dotfiles/leader
  67. "u" '(:ignore t :which-key "Browse")
  68. "uu" '(browse-url :which-key "URL")
  69. "up" '(browse-url-at-point :which-key "Point")
  70. "uc" '(browse-url-at-cursor :which-key "Cursor"))
  71. #+end_src
  72. * Displays detection
  73. When the window manager first launches the ~init-hook~ executes, allowing us to define some custom logic.
  74. + Display time and date
  75. + Display battery info (if available)
  76. In my personal configuration, I do not want the battery or time displayed within Emacs when it's not running as desktop environment because that information is typically already available.
  77. #+begin_src emacs-lisp
  78. (defun dotfiles/init-hook ()
  79. (exwm-workspace-switch-create 1)
  80. (setq display-time-and-date t)
  81. (display-battery-mode 1)
  82. (display-time-mode 1))
  83. #+end_src
  84. Using =autorandr= with pre configured profiles, switching screens (AKA hot plugging) is also handled through a hook.
  85. #+begin_src emacs-lisp
  86. (defun dotfiles/update-display ()
  87. "Update the displays by forcing a change through autorandr."
  88. (dotfiles/run-in-background "autorandr --change --force"))
  89. #+end_src
  90. * Window manager
  91. Connect our custom hooks and configure the input keys, a custom layer for key capture layers.
  92. + Enable =randr= support
  93. + Pass through to Emacs
  94. + =M-x= to Emacs
  95. + =C-g= to Emacs
  96. + =C-SPC= to Emacs
  97. + Bindings with =S= (Super / Win)
  98. + Reset =S-r=
  99. + Launch =S-&=
  100. + Workspace =S-[1..9]=
  101. #+begin_src emacs-lisp
  102. (use-package exwm
  103. :when (window-system)
  104. :custom (exwm-workspace-show-all-buffers t)
  105. (exwm-input-prefix-keys
  106. '(?\M-x
  107. ?\C-g
  108. ?\C-\ ))
  109. (exwm-input-global-keys
  110. `(([?\s-r] . exwm-reset)
  111. ,@(mapcar (lambda (i)
  112. `(,(kbd (format "s-%d" i)) .
  113. (lambda ()
  114. (interactive)
  115. (exwm-workspace-switch-create ,i))))
  116. (number-sequence 1 9))))
  117. :config (require 'exwm-randr)
  118. (exwm-randr-enable)
  119. (add-hook 'exwm-init-hook #'dotfiles/init-hook)
  120. (add-hook 'exwm-randr-screen-change-hook #'dotfiles/update-display)
  121. (add-hook 'exwm-update-class-hook (lambda () (exwm-workspace-rename-buffer exwm-class-name)))
  122. (dotfiles/update-display)
  123. (exwm-enable))
  124. #+end_src
  125. * Footnotes
  126. [fn:1] https://github.com/ch11ng/exwm
  127. [fn:2] https://en.wikipedia.org/wiki/X_Window_System
  128. [fn:3] https://en.wikipedia.org/wiki/Xinit
  129. [fn:4] https://wiki.termux.com/wiki/Graphical_Environment