Skip to content

Commit

Permalink
Support wayland
Browse files Browse the repository at this point in the history
  • Loading branch information
manateelazycat committed Oct 19, 2022
1 parent 133b02e commit 29a5e56
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 2 deletions.
26 changes: 24 additions & 2 deletions eaf.el
Original file line number Diff line number Diff line change
Expand Up @@ -1157,20 +1157,42 @@ kxsgtn/ignore_spurious_focus_events_for/")
(let* ((window-allocation (eaf-get-window-allocation window))
(window-divider-right-padding (if window-divider-mode window-divider-default-right-width 0))
(window-divider-bottom-padding (if window-divider-mode window-divider-default-bottom-width 0))
(titlebar-height (eaf--get-titlebar-height))
(frame-coordinate (eaf--get-frame-coordinate))
(frame-x (car frame-coordinate))
(frame-y (cadr frame-coordinate))
(x (+ (eaf--buffer-x-position-adjust frame) (nth 0 window-allocation)))
(y (+ (eaf--buffer-y-postion-adjust frame) (nth 1 window-allocation)))
(w (nth 2 window-allocation))
(h (nth 3 window-allocation)))
(push (format "%s:%s:%s:%s:%s:%s"
eaf--buffer-id
(eaf-get-emacs-xid frame)
x
y
(+ x frame-x)
(+ y titlebar-height frame-y)
(- w window-divider-right-padding)
(- h window-divider-bottom-padding))
view-infos)))))))
(eaf-call-async "update_views" (mapconcat #'identity view-infos ","))))))

(defun eaf--get-frame-coordinate ()
(cond ((eaf-emacs-running-in-wayland-native)
(let* ((coordinate (mapcar #'string-to-number
(string-split
(dbus-call-method :session "org.gnome.Shell" "/org/eaf/wayland" "org.eaf.wayland" "get_emacs_window_coordinate" :timeout 1000)
",")))
(frame-x (truncate (/ (car coordinate) (frame-scale-factor))))
(frame-y (truncate (/ (cadr coordinate) (frame-scale-factor)))))
(list frame-x frame-y)))
(t
(list 0 0))))

(defun eaf--get-titlebar-height ()
(let ((is-fullscreen-p (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth))))
(if is-fullscreen-p
0
32)))

(defun eaf--get-eaf-buffers ()
"A function that return a list of EAF buffers."
(cl-remove-if-not
Expand Down
83 changes: 83 additions & 0 deletions gnome-shell/[email protected]/extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* extension.js
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/

/* exported init */

const { Gio } = imports.gi;

const EAFWaylandInterface = `
<node>
<interface name="org.eaf.wayland">
<method name="get_active_window">
<arg name="active_window" type="s" direction="out" />
</method>
<method name="get_emacs_window_coordinate">
<arg name="window_coordinate" type="s" direction="out" />
</method>
</interface>
</node>
`;

class wayland {
dbus;

enable() {
this.dbus = Gio.DBusExportedObject.wrapJSObject(
EAFWaylandInterface,
this,
);
this.dbus.export(
Gio.DBus.session,
'/org/eaf/wayland',
);
}

disable() {
this.dbus.unexport_from_connection(
Gio.DBus.session,
);
this.dbus = undefined;
}

get_windows() {
return global.get_window_actors()
.map(w => ({id: w.toString(),
ref: w,
title: w.get_meta_window().get_wm_class()}))
.filter(w => !w.title.includes('Gnome-shell'));
}

get_active_window() {
return this.get_windows().slice(-1)[0].title
}

get_emacs_window_coordinate() {
const match_windows = global.get_window_actors().filter(w => w.get_meta_window().get_wm_class() == "emacs")
if (match_windows[0] == undefined) {
return "0,0"
} else {
const emacs_window = match_windows[0]
const rect = emacs_window.get_meta_window().get_frame_rect()
return rect.x + "," + rect.y
}
}
}

function init() {
return new wayland();
}
10 changes: 10 additions & 0 deletions gnome-shell/[email protected]/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"description": "Expose a D-Bus interface to help EAF running on Wayland",
"name": "EAF Waynland Extension",
"shell-version": [
"42"
],
"url": "https://github.com/emacs-eaf/emacs-application-framework",
"uuid": "[email protected]",
"version": 1
}

0 comments on commit 29a5e56

Please sign in to comment.