summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif/shell/quickshell/WorkspaceSwitcher.qml
blob: 9546abb4d4d51f8713cc68e921e9d7a966b07647 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import Quickshell
import QtQuick
import qs.Services
import Quickshell.Widgets

Row {
  id: workspaces

  property var ignoreWorkspaces: @ignore_workspaces@

  height: parent.height
  anchors.verticalCenter: parent.verticalCenter
  spacing: 0

  Repeater {
    model: ScriptModel {
      values: {
	let currWorkspaces = NiriService.workspaces;
	const ignoreWorkspaces = Array.from(workspaces.ignoreWorkspaces);
	currWorkspaces = currWorkspaces.filter(ws => ws.is_active || ignoreWorkspaces.every(iws => iws !== ws.name));
	currWorkspaces.sort((a, b) => {
	  if (NiriService.outputs?.[a.output]?.logical?.x !== NiriService.outputs?.[b.output]?.logical?.x)
	    return NiriService.outputs?.[a.output]?.logical?.x - NiriService.outputs?.[b.output]?.logical?.x
	  if (NiriService.outputs?.[a.output]?.logical?.y !== NiriService.outputs?.[b.output]?.logical?.y)
	    return NiriService.outputs?.[a.output]?.logical?.y - NiriService.outputs?.[b.output]?.logical?.y
	  return a.idx - b.idx;
	});
	return currWorkspaces;
      }
    }

    Item {
      id: wsItem

      property var workspaceData: modelData

      width: wsLabel.contentWidth + 8
      height: parent.height
      anchors.verticalCenter: parent.verticalCenter

      WrapperMouseArea {
	id: mouseArea

	anchors.fill: parent

	hoverEnabled: true
	cursorShape: Qt.PointingHandCursor
	enabled: true
	onClicked: {
	  NiriService.sendCommand({ "Action": { "FocusWorkspace": { "reference": { "Id": workspaceData.id } } } }, _ => {})
	}

	Rectangle {
	  anchors.fill: parent

	  color: {
	    if (mouseArea.containsMouse) {
	      return "#33808080";
	    }
	    return "transparent";
	  }

	  Text {
	    id: wsLabel

	    anchors.centerIn: parent

	    font.pointSize: 10
	    font.family: "Fira Sans"
	    color: {
	      if (workspaceData.is_active)
		return "#23fd00";
	      if (workspaceData.active_window_id === null)
		return "#555";
	      return "white";
	    }

	    text: workspaceData.name ? workspaceData.name : workspaceData.idx
	  }
	}
      }
    }
  }
}