Skip to content

Commit 4ff4c8f

Browse files
committed
Wofi and Bemenu support. Closes #71 and #105
1 parent d319ea5 commit 4ff4c8f

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2021 Scott Hansen <firecat four one five three at gmail dot com>
3+
Copyright (c) 2022 Scott Hansen <firecat four one five three at gmail dot com>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
# Networkmanager-dmenu
22

3-
Manage NetworkManager connections with dmenu, [Rofi][1] or [Bemenu][2] instead of nm-applet
4-
5-
**WARNING** _Two breaking changes 2021-12-08_
6-
7-
1. _ALL_ menu configuration moved to `dmenu_command`, including `-i`. Note
8-
options changed in config.ini.example
9-
2. Minimum Python version now 3.7
3+
Manage NetworkManager connections with dmenu, [Rofi][1], [Bemenu][2] or
4+
[Wofi][7] instead of nm-applet
105

116
## Features
127

@@ -32,7 +27,7 @@ Manage NetworkManager connections with dmenu, [Rofi][1] or [Bemenu][2] instead o
3227

3328
1. Python 3.7+
3429
2. NetworkManager
35-
3. Dmenu, Rofi or bemenu
30+
3. Dmenu (X), Rofi (X or XWayland), Wofi (Wayland) or Bemenu (X or Wayland)
3631
4. Python gobject (PyGObject, python-gobject, etc.)
3732
5. (Debian/Ubuntu based distros) libnm-util-dev and gir1.2-nm-1.0 (you have to
3833
explicitly install the latter on Debian Sid)
@@ -53,8 +48,8 @@ Manage NetworkManager connections with dmenu, [Rofi][1] or [Bemenu][2] instead o
5348
- If using dmenu for passphrase entry (pinentry not set), dmenu options in the
5449
`[dmenu_passphrase]` section of config.ini will set the normal foreground and
5550
background colors to be the same to obscure the passphrase. The [Suckless
56-
password patch][6] `-P` option is supported if that patch is installed. Rofi and
57-
bemenu will use their respective flags for passphrase entry.
51+
password patch][6] `-P` option is supported if that patch is installed. Rofi,
52+
Wofi and Bemenu will use their respective flags for passphrase entry.
5853
- Set default terminal (xterm, urxvtc, etc.) command in config.ini if desired.
5954
- Saved connections can be listed if desired. Set `list_saved = True` under
6055
`[dmenu]` in config.ini. If set to `False`, saved connections are still
@@ -106,3 +101,4 @@ Manage NetworkManager connections with dmenu, [Rofi][1] or [Bemenu][2] instead o
106101
[4]: https://github.com/Woomy4680-exe/Woomy-overlay "Woomy Overlay"
107102
[5]: https://wiki.archlinux.org/index.php/NetworkManager#Set_up_PolicyKit_permissions "PolicyKit permissions"
108103
[6]: https://tools.suckless.org/dmenu/patches/password/ "Suckless password patch"
104+
[7]: https://hg.sr.ht/~scoopta/wofi "Wofi"

networkmanager_dmenu

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,27 @@ def cli_args():
6363
return args
6464

6565

66+
def dmenu_pass(command, color):
67+
"""Check if dmenu passphrase patch is applied and return the correct command
68+
line arg list
69+
70+
Args: command - string
71+
color - obscure color string
72+
Returns: list or None
73+
74+
"""
75+
if command != 'dmenu':
76+
return None
77+
try:
78+
# Check for dmenu password patch
79+
dm_patch = b'P' in subprocess.run(["dmenu", "-h"],
80+
capture_output=True,
81+
check=False).stderr
82+
except FileNotFoundError:
83+
dm_patch = False
84+
return ["-P"] if dm_patch else ["-nb", color, "-nf", color]
85+
86+
6687
def dmenu_cmd(num_lines, prompt="Networks", active_lines=None):
6788
"""Parse config.ini for menu options
6889
@@ -73,9 +94,11 @@ def dmenu_cmd(num_lines, prompt="Networks", active_lines=None):
7394
["dmenu", "-l", "<num_lines>", "-p", "<prompt>", "-i"]
7495
7596
"""
97+
# Create command string
7698
commands = {"dmenu": ["-p", str(prompt)],
7799
"rofi": ["-dmenu", "-p", str(prompt), "-l", str(num_lines)],
78-
"bemenu": ["-p", str(prompt)]}
100+
"bemenu": ["-p", str(prompt)],
101+
"wofi": ["-p", str(prompt)]}
79102
command = shlex.split(CONF.get('dmenu', 'dmenu_command', fallback="dmenu"))
80103
command.extend(cli_args())
81104
command.extend(commands.get(command[0], []))
@@ -87,17 +110,10 @@ def dmenu_cmd(num_lines, prompt="Networks", active_lines=None):
87110
obscure = CONF.getboolean('dmenu_passphrase', 'obscure', fallback=False)
88111
if prompt == "Passphrase" and obscure is True:
89112
obscure_color = CONF.get('dmenu_passphrase', 'obscure_color', fallback='#222222')
90-
try:
91-
# Check for dmenu password patch
92-
dm_patch = b'P' in subprocess.run(["dmenu", "-h"],
93-
capture_output=True,
94-
check=False).stderr
95-
except FileNotFoundError:
96-
dm_patch = False
97-
dmenu = ["-P"] if dm_patch else ["-nb", obscure_color, "-nf", obscure_color]
98-
pass_prompts = {"dmenu": dmenu,
113+
pass_prompts = {"dmenu": dmenu_pass(command[0], obscure_color),
99114
"rofi": ['-password'],
100-
"bemenu": ['x']}
115+
"bemenu": ['-x'],
116+
"wofi": ['-P']}
101117
command.extend(pass_prompts.get(command[0], []))
102118
return command
103119

0 commit comments

Comments
 (0)