Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
i3-switcher
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pavel Kácha
i3-switcher
Commits
22ef0dd5
Commit
22ef0dd5
authored
Feb 21, 2024
by
Pavel Kácha
Browse files
Options
Downloads
Patches
Plain Diff
Bring the code to Py 3
parent
3d3a3bd3
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
dmenu-win.py
+4
-4
4 additions, 4 deletions
dmenu-win.py
dmenu-xdg.py
+6
-6
6 additions, 6 deletions
dmenu-xdg.py
i3-switcher.py
+4
-3
4 additions, 3 deletions
i3-switcher.py
ipc.py
+5
-5
5 additions, 5 deletions
ipc.py
with
19 additions
and
18 deletions
dmenu-win.py
+
4
−
4
View file @
22ef0dd5
#!/usr/bin/python
#!/usr/bin/python
3
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
sys
import
sys
...
@@ -9,7 +9,7 @@ def main(argv):
...
@@ -9,7 +9,7 @@ def main(argv):
sock
=
ipc
.
i3
()
sock
=
ipc
.
i3
()
windows
=
ipc
.
getwin
(
sock
.
command
(
ipc
.
TREE
),
activews
=
False
)
windows
=
ipc
.
getwin
(
sock
.
command
(
ipc
.
TREE
),
activews
=
False
)
dmwindows
=
{}
dmwindows
=
{}
for
w
in
windows
.
iter
values
():
for
w
in
windows
.
values
():
line
=
"
%2d: %s
"
%
(
w
[
"
wsnum
"
],
w
[
"
name
"
])
line
=
"
%2d: %s
"
%
(
w
[
"
wsnum
"
],
w
[
"
name
"
])
dup
=
2
dup
=
2
while
line
in
dmwindows
:
while
line
in
dmwindows
:
...
@@ -17,9 +17,9 @@ def main(argv):
...
@@ -17,9 +17,9 @@ def main(argv):
dup
+=
1
dup
+=
1
dmwindows
[
line
]
=
w
[
"
window
"
]
dmwindows
[
line
]
=
w
[
"
window
"
]
dmenu
=
subprocess
.
Popen
([
'
dmenu
'
]
+
argv
[
1
:],
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
dmenu
=
subprocess
.
Popen
([
'
dmenu
'
]
+
argv
[
1
:],
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
dmenulist
=
"
\n
"
.
join
(
sorted
(
dmwindows
.
iter
keys
())).
encode
(
"
utf-8
"
)
dmenulist
=
"
\n
"
.
join
(
sorted
(
dmwindows
.
keys
())).
encode
(
"
utf-8
"
)
dmenustdout
=
dmenu
.
communicate
(
dmenulist
)[
0
]
dmenustdout
=
dmenu
.
communicate
(
dmenulist
)[
0
]
picked
=
dmenustdout
.
rstrip
(
"
\n
"
).
decode
(
"
utf-8
"
)
picked
=
dmenustdout
.
rstrip
(
b
"
\n
"
).
decode
(
"
utf-8
"
)
if
picked
:
if
picked
:
sock
.
command
(
ipc
.
COMMAND
,
'
[id=
"
%d
"
] focus
'
%
dmwindows
[
picked
])
sock
.
command
(
ipc
.
COMMAND
,
'
[id=
"
%d
"
] focus
'
%
dmwindows
[
picked
])
...
...
This diff is collapsed.
Click to expand it.
dmenu-xdg.py
+
6
−
6
View file @
22ef0dd5
#!/usr/bin/python
#!/usr/bin/python
3
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
os
import
os
...
@@ -26,7 +26,7 @@ def uniq_list(l):
...
@@ -26,7 +26,7 @@ def uniq_list(l):
def
quote
(
s
):
def
quote
(
s
):
res
=
re
.
sub
(
r
'
[`$\\]
'
,
lambda
(
match
)
:
'
\\
'
+
match
.
group
(
0
)
,
s
)
res
=
re
.
sub
(
r
'
[`$\\]
'
,
lambda
match
:
'
\\
'
+
match
.
group
(
0
)
,
s
)
res
=
u
"
\"
"
+
res
+
u
"
\"
"
if
res
!=
s
or
s
==
u
""
else
s
res
=
u
"
\"
"
+
res
+
u
"
\"
"
if
res
!=
s
or
s
==
u
""
else
s
return
res
return
res
...
@@ -55,10 +55,10 @@ def main(argv):
...
@@ -55,10 +55,10 @@ def main(argv):
continue
continue
generic
=
dsk
.
getGenericName
()
generic
=
dsk
.
getGenericName
()
if
not
isinstance
(
generic
,
unicode
):
if
not
isinstance
(
generic
,
str
):
generic
=
generic
.
decode
(
"
utf-8
"
)
generic
=
generic
.
decode
(
"
utf-8
"
)
name
=
dsk
.
getName
()
name
=
dsk
.
getName
()
if
not
isinstance
(
name
,
unicode
):
if
not
isinstance
(
name
,
str
):
name
=
name
.
decode
(
"
utf-8
"
)
name
=
name
.
decode
(
"
utf-8
"
)
dsk
.
name
=
name
# ugly, sure
dsk
.
name
=
name
# ugly, sure
label
=
name
label
=
name
...
@@ -72,9 +72,9 @@ def main(argv):
...
@@ -72,9 +72,9 @@ def main(argv):
pick
[
label
]
=
dsk
pick
[
label
]
=
dsk
dmenu
=
subprocess
.
Popen
([
'
dmenu
'
]
+
argv
[
1
:],
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
dmenu
=
subprocess
.
Popen
([
'
dmenu
'
]
+
argv
[
1
:],
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
dmenulist
=
"
\n
"
.
join
(
sorted
(
pick
.
iter
keys
())).
encode
(
"
utf-8
"
)
dmenulist
=
"
\n
"
.
join
(
sorted
(
pick
.
keys
())).
encode
(
"
utf-8
"
)
dmenustdout
=
dmenu
.
communicate
(
dmenulist
)[
0
]
dmenustdout
=
dmenu
.
communicate
(
dmenulist
)[
0
]
picked
=
dmenustdout
.
rstrip
(
"
\n
"
).
decode
(
"
utf-8
"
)
picked
=
dmenustdout
.
rstrip
(
b
"
\n
"
).
decode
(
"
utf-8
"
)
if
picked
:
if
picked
:
try
:
try
:
dsk
=
pick
[
picked
]
dsk
=
pick
[
picked
]
...
...
This diff is collapsed.
Click to expand it.
i3-switcher.py
+
4
−
3
View file @
22ef0dd5
#!/usr/bin/python
#!/usr/bin/python
3
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
sys
import
sys
...
@@ -58,11 +58,12 @@ def main(argv=None):
...
@@ -58,11 +58,12 @@ def main(argv=None):
clients
=
ipc
.
getwin
(
i3command
.
command
(
ipc
.
TREE
))
clients
=
ipc
.
getwin
(
i3command
.
command
(
ipc
.
TREE
))
sortedclients
=
sorted
(
clients
.
values
(),
key
=
itemgetter
(
"
wsnum
"
,
"
order
"
),
reverse
=
True
)
sortedclients
=
sorted
(
clients
.
values
(),
key
=
itemgetter
(
"
wsnum
"
,
"
order
"
),
reverse
=
True
)
for
c
in
sortedclients
:
for
c
in
sortedclients
:
name
=
c
.
get
(
"
name
"
)
or
str
(
c
)
out
.
append
({
out
.
append
({
u
"
name
"
:
u
"
client
"
,
u
"
name
"
:
u
"
client
"
,
u
"
instance
"
:
str
(
c
[
"
id
"
]),
u
"
instance
"
:
str
(
c
[
"
id
"
]),
u
"
full_text
"
:
unicode
(
c
[
"
name
"
])
,
u
"
full_text
"
:
name
,
u
"
short_text
"
:
unicode
(
c
[
"
name
"
])
[
0
:
20
]
+
u
"
…
"
,
u
"
short_text
"
:
name
[
0
:
20
]
+
u
"
…
"
,
u
"
color
"
:
u
"
#FFFFFF
"
if
c
[
"
focused
"
]
else
u
"
#AAAAAA
"
u
"
color
"
:
u
"
#FFFFFF
"
if
c
[
"
focused
"
]
else
u
"
#AAAAAA
"
})
})
...
...
This diff is collapsed.
Click to expand it.
ipc.py
+
5
−
5
View file @
22ef0dd5
#!/usr/bin/python
#!/usr/bin/python
3
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
socket
import
socket
...
@@ -25,7 +25,7 @@ class i3(object):
...
@@ -25,7 +25,7 @@ class i3(object):
def
send
(
self
,
msg_type
,
payload
=
''
):
def
send
(
self
,
msg_type
,
payload
=
''
):
pld
=
payload
.
encode
(
'
utf-8
'
)
pld
=
payload
.
encode
(
'
utf-8
'
)
msg
=
'
i3-ipc
'
+
struct
.
pack
(
'
II
'
,
len
(
pld
),
msg_type
)
+
pld
msg
=
b
'
i3-ipc
'
+
struct
.
pack
(
'
II
'
,
len
(
pld
),
msg_type
)
+
pld
self
.
socket
.
sendall
(
msg
)
self
.
socket
.
sendall
(
msg
)
...
@@ -43,7 +43,7 @@ class i3(object):
...
@@ -43,7 +43,7 @@ class i3(object):
chunk
=
self
.
socket
.
recv
(
rest
)
chunk
=
self
.
socket
.
recv
(
rest
)
data
.
append
(
chunk
)
data
.
append
(
chunk
)
rest
-=
len
(
chunk
)
rest
-=
len
(
chunk
)
return
""
.
join
(
data
)
return
b
""
.
join
(
data
)
def
close
(
self
):
def
close
(
self
):
...
@@ -75,14 +75,14 @@ def getwin(tree, activews=True):
...
@@ -75,14 +75,14 @@ def getwin(tree, activews=True):
stack
.
extend
(
node
.
get
(
"
floating_nodes
"
,
[]))
stack
.
extend
(
node
.
get
(
"
floating_nodes
"
,
[]))
stack
.
extend
(
node
.
get
(
"
list
"
,
[]))
stack
.
extend
(
node
.
get
(
"
list
"
,
[]))
if
activews
:
if
activews
:
for
w
in
winlist
.
keys
():
for
w
in
list
(
winlist
.
keys
()
)
:
if
winlist
[
w
][
"
wsnum
"
]
!=
wsactive
:
if
winlist
[
w
][
"
wsnum
"
]
!=
wsactive
:
del
winlist
[
w
]
del
winlist
[
w
]
return
winlist
return
winlist
def
printjson
(
d
):
def
printjson
(
d
):
print
json
.
dumps
(
d
,
indent
=
2
,
sort_keys
=
True
)
print
(
json
.
dumps
(
d
,
indent
=
2
,
sort_keys
=
True
)
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment