Skip to content

Commit

Permalink
Add "show all opened windows" view endpoint to bundled plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Exidex committed Jan 6, 2025
1 parent 27e60d4 commit a5d69e8
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ edition = "2021"

[workspace.dependencies]
# iced
#iced = { version = "0.13.99", features = ["tokio", "lazy", "advanced", "image"] }
#iced = { version = "0.13.99", features = ["wgpu", "tokio", "lazy", "advanced", "image"] }
iced = { git = "https://github.com/project-gauntlet/iced.git", branch = "gauntlet-0.13", default-features = false, features = ["wgpu", "tokio", "advanced", "image"] }
#iced_aw = { version = "0.11.99", features = ["date_picker", "wrap", "number_input", "grid", "spinner"] }
iced_aw = { git = "https://github.com/project-gauntlet/iced_aw.git", branch = "gauntlet-0.13", default-features = false, features = ["date_picker", "wrap", "number_input", "grid", "spinner"] }
Expand Down
7 changes: 7 additions & 0 deletions bundled_plugins/gauntlet/gauntlet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ path = 'src/applications.tsx'
type = 'entrypoint-generator'
description = 'Run installed applications from your system'

[[entrypoint]]
id = 'windows'
name = 'All Open Windows'
path = 'src/windows.tsx'
type = 'view'
description = 'Show all open windows'

[[entrypoint]]
id = 'settings'
name = 'Gauntlet Settings'
Expand Down
11 changes: 3 additions & 8 deletions bundled_plugins/gauntlet/src/applications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ import {
macos_settings_pre_13,
macos_system_applications
} from "gauntlet:bridge/internal-macos";
import { applicationAccessories, applicationActions, OpenWindowData } from "./window/shared";
import { applicationAccessories, applicationActions } from "./window/shared";
import { applicationEventLoopX11, focusX11Window } from "./window/x11";
import { applicationEventLoopWayland, focusWaylandWindow } from "./window/wayland";
import { windows_app_from_path, windows_application_dirs, windows_open_application } from "gauntlet:bridge/internal-windows";

export default async function Applications({ add, remove, get, getAll }: GeneratorProps): Promise<void | (() => void)> {
const openWindows: Record<string, OpenWindowData> = {};

switch (current_os()) {
case "linux": {
Expand All @@ -38,9 +37,8 @@ export default async function Applications({ add, remove, get, getAll }: Generat
linux_open_application(id)
},
focusWaylandWindow,
openWindows
),
accessories: applicationAccessories(id, openWindows),
accessories: applicationAccessories(id),
icon: data.icon, // TODO lazy icons
"__linux__": {
startupWmClass: data.startup_wm_class,
Expand All @@ -56,9 +54,8 @@ export default async function Applications({ add, remove, get, getAll }: Generat
linux_open_application(id)
},
focusX11Window,
openWindows,
),
accessories: applicationAccessories(id, openWindows),
accessories: applicationAccessories(id),
icon: data.icon, // TODO lazy icons
"__linux__": {
startupWmClass: data.startup_wm_class,
Expand All @@ -74,7 +71,6 @@ export default async function Applications({ add, remove, get, getAll }: Generat
if (wayland()) {
try {
applicationEventLoopWayland(
openWindows,
focusWaylandWindow,
add,
get,
Expand All @@ -86,7 +82,6 @@ export default async function Applications({ add, remove, get, getAll }: Generat
} else {
try {
applicationEventLoopX11(
openWindows,
focusX11Window,
add,
get,
Expand Down
15 changes: 7 additions & 8 deletions bundled_plugins/gauntlet/src/window/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ export type OpenWindowData = {
appId: string
}

export const openWindows: Record<string, OpenWindowData> = {};

export function applicationActions(
id: string,
openApplication: () => void,
focusWindow: (windowId: string) => void,
openWindows: Record<string, OpenWindowData>
): GeneratedCommandAction[] {
const appWindows = Object.entries(openWindows)
.filter(([_, windowData]) => windowData.appId == id)
Expand Down Expand Up @@ -68,7 +69,7 @@ export function applicationActions(
}
}

export function applicationAccessories(id: string, openWindows: Record<string, OpenWindowData>): GeneratedCommandAccessory[] {
export function applicationAccessories(id: string): GeneratedCommandAccessory[] {
const appWindows = Object.entries(openWindows)
.filter(([_, windowData]) => windowData.appId == id)

Expand All @@ -88,7 +89,6 @@ export function addOpenWindow(
generatedEntrypoint: GeneratedCommand,
windowId: string,
windowTitle: string,
openWindows: Record<string, OpenWindowData>,
openApplication: () => void,
focusWindow: (windowId: string) => void,
add: (id: string, data: GeneratedCommand) => void,
Expand All @@ -102,14 +102,13 @@ export function addOpenWindow(

add(appId, {
...generatedEntrypoint,
actions: applicationActions(appId, openApplication, focusWindow, openWindows),
accessories: applicationAccessories(appId, openWindows)
actions: applicationActions(appId, openApplication, focusWindow),
accessories: applicationAccessories(appId)
})
}
}

export function deleteOpenWindow(
openWindows: Record<string, OpenWindowData>,
windowId: string,
openApplication: (appId: string) => (() => void),
focusWindow: (windowId: string) => void,
Expand All @@ -125,8 +124,8 @@ export function deleteOpenWindow(
if (generatedEntrypoint) {
add(openWindow.appId, {
...generatedEntrypoint,
actions: applicationActions(openWindow.appId, openApplication(openWindow.appId), focusWindow, openWindows),
accessories: applicationAccessories(openWindow.appId, openWindows)
actions: applicationActions(openWindow.appId, openApplication(openWindow.appId), focusWindow),
accessories: applicationAccessories(openWindow.appId)
})
}
}
Expand Down
9 changes: 2 additions & 7 deletions bundled_plugins/gauntlet/src/window/wayland.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addOpenWindow, deleteOpenWindow, openLinuxApplication, OpenWindowData } from "./shared";
import { addOpenWindow, deleteOpenWindow, openLinuxApplication } from "./shared";
import { GeneratedCommand } from "@project-gauntlet/api/helpers";
import { linux_wayland_focus_window, application_wayland_pending_event } from "gauntlet:bridge/internal-linux";

Expand All @@ -8,7 +8,6 @@ export function focusWaylandWindow(windowId: string) {
}

export function applicationEventLoopWayland(
openWindows: Record<string, OpenWindowData>,
focusWindow: (windowId: string) => void,
add: (id: string, data: GeneratedCommand) => void,
get: (id: string) => GeneratedCommand | undefined,
Expand All @@ -33,7 +32,7 @@ export function applicationEventLoopWayland(
case "WindowClosed": {
delete knownWindows[applicationEvent.window_id]

deleteOpenWindow(openWindows, applicationEvent.window_id, openLinuxApplication, focusWindow, get, add)
deleteOpenWindow(applicationEvent.window_id, openLinuxApplication, focusWindow, get, add)

break;
}
Expand All @@ -52,7 +51,6 @@ export function applicationEventLoopWayland(
windowId,
windowAppId,
windowTitle,
openWindows,
focusWindow,
add,
get,
Expand All @@ -78,7 +76,6 @@ export function applicationEventLoopWayland(
windowId,
windowAppId,
windowTitle,
openWindows,
focusWindow,
add,
get,
Expand All @@ -97,7 +94,6 @@ function addOpenWindowWayland(
windowId: string,
windowAppId: string,
windowTitle: string,
openWindows: Record<string, OpenWindowData>,
focusWindow: (windowId: string) => void,
add: (id: string, data: GeneratedCommand) => void,
get: (id: string) => GeneratedCommand | undefined,
Expand Down Expand Up @@ -130,7 +126,6 @@ function addOpenWindowWayland(
generatedEntrypoint,
windowId,
windowTitle,
openWindows,
openLinuxApplication(appId),
focusWindow,
add,
Expand Down
27 changes: 12 additions & 15 deletions bundled_plugins/gauntlet/src/window/x11.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GeneratedCommand } from "@project-gauntlet/api/helpers";
import { addOpenWindow, deleteOpenWindow, openLinuxApplication, OpenWindowData } from "./shared";
import { addOpenWindow, deleteOpenWindow, openLinuxApplication } from "./shared";
import { application_x11_pending_event, linux_x11_focus_window } from "gauntlet:bridge/internal-linux";

export type X11WindowData = {
Expand Down Expand Up @@ -36,7 +36,6 @@ export function focusX11Window(windowId: string) {
}

export function applicationEventLoopX11(
openWindows: Record<string, OpenWindowData>,
focusWindow: (windowId: string) => void,
add: (id: string, data: GeneratedCommand) => void,
get: (id: string) => GeneratedCommand | undefined,
Expand Down Expand Up @@ -87,7 +86,7 @@ export function applicationEventLoopX11(
case "DestroyNotify": {
delete windows[applicationEvent.id]

deleteOpenWindow(openWindows, applicationEvent.id, openLinuxApplication, focusWindow, get, add)
deleteOpenWindow(applicationEvent.id, openLinuxApplication, focusWindow, get, add)

break;
}
Expand All @@ -96,7 +95,7 @@ export function applicationEventLoopX11(
if (window) {
window.mapped = true;

validateAndAddOpenWindow(window, openWindows, windows, openLinuxApplication, focusWindow, add, getAll)
validateAndAddOpenWindow(window, windows, openLinuxApplication, focusWindow, add, getAll)
}

break;
Expand All @@ -106,7 +105,7 @@ export function applicationEventLoopX11(
if (window) {
window.mapped = false;

deleteOpenWindow(openWindows, applicationEvent.id, openLinuxApplication, focusWindow, get, add)
deleteOpenWindow(applicationEvent.id, openLinuxApplication, focusWindow, get, add)
}

break;
Expand All @@ -117,7 +116,7 @@ export function applicationEventLoopX11(
if (window) {
window.mapped = true;

validateAndAddOpenWindow(window, openWindows, windows, openLinuxApplication, focusWindow, add, getAll)
validateAndAddOpenWindow(window, windows, openLinuxApplication, focusWindow, add, getAll)
}

break;
Expand All @@ -127,7 +126,7 @@ export function applicationEventLoopX11(
if (window) {
window.title = applicationEvent.title;

validateAndAddOpenWindow(window, openWindows, windows, openLinuxApplication, focusWindow, add, getAll)
validateAndAddOpenWindow(window, windows, openLinuxApplication, focusWindow, add, getAll)
}

break;
Expand All @@ -138,7 +137,7 @@ export function applicationEventLoopX11(
window.class = applicationEvent.class;
window.instance = applicationEvent.instance;

validateAndAddOpenWindow(window, openWindows, windows, openLinuxApplication, focusWindow, add, getAll)
validateAndAddOpenWindow(window, windows, openLinuxApplication, focusWindow, add, getAll)
}

break;
Expand All @@ -148,7 +147,7 @@ export function applicationEventLoopX11(
if (window) {
window.windowGroup = applicationEvent.window_group;

validateAndAddOpenWindow(window, openWindows, windows, openLinuxApplication, focusWindow, add, getAll)
validateAndAddOpenWindow(window, windows, openLinuxApplication, focusWindow, add, getAll)
}

break;
Expand All @@ -158,7 +157,7 @@ export function applicationEventLoopX11(
if (window) {
window.protocols = applicationEvent.protocols;

validateAndAddOpenWindow(window, openWindows, windows, openLinuxApplication, focusWindow, add, getAll)
validateAndAddOpenWindow(window, windows, openLinuxApplication, focusWindow, add, getAll)
}

break;
Expand All @@ -168,7 +167,7 @@ export function applicationEventLoopX11(
if (window) {
window.transientFor = applicationEvent.transient_for;

validateAndAddOpenWindow(window, openWindows, windows, openLinuxApplication, focusWindow, add, getAll)
validateAndAddOpenWindow(window, windows, openLinuxApplication, focusWindow, add, getAll)
}

break;
Expand All @@ -178,7 +177,7 @@ export function applicationEventLoopX11(
if (window) {
window.windowTypes = applicationEvent.window_types;

validateAndAddOpenWindow(window, openWindows, windows, openLinuxApplication, focusWindow, add, getAll)
validateAndAddOpenWindow(window, windows, openLinuxApplication, focusWindow, add, getAll)
}

break;
Expand All @@ -188,7 +187,7 @@ export function applicationEventLoopX11(
if (window) {
window.desktopFileName = applicationEvent.desktop_file_name;

validateAndAddOpenWindow(window, openWindows, windows, openLinuxApplication, focusWindow, add, getAll)
validateAndAddOpenWindow(window, windows, openLinuxApplication, focusWindow, add, getAll)
}

break;
Expand All @@ -200,7 +199,6 @@ export function applicationEventLoopX11(

function validateAndAddOpenWindow(
window: X11WindowData,
openWindows: Record<string, OpenWindowData>,
windows: Record<string, X11WindowData>,
openApplication: (appId: string) => (() => void),
focusWindow: (windowId: string) => void,
Expand Down Expand Up @@ -242,7 +240,6 @@ function validateAndAddOpenWindow(
generatedEntrypoint,
window.id,
window.title,
openWindows,
openApplication(appId),
focusWindow,
add,
Expand Down
43 changes: 43 additions & 0 deletions bundled_plugins/gauntlet/src/windows.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { ReactElement } from "react";
import { List } from "@project-gauntlet/api/components";
import { openWindows } from "./window/shared";
import { current_os, wayland } from "gauntlet:bridge/internal-all";
import { focusWaylandWindow } from "./window/wayland";
import { focusX11Window } from "./window/x11";

export default function Windows(): ReactElement {
switch (current_os()) {
case "linux": {
if (wayland()) {
return (
<ListOfWindows focus={(windowId) => focusWaylandWindow(windowId)}/>
)
} else {
return (
<ListOfWindows focus={(windowId) => focusX11Window(windowId)}/>
)
}
}
default: {
return (
<List>
<List.Item title="Not supported on current system"/>
</List>
)
}
}
}

function ListOfWindows({ focus }: { focus: (windowId: string) => void }) {
return (
<List>
{
Object.entries(openWindows)
.map(([_, window]) => (
<List.Item key={window.id} title={window.title} onClick={() => { focus(window.id) }}/>
)
)
}
</List>
)
}

0 comments on commit a5d69e8

Please sign in to comment.