forked from Shinonome/dots-hyprland
bar: activewindow: more accurate on multimonitor systems
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import "root:/services"
|
||||||
import "root:/modules/common"
|
import "root:/modules/common"
|
||||||
import "root:/modules/common/widgets"
|
import "root:/modules/common/widgets"
|
||||||
import QtQuick
|
import QtQuick
|
||||||
@@ -11,6 +12,10 @@ Item {
|
|||||||
readonly property HyprlandMonitor monitor: Hyprland.monitorFor(bar.screen)
|
readonly property HyprlandMonitor monitor: Hyprland.monitorFor(bar.screen)
|
||||||
readonly property Toplevel activeWindow: ToplevelManager.activeToplevel
|
readonly property Toplevel activeWindow: ToplevelManager.activeToplevel
|
||||||
|
|
||||||
|
property string activeWindowAddress: `0x${activeWindow.HyprlandToplevel.address}`
|
||||||
|
property bool focusingThisMonitor: HyprlandData.activeWorkspace.monitor == monitor.name
|
||||||
|
property var biggestWindow: HyprlandData.biggestWindowForWorkspace(HyprlandData.monitors[root.monitor.id].activeWorkspace.id)
|
||||||
|
|
||||||
implicitWidth: colLayout.implicitWidth
|
implicitWidth: colLayout.implicitWidth
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
@@ -26,7 +31,10 @@ Item {
|
|||||||
font.pixelSize: Appearance.font.pixelSize.smaller
|
font.pixelSize: Appearance.font.pixelSize.smaller
|
||||||
color: Appearance.colors.colSubtext
|
color: Appearance.colors.colSubtext
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
text: root.activeWindow?.activated ? root.activeWindow?.appId : qsTr("Desktop")
|
text: root.focusingThisMonitor && root.activeWindow?.activated && root.biggestWindow ?
|
||||||
|
root.activeWindow?.appId :
|
||||||
|
(root.biggestWindow?.class) ?? qsTr("Desktop")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
@@ -34,7 +42,9 @@ Item {
|
|||||||
font.pixelSize: Appearance.font.pixelSize.small
|
font.pixelSize: Appearance.font.pixelSize.small
|
||||||
color: Appearance.colors.colOnLayer0
|
color: Appearance.colors.colOnLayer0
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
text: root.activeWindow?.activated ? root.activeWindow?.title : `${qsTr("Workspace")} ${monitor.activeWorkspace?.id}`
|
text: root.focusingThisMonitor && root.activeWindow?.activated && root.biggestWindow ?
|
||||||
|
root.activeWindow?.title :
|
||||||
|
(root.biggestWindow?.title) ?? `${qsTr("Workspace")} ${monitor.activeWorkspace?.id}`
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,14 +173,7 @@ Item {
|
|||||||
id: workspaceButtonBackground
|
id: workspaceButtonBackground
|
||||||
implicitWidth: workspaceButtonWidth
|
implicitWidth: workspaceButtonWidth
|
||||||
implicitHeight: workspaceButtonWidth
|
implicitHeight: workspaceButtonWidth
|
||||||
property var biggestWindow: {
|
property var biggestWindow: HyprlandData.biggestWindowForWorkspace(button.workspaceValue)
|
||||||
const windowsInThisWorkspace = HyprlandData.windowList.filter(w => w.workspace.id == button.workspaceValue)
|
|
||||||
return windowsInThisWorkspace.reduce((maxWin, win) => {
|
|
||||||
const maxArea = (maxWin?.size?.[0] ?? 0) * (maxWin?.size?.[1] ?? 0)
|
|
||||||
const winArea = (win?.size?.[0] ?? 0) * (win?.size?.[1] ?? 0)
|
|
||||||
return winArea > maxArea ? win : maxWin
|
|
||||||
}, null)
|
|
||||||
}
|
|
||||||
property var mainAppIconSource: Quickshell.iconPath(AppSearch.guessIcon(biggestWindow?.class), "image-missing")
|
property var mainAppIconSource: Quickshell.iconPath(AppSearch.guessIcon(biggestWindow?.class), "image-missing")
|
||||||
|
|
||||||
StyledText { // Workspace number text
|
StyledText { // Workspace number text
|
||||||
|
|||||||
@@ -15,34 +15,56 @@ Singleton {
|
|||||||
property var windowList: []
|
property var windowList: []
|
||||||
property var addresses: []
|
property var addresses: []
|
||||||
property var windowByAddress: ({})
|
property var windowByAddress: ({})
|
||||||
|
property var workspaces: []
|
||||||
|
property var workspaceIds: []
|
||||||
|
property var workspaceById: ({})
|
||||||
|
property var activeWorkspace: null
|
||||||
property var monitors: []
|
property var monitors: []
|
||||||
property var layers: ({})
|
property var layers: ({})
|
||||||
|
|
||||||
function updateWindowList() {
|
function updateWindowList() {
|
||||||
getClients.running = true
|
getClients.running = true;
|
||||||
getMonitors.running = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateLayers() {
|
function updateLayers() {
|
||||||
getLayers.running = true
|
getLayers.running = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateMonitors() {
|
||||||
|
getMonitors.running = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateWorkspaces() {
|
||||||
|
getWorkspaces.running = true;
|
||||||
|
getActiveWorkspace.running = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateAll() {
|
||||||
|
updateWindowList();
|
||||||
|
updateMonitors();
|
||||||
|
updateLayers();
|
||||||
|
updateWorkspaces();
|
||||||
|
}
|
||||||
|
|
||||||
|
function biggestWindowForWorkspace(workspaceId) {
|
||||||
|
const windowsInThisWorkspace = HyprlandData.windowList.filter(w => w.workspace.id == workspaceId);
|
||||||
|
return windowsInThisWorkspace.reduce((maxWin, win) => {
|
||||||
|
const maxArea = (maxWin?.size?.[0] ?? 0) * (maxWin?.size?.[1] ?? 0);
|
||||||
|
const winArea = (win?.size?.[0] ?? 0) * (win?.size?.[1] ?? 0);
|
||||||
|
return winArea > maxArea ? win : maxWin;
|
||||||
|
}, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
updateWindowList()
|
updateAll();
|
||||||
updateLayers()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: Hyprland
|
target: Hyprland
|
||||||
|
|
||||||
function onRawEvent(event) {
|
function onRawEvent(event) {
|
||||||
// Filter out redundant old v1 events for the same thing
|
// console.log("Hyprland raw event:", event.name);
|
||||||
if(event.name in [
|
updateAll()
|
||||||
"activewindow", "focusedmon", "monitoradded",
|
|
||||||
"createworkspace", "destroyworkspace", "moveworkspace",
|
|
||||||
"activespecial", "movewindow", "windowtitle"
|
|
||||||
]) return ;
|
|
||||||
updateWindowList()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,15 +72,15 @@ Singleton {
|
|||||||
id: getClients
|
id: getClients
|
||||||
command: ["bash", "-c", "hyprctl clients -j | jq -c"]
|
command: ["bash", "-c", "hyprctl clients -j | jq -c"]
|
||||||
stdout: SplitParser {
|
stdout: SplitParser {
|
||||||
onRead: (data) => {
|
onRead: data => {
|
||||||
root.windowList = JSON.parse(data)
|
root.windowList = JSON.parse(data);
|
||||||
let tempWinByAddress = {}
|
let tempWinByAddress = {};
|
||||||
for (var i = 0; i < root.windowList.length; ++i) {
|
for (var i = 0; i < root.windowList.length; ++i) {
|
||||||
var win = root.windowList[i]
|
var win = root.windowList[i];
|
||||||
tempWinByAddress[win.address] = win
|
tempWinByAddress[win.address] = win;
|
||||||
}
|
}
|
||||||
root.windowByAddress = tempWinByAddress
|
root.windowByAddress = tempWinByAddress;
|
||||||
root.addresses = root.windowList.map((win) => win.address)
|
root.addresses = root.windowList.map(win => win.address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,8 +89,8 @@ Singleton {
|
|||||||
id: getMonitors
|
id: getMonitors
|
||||||
command: ["bash", "-c", "hyprctl monitors -j | jq -c"]
|
command: ["bash", "-c", "hyprctl monitors -j | jq -c"]
|
||||||
stdout: SplitParser {
|
stdout: SplitParser {
|
||||||
onRead: (data) => {
|
onRead: data => {
|
||||||
root.monitors = JSON.parse(data)
|
root.monitors = JSON.parse(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,10 +99,36 @@ Singleton {
|
|||||||
id: getLayers
|
id: getLayers
|
||||||
command: ["bash", "-c", "hyprctl layers -j | jq -c"]
|
command: ["bash", "-c", "hyprctl layers -j | jq -c"]
|
||||||
stdout: SplitParser {
|
stdout: SplitParser {
|
||||||
onRead: (data) => {
|
onRead: data => {
|
||||||
root.layers = JSON.parse(data)
|
root.layers = JSON.parse(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: getWorkspaces
|
||||||
|
command: ["bash", "-c", "hyprctl workspaces -j | jq -c"]
|
||||||
|
stdout: SplitParser {
|
||||||
|
onRead: data => {
|
||||||
|
root.workspaces = JSON.parse(data);
|
||||||
|
let tempWorkspaceById = {};
|
||||||
|
for (var i = 0; i < root.workspaces.length; ++i) {
|
||||||
|
var ws = root.workspaces[i];
|
||||||
|
tempWorkspaceById[ws.id] = ws;
|
||||||
|
}
|
||||||
|
root.workspaceById = tempWorkspaceById;
|
||||||
|
root.workspaceIds = root.workspaces.map(ws => ws.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: getActiveWorkspace
|
||||||
|
command: ["bash", "-c", "hyprctl activeworkspace -j | jq -c"]
|
||||||
|
stdout: SplitParser {
|
||||||
|
onRead: data => {
|
||||||
|
root.activeWorkspace = JSON.parse(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user