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.

133 lines
4.1 KiB

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. *VNCServer*[fn:4] reads the configuration from ~~/.vnc/xstartup~. Override this location with a link to the custom configuration.
  24. #+begin_src emacs-lisp
  25. (dotfiles/symlink "~/.emacs.d/config/xinitrc"
  26. "~/.vnc/xstartup")
  27. #+end_src
  28. * Browser integration
  29. Write out the ~$BROWSER~ variable so other applications can pick up the custom browser.
  30. #+begin_src emacs-lisp
  31. (setenv "BROWSER" dotfiles/browser)
  32. #+end_src
  33. ** Browse URL keybindings
  34. Create a custom keybinding for browsing the urls behind =SPC u=:
  35. + URL with =u=
  36. + Point with =p=
  37. + Cursor with =c=
  38. #+begin_src emacs-lisp
  39. (dotfiles/leader
  40. "u" '(:ignore t :which-key "Browse")
  41. "uu" '(browse-url :which-key "URL")
  42. "up" '(browse-url-at-point :which-key "Point")
  43. "uc" '(browse-url-at-cursor :which-key "Cursor"))
  44. #+end_src
  45. * Displays detection
  46. When the window manager first launches the ~init-hook~ executes, allowing us to define some custom logic.
  47. + Display time and date
  48. + Display battery info (if available)
  49. 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.
  50. #+begin_src emacs-lisp
  51. (defun dotfiles/init-hook ()
  52. (exwm-workspace-switch-create 1)
  53. (setq display-time-and-date t)
  54. (display-battery-mode 1)
  55. (display-time-mode 1))
  56. #+end_src
  57. Using =autorandr= with pre configured profiles, switching screens (AKA hot plugging) is also handled through a hook.
  58. #+begin_src emacs-lisp
  59. (defun dotfiles/update-display ()
  60. "Update the displays by forcing a change through autorandr."
  61. (dotfiles/run-in-background "autorandr --change --force"))
  62. #+end_src
  63. * Window manager
  64. Connect our custom hooks and configure the input keys, a custom layer for key capture layers.
  65. + Enable =randr= support
  66. + Pass through to Emacs
  67. + =M-x= to Emacs
  68. + =C-g= to Emacs
  69. + =C-SPC= to Emacs
  70. + Bindings with =S= (Super / Win)
  71. + Reset =S-r=
  72. + Launch =S-&=
  73. + Workspace =S-[1..9]=
  74. #+begin_src emacs-lisp
  75. (use-package exwm
  76. :when (window-system)
  77. :custom (exwm-workspace-show-all-buffers t)
  78. (exwm-input-prefix-keys
  79. '(?\M-x
  80. ?\C-g
  81. ?\C-\ ))
  82. (exwm-input-global-keys
  83. `(([?\s-r] . exwm-reset)
  84. ,@(mapcar (lambda (i)
  85. `(,(kbd (format "s-%d" i)) .
  86. (lambda ()
  87. (interactive)
  88. (exwm-workspace-switch-create ,i))))
  89. (number-sequence 1 9))))
  90. :config (require 'exwm-randr)
  91. (exwm-randr-enable)
  92. (add-hook 'exwm-init-hook #'dotfiles/init-hook)
  93. (add-hook 'exwm-randr-screen-change-hook #'dotfiles/update-display)
  94. (add-hook 'exwm-update-class-hook (lambda () (exwm-workspace-rename-buffer exwm-class-name)))
  95. (dotfiles/update-display)
  96. (exwm-enable))
  97. #+end_src
  98. * Resources
  99. [fn:1] https://github.com/ch11ng/exwm
  100. [fn:2] https://en.wikipedia.org/wiki/X_Window_System
  101. [fn:3] https://en.wikipedia.org/wiki/Xinit
  102. [fn:4] https://wiki.termux.com/wiki/Graphical_Environment