-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathPanelScreens.java
More file actions
182 lines (172 loc) · 8.38 KB
/
PanelScreens.java
File metadata and controls
182 lines (172 loc) · 8.38 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package io.github.humbleui.jwm.examples;
import java.util.function.*;
import io.github.humbleui.jwm.*;
import io.github.humbleui.skija.*;
import io.github.humbleui.types.*;
public class PanelScreens extends Panel {
public EventWindowResize lastResize = new EventWindowResize(0, 0, 0, 0);
public EventWindowMove lastMove = new EventWindowMove(0, 0);
public Paint stroke = new Paint().setMode(PaintMode.STROKE).setColor(0x80FFFFFF);
public Paint fill = new Paint().setColor(0x20FFFFFF);
public Paint white = new Paint().setColor(0xFFFFFFFF);
public int idx = 0;
public Options titleStyles = new Options("Default", "Hidden");
public PanelScreens(Window window) {
super(window);
if (Platform.MACOS == Platform.CURRENT) {
titleStyles = new Options("Default", "Hidden", "Transparent", "Unified", "Unified Compact", "Unified Transparent", "Unified Compact Transparent");
} else if (Platform.X11 == Platform.CURRENT || Platform.WAYLAND == Platform.CURRENT) {
titleStyles = new Options("Default", "Hidden");
}
}
public void setTitleStyle(String style) {
titleStyles.set(style);
if (Platform.MACOS == Platform.CURRENT) {
WindowMac w = (WindowMac) window;
switch (style) {
case "Default" -> {
w.setTitlebarStyle(WindowMacTitlebarStyle.DEFAULT);
w.setFullSizeContentView(false);
}
case "Hidden" -> {
window.setTitlebarVisible(false);
}
case "Transparent" -> {
window.setTitlebarVisible(true);
w.setTitlebarStyle(WindowMacTitlebarStyle.DEFAULT);
w.setFullSizeContentView(true);
w.setTrafficLightPosition(0, 0);
}
case "Unified" -> {
w.setTitlebarStyle(WindowMacTitlebarStyle.UNIFIED);
w.setFullSizeContentView(false);
}
case "Unified Compact" -> {
w.setTitlebarStyle(WindowMacTitlebarStyle.UNIFIED_COMPACT);
}
case "Unified Transparent" -> {
w.setTitlebarStyle(WindowMacTitlebarStyle.UNIFIED);
w.setFullSizeContentView(true);
}
case "Unified Compact Transparent" -> {
w.setTitlebarStyle(WindowMacTitlebarStyle.UNIFIED_COMPACT);
w.setFullSizeContentView(true);
}
}
} else if (Platform.X11 == Platform.CURRENT) {
WindowX11 w = (WindowX11) window;
switch (style) {
case "Default" ->
w.setTitlebarVisible(true);
case "Hidden" ->
w.setTitlebarVisible(false);
}
} else if (Platform.WAYLAND == Platform.CURRENT) {
WindowWayland w = (WindowWayland) window;
switch (style) {
case "Default" ->
w.setTitlebarVisible(true);
case "Hidden" ->
w.setTitlebarVisible(false);
}
}
}
@Override
public void accept(Event e) {
float scale = window.getScreen().getScale();
if (e instanceof EventKey eventKey) {
if (eventKey.isPressed() == true && eventKey.isModifierDown(Example.MODIFIER)) {
switch (eventKey.getKey()) {
case DIGIT1 ->
window.minimize();
case DIGIT2 ->
window.maximize();
case DIGIT3 ->
window.restore();
case DIGIT4 -> {
window.setVisible(false);
}
case DIGIT5 -> {
Screen[] screens = App.getScreens();
idx = (idx + 1) % (screens.length * 5);
IRect bounds = screens[idx / 5].getWorkArea();
switch (idx % 5) {
case 0 -> window.setWindowPosition(bounds.getLeft() + bounds.getWidth() / 4, bounds.getTop() + bounds.getHeight() / 4);
case 1 -> window.setWindowPosition(bounds.getLeft(), bounds.getTop());
case 2 -> window.setWindowPosition(bounds.getLeft() + bounds.getWidth() / 2, bounds.getTop());
case 3 -> window.setWindowPosition(bounds.getLeft(), bounds.getTop() + bounds.getHeight() / 2);
case 4 -> window.setWindowPosition(bounds.getLeft() + bounds.getWidth() / 2, bounds.getTop() + bounds.getHeight() / 2);
}
}
case DIGIT6 -> {
IRect bounds = window.getScreen().getWorkArea();
int width = (int) (((int) ((bounds.getWidth() / 2) / scale)) * scale);
int height = (int) (((int) ((bounds.getHeight() / 2) / scale)) * scale);
if (window.getWindowRect().getWidth() != width || window.getWindowRect().getHeight() != height) {
window.setWindowSize(width, height);
} else {
window.setContentSize(width, height);
}
}
case T -> {
setTitleStyle(titleStyles.next());
window.focus();
}
}
}
} if (e instanceof EventWindowResize ee) {
lastResize = ee;
window.requestFrame();
} else if (e instanceof EventWindowMove ee) {
lastMove = ee;
window.requestFrame();
}
}
public void drawRect(Canvas canvas, IRect rect) {
canvas.drawRect(Rect.makeXYWH(rect.getLeft(), rect.getTop(), rect.getWidth(), rect.getHeight()), fill);
canvas.drawRect(Rect.makeXYWH(rect.getLeft(), rect.getTop(), rect.getWidth(), rect.getHeight()), stroke);
}
@Override
public void paintImpl(Canvas canvas, int width, int height, float scale) {
float minX = 0, minY = 0, maxX = 0, maxY = 0;
for (var screen: App.getScreens()) {
var bounds = screen.getBounds();
minX = Math.min(minX, bounds.getLeft());
minY = Math.min(minY, bounds.getTop());
maxX = Math.max(maxX, bounds.getRight());
maxY = Math.max(maxY, bounds.getBottom());
}
canvas.save();
float scale2 = Math.min((width - Example.PADDING * 2) / (maxX - minX),
(height - Example.PADDING * 2) / (maxY - minY));
canvas.translate(Example.PADDING, Example.PADDING);
canvas.scale(scale2, scale2);
canvas.translate(-minX, (height - Example.PADDING * 2) / scale2 - maxY);
stroke.setStrokeWidth(1 * scale / scale2);
for (var screen: App.getScreens()) {
stroke.setColor(screen.isPrimary() ? 0x80CC3333 : 0x80FFFFFF);
drawRect(canvas, screen.getBounds());
drawRect(canvas, screen.getWorkArea());
}
IRect windowRect = window.getWindowRect();
drawRect(canvas, windowRect);
drawRect(canvas, window.getContentRectAbsolute());
stroke.setColor(0x80CC3333);
drawRect(canvas, IRect.makeXYWH(lastMove.getWindowLeft(), lastMove.getWindowTop(), lastResize.getWindowWidth(), lastResize.getWindowHeight()));
canvas.restore();
var contentRect = window.getContentRect();
var capHeight = Example.FONT12.getMetrics().getCapHeight();
var lineHeight = capHeight + (int) 8 * scale;
canvas.save();
canvas.translate(Example.PADDING, Example.PADDING + capHeight);
canvas.drawString("Position: " + windowRect.getLeft() + ", " + windowRect.getTop(), 0, 0, Example.FONT12, white);
canvas.translate(0, lineHeight);
canvas.drawString("Window size: " + windowRect.getWidth() + ", " + windowRect.getHeight(), 0, 0, Example.FONT12, white);
canvas.translate(0, lineHeight);
canvas.drawString("Content size: " + contentRect.getWidth() + ", " + contentRect.getHeight(), 0, 0, Example.FONT12, white);
canvas.translate(0, lineHeight);
canvas.drawString("Titlebar: " + titleStyles.get(), 0, 0, Example.FONT12, white);
canvas.translate(0, lineHeight);
canvas.restore();
}
}