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.

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