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.

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