Skip to content

Commit 4d0eb55

Browse files
Mumulhlmanateelazycat
authored andcommitted
fix: Hyprland window alignment
1 parent a90636e commit 4d0eb55

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

core/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,25 @@ def handle_arg_types(arg):
249249

250250
return sexpdata.Quoted(arg)
251251

252+
def hyprland_window_move(x, y):
253+
import subprocess
254+
import json
255+
256+
clients = json.loads(subprocess.check_output("hyprctl -j clients", shell=True))
257+
window_info = []
258+
259+
for window in clients:
260+
if window["title"] == "eaf.py":
261+
window_info = window["at"]
262+
break
263+
264+
if len(window_info) == 0:
265+
return
266+
267+
[window_x, window_y] = window_info
268+
269+
if not (x - window_x == 0 and y - window_y == 0):
270+
subprocess.check_call(f"hyprctl dispatch movewindowpixel '{x - window_x} {y - window_y}','title:^(eaf.py)$'", shell=True)
252271

253272
def eval_in_emacs(method_name, args):
254273
global epc_client

core/view.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from PyQt6.QtCore import Qt, QEvent, QPoint
2323
from PyQt6.QtGui import QPainter, QWindow, QBrush
2424
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QGraphicsView, QFrame
25-
from core.utils import eval_in_emacs, focus_emacs_buffer, get_emacs_func_cache_result
25+
from core.utils import eval_in_emacs, focus_emacs_buffer, get_emacs_func_cache_result, hyprland_window_move
2626

2727
class View(QWidget):
2828

@@ -105,8 +105,12 @@ def adjust_aspect_ratio(self):
105105
def eventFilter(self, obj, event):
106106
# import time
107107
# print(time.time(), event.type())
108-
108+
109109
import platform
110+
import os
111+
112+
if os.getenv("XDG_CURRENT_DESKTOP") == "Hyprland":
113+
hyprland_window_move(self.x, self.y)
110114

111115
if event.type() in [QEvent.Type.ShortcutOverride]:
112116
eval_in_emacs('eaf-activate-emacs-window', [self.buffer_id])
@@ -126,7 +130,7 @@ def eventFilter(self, obj, event):
126130
def showEvent(self, event):
127131
# NOTE: we must reparent after widget show, otherwise reparent operation maybe failed.
128132
import platform
129-
133+
130134
self.reparent()
131135

132136
if platform.system() in ["Windows", "Darwin"]:

0 commit comments

Comments
 (0)