@@ -564,13 +564,17 @@ A hashtable, key is url and value is title.")
564
564
(defun eaf--follow-system-dpi ()
565
565
(if (and (getenv " WAYLAND_DISPLAY" ) (not (string= (getenv " WAYLAND_DISPLAY" ) " " )))
566
566
(progn
567
- ; ; We need manually set scale factor when at Gnome/Wayland environment.
568
- ; ; It is important to set QT_AUTO_SCREEN_SCALE_FACTOR=0
569
- ; ; otherwise Qt which explicitly force high DPI enabling get scaled TWICE.
570
- (setenv " QT_AUTO_SCREEN_SCALE_FACTOR" " 0" )
567
+ (cond ((eaf-emacs-running-in-wayland-native)
568
+ ; ; Wayland native need to set QT_AUTO_SCREEN_SCALE_FACTOR=1
569
+ ; ; otherwise Qt window only have half of screen.
570
+ (setenv " QT_AUTO_SCREEN_SCALE_FACTOR" " 1" ))
571
+ (t
572
+ ; ; XWayland need to set QT_AUTO_SCREEN_SCALE_FACTOR=0
573
+ ; ; otherwise Qt which explicitly force high DPI enabling get scaled TWICE.
574
+ (setenv " QT_AUTO_SCREEN_SCALE_FACTOR" " 0" )))
571
575
; ; Set EAF application scale factor.
572
576
(setenv " QT_SCALE_FACTOR" " 1" )
573
- ; ; Force xwayland to ensure SWay works .
577
+ ; ; Use XCB for input event transfer .
574
578
(setenv " QT_QPA_PLATFORM" " xcb" ))
575
579
(setq process-environment
576
580
(seq-filter
@@ -811,24 +815,24 @@ to edit EAF keybindings!" fun fun)))
811
815
(set-keymap-parent map eaf-mode-map*))
812
816
(cl-loop for (key . fun) in (reverse keybinding)
813
817
do (define-key map (kbd key)
814
- (cond
815
- ; ; If command is normal symbol, just call it directly.
816
- ((symbolp fun)
817
- fun)
818
-
819
- ; ; If command is string and include - , it's elisp function, use `intern' build elisp function from function name.
820
- ((string-match " -" fun)
821
- (intern fun))
822
-
823
- ; ; If command prefix with js_, call JavaScript function directly.
824
- ((string-prefix-p " js_" fun)
825
- (eaf--make-js-proxy-function fun))
826
-
827
- ; ; If command is not built-in function and not include char '-'
828
- ; ; it's command in python side, build elisp proxy function to call it.
829
- (t
830
- (eaf--make-py-proxy-function fun))
831
- ))
818
+ (cond
819
+ ; ; If command is normal symbol, just call it directly.
820
+ ((symbolp fun)
821
+ fun)
822
+
823
+ ; ; If command is string and include - , it's elisp function, use `intern' build elisp function from function name.
824
+ ((string-match " -" fun)
825
+ (intern fun))
826
+
827
+ ; ; If command prefix with js_, call JavaScript function directly.
828
+ ((string-prefix-p " js_" fun)
829
+ (eaf--make-js-proxy-function fun))
830
+
831
+ ; ; If command is not built-in function and not include char '-'
832
+ ; ; it's command in python side, build elisp proxy function to call it.
833
+ (t
834
+ (eaf--make-py-proxy-function fun))
835
+ ))
832
836
finally return map))))
833
837
834
838
(defun eaf--get-app-bindings (app-name )
@@ -918,111 +922,120 @@ In this situation, we use 'stay on top' technicality that show EAF window when E
918
922
919
923
'Stay on top' technicality is not perfect like 'cross-process reparent' technicality,
920
924
provide at least one way to let everyone experience EAF. ;)"
921
- (or (eq system-type 'darwin ) ; macOS
922
- (and (eq window-system 'pgtk ) ; Wayland native
923
- (fboundp 'pgtk-backend-display-class )
924
- (string-equal (pgtk-backend-display-class) " GdkWaylandDisplay" ))
925
- (not (display-graphic-p )) ; Terminal emulator
925
+ (or (eq system-type 'darwin ) ; macOS
926
+ (eaf-emacs-running-in-wayland-native) ; Wayland native
927
+ (not (display-graphic-p )) ; Terminal emulator
926
928
))
927
929
930
+ (defun eaf-emacs-running-in-wayland-native ()
931
+ (and (eq window-system 'pgtk )
932
+ (fboundp 'pgtk-backend-display-class )
933
+ (string-equal (pgtk-backend-display-class) " GdkWaylandDisplay" )))
934
+
928
935
(eval-when-compile
929
936
(when (eaf-emacs-not-use-reparent-technology)
930
937
(cond
931
938
((eq system-type 'darwin )
932
- (defcustom eaf--stay-on-top -safe-focus-change t
939
+ (defcustom eaf--mac -safe-focus-change t
933
940
" Whether to verify the active application on Emacs frame focus change.
934
941
935
942
Only set this to nil if you do not use the mouse inside EAF buffers.
936
943
The benefit of setting this to nil is that application switching
937
944
is a lot faster but could be buggy."
938
945
:type 'boolean )
939
946
940
- (defvar eaf--stay-on-top -switch-to-python nil
947
+ (defvar eaf--mac -switch-to-python nil
941
948
" Record if Emacs should switch to Python process." )
942
949
943
- (defvar eaf--stay-on-top -has-focus t
950
+ (defvar eaf--mac -has-focus t
944
951
" Record if Emacs has focus." )
945
952
946
- (defvar eaf--stay-on-top -unsafe-focus-change-timer nil
953
+ (defvar eaf--mac -unsafe-focus-change-timer nil
947
954
" Use timer to ignore spurious focus events.
948
955
949
- This is only used when `eaf--stay-on-top -safe-focus-change' is nil.
956
+ This is only used when `eaf--mac -safe-focus-change' is nil.
950
957
951
958
See
952
959
https://old.reddit.com/r/emacs/comments/\
953
960
kxsgtn/ignore_spurious_focus_events_for/" )
954
961
955
- (defun eaf--stay-on-top -unsafe-focus-change-handler ()
962
+ (defun eaf--mac -unsafe-focus-change-handler ()
956
963
; ; ignore errors related to
957
964
; ; (wrong-type-argument eaf-epc-manager nil)
958
965
(ignore-errors
959
966
(if (frame-focus-state )
960
- (eaf--stay-on-top -unsafe-focus-in)
961
- (eaf--stay-on-top -unsafe-focus-out)))
962
- (setq eaf--stay-on-top -unsafe-focus-change-timer nil ))
967
+ (eaf--mac -unsafe-focus-in)
968
+ (eaf--mac -unsafe-focus-out)))
969
+ (setq eaf--mac -unsafe-focus-change-timer nil ))
963
970
964
- (defun eaf--stay-on-top -focus-change ()
971
+ (defun eaf--mac -focus-change ()
965
972
" Manage Emacs's focus change."
966
- (if eaf--stay-on-top -safe-focus-change
973
+ (if eaf--mac -safe-focus-change
967
974
(let ((front (shell-command-to-string " app-frontmost --name" )))
968
975
(cond
969
976
((string= " Python\n " front)
970
- (setq eaf--stay-on-top -switch-to-python t ))
977
+ (setq eaf--mac -switch-to-python t ))
971
978
972
979
((string= " Emacs\n " front)
973
980
(cond
974
- (eaf--stay-on-top -switch-to-python
975
- (setq eaf--stay-on-top -switch-to-python nil ))
976
- ((not eaf--stay-on-top -has-focus)
977
- (run-with-timer 0.1 nil #'eaf--stay-on-top -focus-in ))
978
- (eaf--stay-on-top -has-focus
979
- (eaf--stay-on-top -focus-out))))
980
- (t (eaf--stay-on-top -focus-out))))
981
- (setq eaf--stay-on-top -unsafe-focus-change-timer
982
- (unless eaf--stay-on-top -unsafe-focus-change-timer
981
+ (eaf--mac -switch-to-python
982
+ (setq eaf--mac -switch-to-python nil ))
983
+ ((not eaf--mac -has-focus)
984
+ (run-with-timer 0.1 nil #'eaf--mac -focus-in ))
985
+ (eaf--mac -has-focus
986
+ (eaf--mac -focus-out))))
987
+ (t (eaf--mac -focus-out))))
988
+ (setq eaf--mac -unsafe-focus-change-timer
989
+ (unless eaf--mac -unsafe-focus-change-timer
983
990
(run-at-time 0.06 nil
984
- #'eaf--stay-on-top -unsafe-focus-change-handler )))))
991
+ #'eaf--mac -unsafe-focus-change-handler )))))
985
992
986
- (defun eaf--stay-on-top -replace-eaf-buffers ()
993
+ (defun eaf--mac -replace-eaf-buffers ()
987
994
(dolist (window (window-list ))
988
995
(select-window window)
989
996
(when (eq major-mode 'eaf-mode )
990
997
(get-buffer-create " *eaf temp*" )
991
998
(switch-to-buffer " *eaf temp*" t ))))
992
999
993
- (defun eaf--stay-on-top -focus-in ()
994
- (setq eaf--stay-on-top -has-focus t )
1000
+ (defun eaf--mac -focus-in ()
1001
+ (setq eaf--mac -has-focus t )
995
1002
(ignore-errors
996
1003
(set-window-configuration
997
- (frame-parameter (selected-frame ) 'eaf--stay-on-top -frame ))
1004
+ (frame-parameter (selected-frame ) 'eaf--mac -frame ))
998
1005
(bury-buffer " *eaf temp*" )))
999
1006
1000
- (defun eaf--stay-on-top -focus-out (&optional frame )
1001
- (when eaf--stay-on-top -has-focus
1002
- (setq eaf--stay-on-top -has-focus nil )
1007
+ (defun eaf--mac -focus-out (&optional frame )
1008
+ (when eaf--mac -has-focus
1009
+ (setq eaf--mac -has-focus nil )
1003
1010
(set-frame-parameter (or frame (selected-frame ))
1004
- 'eaf--stay-on-top -frame (current-window-configuration ))
1005
- (eaf--stay-on-top -replace-eaf-buffers)))
1011
+ 'eaf--mac -frame (current-window-configuration ))
1012
+ (eaf--mac -replace-eaf-buffers)))
1006
1013
1007
- (defun eaf--stay-on-top -unsafe-focus-in ()
1014
+ (defun eaf--mac -unsafe-focus-in ()
1008
1015
(eaf-call-async " show_top_views" )
1009
1016
(set-window-configuration
1010
- (frame-parameter (selected-frame ) 'eaf--stay-on-top -frame )))
1017
+ (frame-parameter (selected-frame ) 'eaf--mac -frame )))
1011
1018
1012
- (defun eaf--stay-on-top -unsafe-focus-out (&optional frame )
1019
+ (defun eaf--mac -unsafe-focus-out (&optional frame )
1013
1020
(eaf-call-async " hide_top_views" )
1014
- (set-frame-parameter (or frame (selected-frame )) 'eaf--stay-on-top -frame
1021
+ (set-frame-parameter (or frame (selected-frame )) 'eaf--mac -frame
1015
1022
(current-window-configuration )))
1016
1023
1017
- (defun eaf--stay-on-top -delete-frame-handler (frame )
1018
- (if eaf--stay-on-top -safe-focus-change
1019
- (eaf--stay-on-top -focus-out frame)
1020
- (eaf--stay-on-top -unsafe-focus-out frame)))
1024
+ (defun eaf--mac -delete-frame-handler (frame )
1025
+ (if eaf--mac -safe-focus-change
1026
+ (eaf--mac -focus-out frame)
1027
+ (eaf--mac -unsafe-focus-out frame)))
1021
1028
1022
- (add-function :after after-focus-change-function #'eaf--stay-on-top -focus-change )
1023
- (add-to-list 'delete-frame-functions #'eaf--stay-on-top -delete-frame-handler ))
1029
+ (add-function :after after-focus-change-function #'eaf--mac -focus-change )
1030
+ (add-to-list 'delete-frame-functions #'eaf--mac -delete-frame-handler ))
1024
1031
(t
1025
- (message " Wayland native code is not supported yet. " )))))
1032
+ (defun eaf--wayland-focus-change ()
1033
+ " Manage Emacs's focus change."
1034
+ (if (frame-focus-state )
1035
+ (eaf-call-async " show_top_views" )
1036
+ (eaf-call-async " hide_top_views" )))
1037
+ (add-function :after after-focus-change-function #'eaf--wayland-focus-change )
1038
+ ))))
1026
1039
1027
1040
(defun eaf-monitor-configuration-change (&rest _ )
1028
1041
" EAF function to respond when detecting a window configuration change."
0 commit comments