fix: fix + simplify workspaces
This commit is contained in:
parent
cd76f0d7ac
commit
9db46e3c9f
3 changed files with 28 additions and 129 deletions
|
|
@ -64,6 +64,7 @@ Item {
|
||||||
localWorkspaces.append(ws);
|
localWorkspaces.append(ws);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
workspaceRepeater.model = localWorkspaces;
|
workspaceRepeater.model = localWorkspaces;
|
||||||
updateWorkspaceFocus();
|
updateWorkspaceFocus();
|
||||||
}
|
}
|
||||||
|
|
@ -176,9 +177,6 @@ Item {
|
||||||
scale: model.isFocused ? 1.0 : 0.9
|
scale: model.isFocused ? 1.0 : 0.9
|
||||||
z: 0
|
z: 0
|
||||||
|
|
||||||
ToolTip.visible: pillMouseArea.containsMouse
|
|
||||||
ToolTip.text: `${model.output}:${model.idx} (ID: ${model.id})`
|
|
||||||
ToolTip.delay: 500
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: pillMouseArea
|
id: pillMouseArea
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,10 @@ Singleton {
|
||||||
|
|
||||||
property var workspaces: []
|
property var workspaces: []
|
||||||
property var windows: []
|
property var windows: []
|
||||||
property var outputs: []
|
|
||||||
property int focusedWindowIndex: -1
|
property int focusedWindowIndex: -1
|
||||||
property bool inOverview: false
|
property bool inOverview: false
|
||||||
|
|
||||||
// Reactive property for focused window title
|
|
||||||
property string focusedWindowTitle: "(No active window)"
|
property string focusedWindowTitle: "(No active window)"
|
||||||
|
|
||||||
// Update the focusedWindowTitle whenever relevant properties change
|
|
||||||
function updateFocusedWindowTitle() {
|
function updateFocusedWindowTitle() {
|
||||||
if (focusedWindowIndex >= 0 && focusedWindowIndex < windows.length) {
|
if (focusedWindowIndex >= 0 && focusedWindowIndex < windows.length) {
|
||||||
focusedWindowTitle = windows[focusedWindowIndex].title || "(Unnamed window)";
|
focusedWindowTitle = windows[focusedWindowIndex].title || "(Unnamed window)";
|
||||||
|
|
@ -25,57 +21,53 @@ Singleton {
|
||||||
focusedWindowTitle = "(No active window)";
|
focusedWindowTitle = "(No active window)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Call updateFocusedWindowTitle on changes
|
|
||||||
onWindowsChanged: updateFocusedWindowTitle()
|
onWindowsChanged: updateFocusedWindowTitle()
|
||||||
onFocusedWindowIndexChanged: updateFocusedWindowTitle()
|
onFocusedWindowIndexChanged: updateFocusedWindowTitle()
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
eventStream.running = true;
|
eventStream.running = true;
|
||||||
outputsProcess.running = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: outputsProcess
|
id: workspaceProcess
|
||||||
running: false
|
running: false
|
||||||
command: ["niri", "msg", "--json", "outputs"]
|
command: ["niri", "msg", "--json", "workspaces"]
|
||||||
|
|
||||||
stdout: SplitParser {
|
stdout: SplitParser {
|
||||||
onRead: function(line) {
|
onRead: function(line) {
|
||||||
try {
|
try {
|
||||||
const outputsData = JSON.parse(line);
|
const workspacesData = JSON.parse(line);
|
||||||
const outputsList = [];
|
const workspacesList = [];
|
||||||
|
|
||||||
// Process each output
|
for (const ws of workspacesData) {
|
||||||
for (const [connector, data] of Object.entries(outputsData)) {
|
workspacesList.push({
|
||||||
const logical = data.logical || {};
|
id: ws.id,
|
||||||
outputsList.push({
|
idx: ws.idx,
|
||||||
connector: connector,
|
name: ws.name || "",
|
||||||
name: data.name || connector,
|
output: ws.output || "",
|
||||||
make: data.make || "",
|
isFocused: ws.is_focused === true,
|
||||||
model: data.model || "",
|
isActive: ws.is_active === true,
|
||||||
x: logical.x || 0,
|
isUrgent: ws.is_urgent === true,
|
||||||
y: logical.y || 0,
|
activeWindowId: ws.active_window_id
|
||||||
width: logical.width || 1920,
|
|
||||||
height: logical.height || 1080,
|
|
||||||
scale: logical.scale || 1.0,
|
|
||||||
transform: logical.transform || "Normal"
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort outputs by position (left to right, top to bottom)
|
workspacesList.sort((a, b) => {
|
||||||
outputsList.sort((a, b) => {
|
if (a.output !== b.output) {
|
||||||
if (a.x !== b.x) return a.x - b.x;
|
return a.output.localeCompare(b.output);
|
||||||
return a.y - b.y;
|
}
|
||||||
|
return a.id - b.id;
|
||||||
});
|
});
|
||||||
|
|
||||||
root.outputs = outputsList;
|
root.workspaces = workspacesList;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to parse outputs:", e, line);
|
console.error("Failed to parse workspaces:", e, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: eventStream
|
id: eventStream
|
||||||
running: false
|
running: false
|
||||||
|
|
@ -85,45 +77,13 @@ Singleton {
|
||||||
onRead: data => {
|
onRead: data => {
|
||||||
try {
|
try {
|
||||||
const event = JSON.parse(data.trim());
|
const event = JSON.parse(data.trim());
|
||||||
|
|
||||||
// Handle different event types
|
|
||||||
if (event.WorkspacesChanged) {
|
if (event.WorkspacesChanged) {
|
||||||
try {
|
workspaceProcess.running = true;
|
||||||
const workspacesData = event.WorkspacesChanged.workspaces;
|
|
||||||
const workspacesList = [];
|
|
||||||
|
|
||||||
// Process each workspace
|
|
||||||
for (const ws of workspacesData) {
|
|
||||||
workspacesList.push({
|
|
||||||
id: ws.id,
|
|
||||||
idx: ws.idx,
|
|
||||||
name: ws.name || "",
|
|
||||||
output: ws.output || "",
|
|
||||||
isFocused: ws.is_focused === true,
|
|
||||||
isActive: ws.is_active === true,
|
|
||||||
isUrgent: ws.is_urgent === true,
|
|
||||||
activeWindowId: ws.active_window_id
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort workspaces by output name and then by ID
|
|
||||||
workspacesList.sort((a, b) => {
|
|
||||||
if (a.output !== b.output) {
|
|
||||||
return a.output.localeCompare(b.output);
|
|
||||||
}
|
|
||||||
return a.id - b.id;
|
|
||||||
});
|
|
||||||
|
|
||||||
root.workspaces = workspacesList;
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Error parsing workspaces event:", e);
|
|
||||||
}
|
|
||||||
} else if (event.WindowsChanged) {
|
} else if (event.WindowsChanged) {
|
||||||
try {
|
try {
|
||||||
const windowsData = event.WindowsChanged.windows;
|
const windowsData = event.WindowsChanged.windows;
|
||||||
const windowsList = [];
|
const windowsList = [];
|
||||||
|
|
||||||
// Process each window
|
|
||||||
for (const win of windowsData) {
|
for (const win of windowsData) {
|
||||||
windowsList.push({
|
windowsList.push({
|
||||||
id: win.id,
|
id: win.id,
|
||||||
|
|
@ -134,12 +94,8 @@ Singleton {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort windows by ID
|
|
||||||
windowsList.sort((a, b) => a.id - b.id);
|
windowsList.sort((a, b) => a.id - b.id);
|
||||||
|
|
||||||
root.windows = windowsList;
|
root.windows = windowsList;
|
||||||
|
|
||||||
// Find focused window index
|
|
||||||
for (let i = 0; i < windowsList.length; i++) {
|
for (let i = 0; i < windowsList.length; i++) {
|
||||||
if (windowsList[i].isFocused) {
|
if (windowsList[i].isFocused) {
|
||||||
root.focusedWindowIndex = i;
|
root.focusedWindowIndex = i;
|
||||||
|
|
@ -150,19 +106,7 @@ Singleton {
|
||||||
console.error("Error parsing windows event:", e);
|
console.error("Error parsing windows event:", e);
|
||||||
}
|
}
|
||||||
} else if (event.WorkspaceActivated) {
|
} else if (event.WorkspaceActivated) {
|
||||||
try {
|
workspaceProcess.running = true;
|
||||||
const focusedId = parseInt(event.WorkspaceActivated.id);
|
|
||||||
|
|
||||||
// Update isFocused flag on all workspaces
|
|
||||||
for (let i = 0; i < root.workspaces.length; i++) {
|
|
||||||
// Set isFocused to true only for the activated workspace
|
|
||||||
root.workspaces[i].isFocused = (root.workspaces[i].id === focusedId);
|
|
||||||
}
|
|
||||||
|
|
||||||
root.workspacesChanged();
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Error parsing workspace activation event:", e);
|
|
||||||
}
|
|
||||||
} else if (event.WindowFocusChanged) {
|
} else if (event.WindowFocusChanged) {
|
||||||
try {
|
try {
|
||||||
const focusedId = event.WindowFocusChanged.id;
|
const focusedId = event.WindowFocusChanged.id;
|
||||||
|
|
|
||||||
|
|
@ -128,49 +128,6 @@ Singleton {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const tempArray = [];
|
|
||||||
for (let i = 0; i < workspaces.count; i++) {
|
|
||||||
tempArray.push({
|
|
||||||
id: workspaces.get(i).id,
|
|
||||||
idx: workspaces.get(i).idx,
|
|
||||||
name: workspaces.get(i).name,
|
|
||||||
output: workspaces.get(i).output,
|
|
||||||
isActive: workspaces.get(i).isActive,
|
|
||||||
isFocused: workspaces.get(i).isFocused,
|
|
||||||
isUrgent: workspaces.get(i).isUrgent
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const outputPositions = {};
|
|
||||||
if (isNiri && Niri.outputs) {
|
|
||||||
for (let i = 0; i < Niri.outputs.length; i++) {
|
|
||||||
const output = Niri.outputs[i];
|
|
||||||
outputPositions[output.connector] = output.x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tempArray.sort((a, b) => {
|
|
||||||
if (a.output !== b.output) {
|
|
||||||
if (isNiri && Niri.outputs && Niri.outputs.length > 0) {
|
|
||||||
const outputA = Niri.outputs.find(o => o.connector === a.output);
|
|
||||||
const outputB = Niri.outputs.find(o => o.connector === b.output);
|
|
||||||
|
|
||||||
if (outputA && outputB) {
|
|
||||||
return outputA.x - outputB.x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return a.output.localeCompare(b.output);
|
|
||||||
}
|
|
||||||
|
|
||||||
return a.id - b.id;
|
|
||||||
});
|
|
||||||
|
|
||||||
workspaces.clear();
|
|
||||||
for (let i = 0; i < tempArray.length; i++) {
|
|
||||||
const ws = tempArray[i];
|
|
||||||
workspaces.append(ws);
|
|
||||||
}
|
|
||||||
workspacesChanged();
|
workspacesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue