1
1
import logging
2
2
import time
3
+ from typing import Dict , List
3
4
4
5
import i3ipc
5
6
@@ -35,10 +36,23 @@ def make_window(self, command: str) -> None:
35
36
time .sleep (0.25 )
36
37
37
38
def resize_width (self , window_title_regex : str , container_percentage : int ) -> None :
38
- pass
39
+ window = self ._get_window (window_title_regex )
40
+ window .command ("focus" )
41
+ window .command (f"resize set width { container_percentage } ppt" )
39
42
40
43
def resize_height (self , window_title_regex : str , container_percentage : int ) -> None :
41
- pass
44
+ window = self ._get_window (window_title_regex )
45
+ window .command ("focus" )
46
+ window .command (f"resize set height { container_percentage } ppt" )
47
+
48
+ def get_window_sizes (self ) -> Dict [str , Dict [str , float ]]:
49
+ return {
50
+ window .name : {
51
+ "width" : window .window_rect .width ,
52
+ "height" : window .window_rect .height ,
53
+ }
54
+ for window in self ._get_windows_in_current_workspace ()
55
+ }
42
56
43
57
def _get_window (self , window_title_regex : str ) -> i3ipc .Con :
44
58
tree = self ._sway .get_tree ()
@@ -54,13 +68,7 @@ def _get_window(self, window_title_regex: str) -> i3ipc.Con:
54
68
)
55
69
return windows [0 ]
56
70
57
- @property
58
- def num_workspace_windows (self ) -> int :
59
- """Get the number of windows open on the current workspace
60
-
61
- The current workspace must not be a "named workspace"
62
- https://i3ipc-python.readthedocs.io/en/latest/replies.html#i3ipc.WorkspaceReply
63
- """
71
+ def _get_windows_in_current_workspace (self ) -> List [i3ipc .Con ]:
64
72
workspaces = self ._sway .get_workspaces ()
65
73
for workspace in workspaces :
66
74
if workspace .focused :
@@ -70,11 +78,20 @@ def num_workspace_windows(self) -> int:
70
78
break
71
79
else :
72
80
raise RuntimeError ("There is no current workspace" )
73
- num_windows = 0
81
+ windows_in_current_workspace = []
74
82
for container in self ._sway .get_tree ().leaves ():
75
83
logging .debug (
76
84
f'"{ container .name } " is in workspace { container .workspace ().num } '
77
85
)
78
86
if container .workspace ().num == current_workspace_num :
79
- num_windows += 1
80
- return num_windows
87
+ windows_in_current_workspace .append (container )
88
+ return windows_in_current_workspace
89
+
90
+ @property
91
+ def num_workspace_windows (self ) -> int :
92
+ """Get the number of windows open on the current workspace
93
+
94
+ The current workspace must not be a "named workspace"
95
+ https://i3ipc-python.readthedocs.io/en/latest/replies.html#i3ipc.WorkspaceReply
96
+ """
97
+ return len (self ._get_windows_in_current_workspace ())
0 commit comments