Fix SIM2 QMI UIM provisioning, auto-enable ModemManager, PIN auto-prompt, call audio, and Dunst clearing
This commit is contained in:
+107
-24
@@ -816,6 +816,97 @@ write_str_file(const char *path, const char *val)
|
||||
return n > 0;
|
||||
}
|
||||
|
||||
static int
|
||||
dunst_window_visible(void)
|
||||
{
|
||||
if (!dpy)
|
||||
return 0;
|
||||
Window r_ret, p_ret, *children = NULL;
|
||||
unsigned int nchildren = 0;
|
||||
int found = 0;
|
||||
if (!XQueryTree(dpy, root, &r_ret, &p_ret, &children, &nchildren) || !children)
|
||||
return 0;
|
||||
for (unsigned int i = 0; i < nchildren; i++) {
|
||||
XWindowAttributes wa;
|
||||
if (!XGetWindowAttributes(dpy, children[i], &wa) || wa.map_state != IsViewable)
|
||||
continue;
|
||||
XClassHint ch = { NULL, NULL };
|
||||
if (XGetClassHint(dpy, children[i], &ch)) {
|
||||
if ((ch.res_class && strcasecmp(ch.res_class, "Dunst") == 0) ||
|
||||
(ch.res_name && strcasecmp(ch.res_name, "dunst") == 0))
|
||||
found = 1;
|
||||
if (ch.res_name)
|
||||
XFree(ch.res_name);
|
||||
if (ch.res_class)
|
||||
XFree(ch.res_class);
|
||||
if (found)
|
||||
break;
|
||||
}
|
||||
}
|
||||
XFree(children);
|
||||
return found;
|
||||
}
|
||||
|
||||
static void
|
||||
unmap_dunst_windows(void)
|
||||
{
|
||||
if (!dpy)
|
||||
return;
|
||||
Window r_ret, p_ret, *children = NULL;
|
||||
unsigned int nchildren = 0;
|
||||
int unmapped = 0;
|
||||
if (!XQueryTree(dpy, root, &r_ret, &p_ret, &children, &nchildren) || !children)
|
||||
return;
|
||||
for (unsigned int i = 0; i < nchildren; i++) {
|
||||
XClassHint ch = { NULL, NULL };
|
||||
if (XGetClassHint(dpy, children[i], &ch)) {
|
||||
if ((ch.res_class && strcasecmp(ch.res_class, "Dunst") == 0) ||
|
||||
(ch.res_name && strcasecmp(ch.res_name, "dunst") == 0)) {
|
||||
XUnmapWindow(dpy, children[i]);
|
||||
unmapped = 1;
|
||||
}
|
||||
if (ch.res_name)
|
||||
XFree(ch.res_name);
|
||||
if (ch.res_class)
|
||||
XFree(ch.res_class);
|
||||
}
|
||||
}
|
||||
XFree(children);
|
||||
if (unmapped)
|
||||
XFlush(dpy);
|
||||
}
|
||||
|
||||
static void
|
||||
clear_all_notifications_now(void)
|
||||
{
|
||||
const char *ndir = getenv("SXMO_NOTIFDIR");
|
||||
char default_dir[256];
|
||||
if (!ndir || !ndir[0]) {
|
||||
const char *home = getenv("HOME");
|
||||
snprintf(default_dir, sizeof(default_dir), "%s/.local/share/sxmo/notifications",
|
||||
(home && home[0]) ? home : "/home/user");
|
||||
ndir = default_dir;
|
||||
}
|
||||
DIR *d = opendir(ndir);
|
||||
if (d) {
|
||||
struct dirent *ent;
|
||||
while ((ent = readdir(d)) != NULL) {
|
||||
if (ent->d_name[0] == '.')
|
||||
continue;
|
||||
char fpath[512];
|
||||
snprintf(fpath, sizeof(fpath), "%s/%s", ndir, ent->d_name);
|
||||
unlink(fpath);
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
unmap_dunst_windows();
|
||||
spawn_detached_sh(
|
||||
"dunstctl close-all >/dev/null 2>&1; "
|
||||
"dunstctl history-clear >/dev/null 2>&1; "
|
||||
"pkill -x dunstify >/dev/null 2>&1; "
|
||||
"sxmo_hook_statusbar.sh notifications >/dev/null 2>&1");
|
||||
}
|
||||
|
||||
static void
|
||||
handle_builtin_toggle(const char *toggle_name)
|
||||
{
|
||||
@@ -914,27 +1005,7 @@ handle_builtin_toggle(const char *toggle_name)
|
||||
}
|
||||
spawn_detached_sh("sxmo_hook_statusbar.sh audio");
|
||||
} else if (strcmp(toggle_name, "notif_clear_all") == 0) {
|
||||
const char *ndir = getenv("SXMO_NOTIFDIR");
|
||||
char default_dir[256];
|
||||
if (!ndir || !ndir[0]) {
|
||||
const char *home = getenv("HOME");
|
||||
snprintf(default_dir, sizeof(default_dir), "%s/.local/share/sxmo/notifications",
|
||||
(home && home[0]) ? home : "/home/user");
|
||||
ndir = default_dir;
|
||||
}
|
||||
DIR *d = opendir(ndir);
|
||||
if (d) {
|
||||
struct dirent *ent;
|
||||
while ((ent = readdir(d)) != NULL) {
|
||||
if (ent->d_name[0] == '.')
|
||||
continue;
|
||||
char fpath[512];
|
||||
snprintf(fpath, sizeof(fpath), "%s/%s", ndir, ent->d_name);
|
||||
unlink(fpath);
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
spawn_detached_sh("sxmo_hook_statusbar.sh notifs");
|
||||
clear_all_notifications_now();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1031,7 +1102,10 @@ activate_selection(unsigned int ev_state)
|
||||
fclose(fp);
|
||||
}
|
||||
unlink(fpath);
|
||||
spawn_detached_sh("sxmo_hook_statusbar.sh notifs");
|
||||
unmap_dunst_windows();
|
||||
spawn_detached_sh(
|
||||
"dunstctl close-all >/dev/null 2>&1; "
|
||||
"sxmo_hook_statusbar.sh notifications >/dev/null 2>&1");
|
||||
hide_menu();
|
||||
menu_mode = MODE_NONE;
|
||||
if (action_cmd[0] && strcmp(action_cmd, "none") != 0)
|
||||
@@ -1040,6 +1114,11 @@ activate_selection(unsigned int ev_state)
|
||||
}
|
||||
if (strncmp(act, "@toggle:", 8) == 0) {
|
||||
handle_builtin_toggle(act + 8);
|
||||
if (strcmp(act + 8, "notif_clear_all") == 0) {
|
||||
hide_menu();
|
||||
menu_mode = MODE_NONE;
|
||||
return;
|
||||
}
|
||||
char cur_menu[64];
|
||||
snprintf(cur_menu, sizeof(cur_menu), "%s", current_builtin_menu);
|
||||
open_builtin_menu(cur_menu, cur_idx);
|
||||
@@ -1906,9 +1985,13 @@ open_builtin_menu(const char *menu_name, int keep_idx)
|
||||
reset_session_defaults(1, "Sys");
|
||||
append_active_call_entries();
|
||||
int nnotifs = count_notifications();
|
||||
int dunst_vis = dunst_window_visible();
|
||||
if (nnotifs > 0) {
|
||||
snprintf(label, sizeof(label), "%s Notifications (%d)", ICON_BEL, nnotifs);
|
||||
add_menu_item(label, "@menu:notifications", 1);
|
||||
} else if (dunst_vis) {
|
||||
snprintf(label, sizeof(label), "%s Clear Notification", ICON_BEL);
|
||||
add_menu_item(label, "@toggle:notif_clear_all", 0);
|
||||
}
|
||||
const char *sh = getenv("SHELL");
|
||||
if (!sh || !sh[0])
|
||||
@@ -2105,9 +2188,9 @@ open_builtin_menu(const char *menu_name, int keep_idx)
|
||||
add_menu_item(label, "@close", 0);
|
||||
} else if (strcmp(menu_name, "notifications") == 0) {
|
||||
reset_session_defaults(1, "Notifs");
|
||||
populate_notifications_menu();
|
||||
snprintf(label, sizeof(label), "%s Clear All Notifications", ICON_CLS);
|
||||
add_menu_item(label, "@toggle:notif_clear_all", 1);
|
||||
add_menu_item(label, "@toggle:notif_clear_all", 0);
|
||||
populate_notifications_menu();
|
||||
snprintf(label, sizeof(label), "%s System Menu", ICON_MNU);
|
||||
add_menu_item(label, "@menu:sys", 1);
|
||||
snprintf(label, sizeof(label), "%s Close Menu", ICON_CLS);
|
||||
|
||||
Reference in New Issue
Block a user