waiting...

This commit is contained in:
2025-11-29 21:37:04 +01:00
parent 3d0c6f8de0
commit a6608b1d81
7 changed files with 67 additions and 15 deletions

View File

@@ -10,6 +10,7 @@ keybind = ctrl+shift+r=reload_config
keybind = ctrl+shift+h=write_screen_file:copy
keybind = ctrl+shift+j=text:ghostty-capture\n
keybind = ctrl+enter=unbind
command = exec fish

View File

@@ -10,6 +10,7 @@ keybind = ctrl+shift+r=reload_config
keybind = ctrl+shift+h=write_screen_file:copy
keybind = ctrl+shift+j=text:ghostty-capture\n
keybind = ctrl+enter=unbind
command = exec fish

View File

@@ -15,6 +15,7 @@ Singleton {
property bool inOverview: false
property string focusedWindowTitle: ""
property string focusedWindowAppId: ""
property var onScreenshotCaptured: null
function updateFocusedWindowTitle() {
if (windows && windows[focusedWindowId]) {
@@ -84,7 +85,8 @@ Singleton {
const event = JSON.parse(data.trim());
if (event.WorkspacesChanged) {
workspaceProcess.running = true;
} else if (event.WindowsChanged) {
}
if (event.WindowsChanged) {
try {
const windowsData = event.WindowsChanged.windows;
const windowsMap = {};
@@ -104,9 +106,11 @@ Singleton {
} catch (e) {
Logger.error("Niri", "Error parsing windows event:", e);
}
} else if (event.WorkspaceActivated) {
}
if (event.WorkspaceActivated) {
workspaceProcess.running = true;
} else if (event.WindowFocusChanged) {
}
if (event.WindowFocusChanged) {
try {
const focusedId = event.WindowFocusChanged.id;
if (focusedId) {
@@ -123,13 +127,15 @@ Singleton {
} catch (e) {
Logger.error("Niri", "Error parsing window focus event:", e);
}
} else if (event.OverviewOpenedOrClosed) {
}
if (event.OverviewOpenedOrClosed) {
try {
root.inOverview = event.OverviewOpenedOrClosed.is_open === true;
} catch (e) {
Logger.error("Niri", "Error parsing overview state:", e);
}
} else if (event.WindowOpenedOrChanged) {
}
if (event.WindowOpenedOrChanged) {
try {
const targetWin = event.WindowOpenedOrChanged.window;
const id = targetWin.id;
@@ -165,7 +171,8 @@ Singleton {
} catch (e) {
Logger.error("Niri", "Error parsing window opened/changed event:", e);
}
} else if (event.windowClosed) {
}
if (event.windowClosed) {
try {
const closedId = event.windowClosed.id;
if (closedId && (root.windows && root.windows[closedId])) {
@@ -179,6 +186,17 @@ Singleton {
Logger.error("Niri", "Error parsing window closed event:", e);
}
}
if (event.ScreenshotCaptured) {
try {
const path = event.ScreenshotCaptured.path || "";
if (!path) return;
if (root.onScreenshotCaptured && typeof root.onScreenshotCaptured === "function") {
root.onScreenshotCaptured(path);
}
} catch (e) {
Logger.error("Niri", "Error parsing screenshot captured event:", e);
}
}
} catch (e) {
Logger.error("Niri", "Error parsing event stream:", e, data);
}

View File

@@ -0,0 +1,16 @@
import QtQuick
import Quickshell
import Quickshell.Io
pragma Singleton
Singleton {
id: root
function onScreenshotCaptured(path) {
if (!path || typeof path !== "string")
return ;
Quickshell.execDetached(["~/.local/scripts/screenshot-script", "edit", path]);
}
}

View File

@@ -18,6 +18,7 @@ ShellRoot {
sourceComponent: Item {
Component.onCompleted: {
SunsetService;
Niri.onScreenshotCaptured = Screenshot.onScreenshotCaptured;
}
Notification {

View File

@@ -32,6 +32,7 @@ class ScreenshotType(Enum):
FULL = "full"
AREA = "area"
WINDOW = "window"
EDIT = "edit"
SCREENSHOT_DIR = Path.home() / "Pictures" / "Screenshots"
@@ -125,8 +126,16 @@ if __name__ == "__main__":
choices=[t.value for t in ScreenshotType],
help="Type of screenshot to take.",
)
parser.add_argument(
"path",
nargs="?",
default="",
help="Path of the given screenshot file (for edit type only).",
)
args = parser.parse_args()
filepath: Path = Path()
if not args.type == ScreenshotType.EDIT.value:
# file path
SCREENSHOT_DIR.mkdir(parents=True, exist_ok=True)
filename = gen_file_name()
@@ -134,6 +143,12 @@ if __name__ == "__main__":
# take screenshot
take_screenshot(filepath, args.type)
else:
if not args.path:
raise RuntimeError("Path argument is required for edit type.")
filepath = Path(args.path).expanduser()
if not filepath.exists():
raise RuntimeError(f"File does not exist: {filepath}")
# create loop instance
loop = GLib.MainLoop()
@@ -156,9 +171,9 @@ if __name__ == "__main__":
loop.quit()
n = Notify.Notification.new(
"Screenshot Taken",
# Mako doesn't have action buttons displayed with notification cards,
"Click to edit",
str(filepath),
)
n.add_action(
# so default action is used, which will be triggered on simply clicking the notification card