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.

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