Fix PMIC/SPM deep-sleep wakeups and backport DE fixes, Anodized theme, and theme editor

- kernel: add 0013-gemini-pmic-wake-and-spm-safety.patch to arm MT6397/MT6351 wake IRQs in late suspend and enable PCM WDT, IM wait, and CNTP backstop on s.sleep
- geminux-powerd: distinguish real input/lid-open wakes from spurious open-lid wakes and re-suspend cleanly on battery timer wakes
- DE/WM: backport systray (32-bit ARGB, XEmbed race fix, lockscreen stacking), NETWM/EWMH/ICCCM and Wine/DXVK focus fixes, bar drawing fixes, and live Xresources reload across dwm, drw, st, libgemui, geminux-apply-theme, and geminux-session
- themes: backport Anodized.xth, geminux-xth.h, and interactive geminux-themes editor/importer (--install), rebuild prebuilt binaries/kernel modules, and update verification scripts
This commit is contained in:
Luxferre committed 2026-11-27 16:32:50 +02:00
1 parent f65dbb28a2
commit 6fcc263256
28 files changed
+3777 -330

No files matched your search

@@ -0,0 +1,96 @@
! Geminux Unified Theme: Anodized (Obsidian & brushed silver, brass-amber highlight, Fira Code + Nerd Fonts)
theme.name: Anodized
theme.isDark: 1
theme.fontFace: Fira Code
theme.uiFontFace: Roboto
theme.iconFontFace: DejaVuSansM Nerd Font
theme.baseFontSize: 32
theme.gtkTheme: Geminux-Anodized
theme.qtTheme: Fusion
theme.iconTheme: Adwaita
*TkTheme: gtkTtk
Xft.dpi: 192
Xft.antialias: 1
Xft.hinting: 1
Xft.hintstyle: hintslight
Xft.rgba: rgb
Xcursor.theme: default
Xcursor.size: 64
theme.bgMain: #08090b
theme.bgBar: #0e1014
theme.bgHeader: #12151a
theme.bgFooter: #0b0d11
theme.bgOverlay: #171b22
theme.bgAltEven: #101318
theme.bgAltOdd: #14181f
theme.bgInput: #161a21
theme.bgInputFocus: #1e232c
theme.bgButton: #1c212a
theme.bgSearch: #191e27
theme.bgBubbleIn: #181d25
theme.bgBubbleOut: #252c38
theme.bgToast: #1c222b
theme.fgMain: #e4e8ee
theme.fgBright: #f5f7fa
theme.fgMuted: #89929f
theme.selBg: #38414f
theme.selFg: #f5f7fa
theme.accent: #cfd6e0
theme.accentAlt: #e5eaf0
theme.highlight: #e2bc72
theme.border: #2d3440
theme.divider: #20252f
theme.success: #79cf9c
theme.info: #9eb3c8
theme.warning: #e2bc72
theme.danger: #e07a7a
theme.dangerBg: #3f1d20
dwm.borderpx: 4
dwm.font: Fira Code, DejaVuSansM Nerd Font 38px
dwm.background: #0e1014
dwm.foreground: #e4e8ee
dwm.border: #2d3440
dwm.selbackground: #38414f
dwm.selforeground: #f5f7fa
dwm.selborder: #cfd6e0
dwm.normbgcolor: #0e1014
dwm.normfgcolor: #e4e8ee
dwm.normbordercolor: #2d3440
dwm.selbgcolor: #38414f
dwm.selfgcolor: #f5f7fa
dwm.selbordercolor: #cfd6e0
dmenu.font: Fira Code, DejaVuSansM Nerd Font 40px
dmenu.background: #12151a
dmenu.foreground: #e4e8ee
dmenu.selbackground: #38414f
dmenu.selforeground: #f5f7fa
dmenu.outbackground: #191e27
dmenu.outforeground: #cfd6e0
dmenu.highlight: #e2bc72
st.font: Fira Code:pixelsize=44:style=Regular:antialias=true:autohint=true
st.termname: xterm-256color
st.background: #08090b
st.foreground: #e4e8ee
st.cursorColor: #cfd6e0
st.revCursorColor: #08090b
st.color0: #08090b
st.color1: #d97878
st.color2: #79cf9c
st.color3: #e2bc72
st.color4: #8ba6c4
st.color5: #b39bc8
st.color6: #84b8be
st.color7: #d5dce4
st.color8: #5b6370
st.color9: #eb9494
st.color10: #96deb3
st.color11: #edd092
st.color12: #a6bdd6
st.color13: #cab5dc
st.color14: #a2cdd2
st.color15: #f5f7fa
+106 -10
View File
@@ -1,27 +1,103 @@
#!/bin/sh #!/bin/sh
# Apply a Geminux .xth theme across .Xresources, xrdb, dunst, GTK2/3/4, Qt, Tk, dwm, st, and libgemui apps. # Apply or install a Geminux .xth theme across .Xresources, xrdb, dunst, GTK2/3/4, Qt, Tk, dwm, st, and libgemui apps.
set -eu set -eu
HOME_DIR="${HOME:-/home/user}" HOME_DIR="${HOME:-/home/user}"
THEME_DIR="$HOME_DIR/.xthemes" THEME_DIR="$HOME_DIR/.xthemes"
TARGET="${1:-}" USER_THEME_DIR="${XDG_CONFIG_HOME:-$HOME_DIR/.config}/geminux/themes"
INSTALL_SRC=""
INSTALL_NAME=""
TARGET=""
if [ "${1:-}" = "--install" ]; then
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
echo "Error: --install requires a .xth file path" >&2
exit 1
fi
INSTALL_SRC="$2"
INSTALL_NAME="${3:-}"
else
TARGET="${1:-}"
fi
sanitize_theme_name() {
printf '%s' "$1" | tr -c 'A-Za-z0-9_-' '_' | sed 's/^_*//; s/_*$//'
}
if [ -n "$INSTALL_SRC" ]; then
if [ ! -f "$INSTALL_SRC" ] || [ ! -r "$INSTALL_SRC" ]; then
echo "Error: cannot read theme file '$INSTALL_SRC'" >&2
exit 1
fi
if ! awk '
{
s = $0
gsub(/^[ \t\r\n]+|[ \t\r\n]+$/, "", s)
if (s == "" || substr(s, 1, 1) == "!" || substr(s, 1, 1) == "#") next
if (index(s, ":") > 1) { ok = 1; exit }
}
END { exit(ok ? 0 : 1) }
' "$INSTALL_SRC"; then
echo "Error: invalid .xth theme file '$INSTALL_SRC'" >&2
exit 1
fi
if [ -z "$INSTALL_NAME" ]; then
INSTALL_NAME="$(awk -F: '/^theme\.name[[:space:]]*:/ { sub(/^[[:space:]]+/, "", $2); sub(/[ \t\r\n]+$/, "", $2); print $2; exit }' "$INSTALL_SRC" || true)"
fi
if [ -z "$INSTALL_NAME" ]; then
INSTALL_NAME="$(basename "$INSTALL_SRC" .xth)"
fi
SAFE_NAME="$(sanitize_theme_name "$INSTALL_NAME")"
if [ -z "$SAFE_NAME" ] || [ "$SAFE_NAME" = "." ] || [ "$SAFE_NAME" = ".." ]; then
echo "Error: invalid target theme name" >&2
exit 1
fi
mkdir -p "$USER_THEME_DIR"
DEST_XTH="$USER_THEME_DIR/$SAFE_NAME.xth"
TMP_INST="$DEST_XTH.tmp.$$"
awk -v tname="$SAFE_NAME" '
BEGIN { had_name = 0 }
/^theme\.name[[:space:]]*:/ {
if (!had_name) {
printf "theme.name: %s\n", tname
had_name = 1
}
next
}
{ print $0 }
END {
if (!had_name) printf "theme.name: %s\n", tname
}
' "$INSTALL_SRC" > "$TMP_INST"
mv -f "$TMP_INST" "$DEST_XTH"
TARGET="$DEST_XTH"
fi
if [ -z "$TARGET" ]; then if [ -z "$TARGET" ]; then
if [ -d "$THEME_DIR" ]; then for _dir in "$USER_THEME_DIR" "$THEME_DIR" "/etc/skel/.xthemes"; do
ls -1 "$THEME_DIR"/*.xth 2>/dev/null | xargs -r -n1 basename | sed 's/\.xth$//' if [ -d "$_dir" ]; then
ls -1 "$_dir"/*.xth 2>/dev/null || true
fi fi
done | xargs -r -n1 basename | sed 's/\.xth$//' | awk '!seen[$0]++' | sort
exit 0 exit 0
fi fi
if [ -f "$TARGET" ]; then if [ -f "$TARGET" ]; then
THEME_FILE="$TARGET" THEME_FILE="$TARGET"
elif [ -f "$THEME_DIR/$TARGET.xth" ]; then elif [ -f "$TARGET.xth" ]; then
THEME_FILE="$THEME_DIR/$TARGET.xth" THEME_FILE="$TARGET.xth"
elif [ -f "/etc/skel/.xthemes/$TARGET.xth" ]; then
THEME_FILE="/etc/skel/.xthemes/$TARGET.xth"
else else
echo "Error: theme '$TARGET' not found in $THEME_DIR" >&2 _base="$(basename "$TARGET" .xth)"
if [ -f "$USER_THEME_DIR/$_base.xth" ]; then
THEME_FILE="$USER_THEME_DIR/$_base.xth"
elif [ -f "$THEME_DIR/$_base.xth" ]; then
THEME_FILE="$THEME_DIR/$_base.xth"
elif [ -f "/etc/skel/.xthemes/$_base.xth" ]; then
THEME_FILE="/etc/skel/.xthemes/$_base.xth"
else
echo "Error: theme '$TARGET' not found in $USER_THEME_DIR or $THEME_DIR" >&2
exit 1 exit 1
fi
fi fi
cp -f "$THEME_FILE" "$HOME_DIR/.Xresources" cp -f "$THEME_FILE" "$HOME_DIR/.Xresources"
@@ -29,7 +105,27 @@ cp -f "$THEME_FILE" "$HOME_DIR/.Xresources"
/usr/bin/geminux-sync-gtk-theme --skip-xrdb /usr/bin/geminux-sync-gtk-theme --skip-xrdb
if [ -n "${DISPLAY:-}" ] && command -v xrdb >/dev/null 2>&1; then if [ -n "${DISPLAY:-}" ] && command -v xrdb >/dev/null 2>&1; then
xrdb -nocpp -merge "$HOME_DIR/.Xresources" >/dev/null 2>&1 || true xrdb -nocpp -load "$HOME_DIR/.Xresources" >/dev/null 2>&1 || true
fi
if [ -n "${DISPLAY:-}" ] && [ "${GEMINUX_NO_SIGNAL:-0}" != "1" ]; then
_pids="$( (ps -eo pid=,comm= 2>/dev/null || ps -ax -o pid=,comm= 2>/dev/null || true) | awk '
{
pid = $1; cmd = $2
sub(/^.*\//, "", cmd)
if (cmd == "dwm" || cmd == "st" || cmd == "geminux-statusd" ||
cmd == "geminux-themes" || cmd == "geminux-control" ||
cmd == "geminux-net" || cmd == "geminux-audio" ||
cmd == "geminux-datetime" || cmd == "geminux-lock") {
print "USR1 " pid
}
}
' )"
if [ -n "${_pids:-}" ]; then
printf '%s\n' "$_pids" | while read -r _sig _p; do
[ -n "${_p:-}" ] && kill -"$_sig" "$_p" 2>/dev/null || true
done
fi
fi fi
# Signal live applications (dwm, st, webarchy, libgemui apps) to reload .Xresources via SIGUSR1 # Signal live applications (dwm, st, webarchy, libgemui apps) to reload .Xresources via SIGUSR1
+7 -1
View File
@@ -18,10 +18,16 @@ if [ ! -f "$HOME_DIR/.Xresources" ] || \
[ -d /etc/skel/.xthemes ] && rm -rf "$HOME_DIR/.xthemes" && cp -a /etc/skel/.xthemes "$HOME_DIR/.xthemes" [ -d /etc/skel/.xthemes ] && rm -rf "$HOME_DIR/.xthemes" && cp -a /etc/skel/.xthemes "$HOME_DIR/.xthemes"
elif [ ! -d "$HOME_DIR/.xthemes" ] && [ -d /etc/skel/.xthemes ]; then elif [ ! -d "$HOME_DIR/.xthemes" ] && [ -d /etc/skel/.xthemes ]; then
cp -a /etc/skel/.xthemes "$HOME_DIR/.xthemes" cp -a /etc/skel/.xthemes "$HOME_DIR/.xthemes"
elif [ -d /etc/skel/.xthemes ]; then
for _xth in /etc/skel/.xthemes/*.xth; do
[ -f "$_xth" ] || continue
_base="$(basename "$_xth")"
[ -f "$HOME_DIR/.xthemes/$_base" ] || cp -f "$_xth" "$HOME_DIR/.xthemes/$_base"
done
fi fi
if [ -f "$HOME_DIR/.Xresources" ] && command -v xrdb >/dev/null 2>&1; then if [ -f "$HOME_DIR/.Xresources" ] && command -v xrdb >/dev/null 2>&1; then
xrdb -merge "$HOME_DIR/.Xresources" 2>/dev/null || true xrdb -nocpp -load "$HOME_DIR/.Xresources" 2>/dev/null || true
fi fi
if command -v xrandr >/dev/null 2>&1; then if command -v xrandr >/dev/null 2>&1; then
@@ -0,0 +1,309 @@
--- a/include/linux/mfd/mt6397/core.h
+++ b/include/linux/mfd/mt6397/core.h
@@ -8,7 +8,6 @@
#define __MFD_MT6397_CORE_H__
#include <linux/mutex.h>
-#include <linux/notifier.h>
enum chip_id {
MT6323_CHIP_ID = 0x23,
@@ -63,7 +62,6 @@
struct mt6397_chip {
struct device *dev;
struct regmap *regmap;
- struct notifier_block pm_nb;
int irq;
struct irq_domain *irq_domain;
struct mutex irqlock;
@@ -79,5 +77,7 @@
int mt6358_irq_init(struct mt6397_chip *chip);
int mt6397_irq_init(struct mt6397_chip *chip);
+int mt6397_irq_suspend(struct mt6397_chip *chip);
+int mt6397_irq_resume(struct mt6397_chip *chip);
#endif /* __MFD_MT6397_CORE_H__ */
--- a/drivers/mfd/mt6397-irq.c
+++ b/drivers/mfd/mt6397-irq.c
@@ -8,7 +8,6 @@
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
-#include <linux/suspend.h>
#include <linux/mfd/mt6323/core.h>
#include <linux/mfd/mt6323/registers.h>
#include <linux/mfd/mt6328/core.h>
@@ -131,34 +130,42 @@
.map = mt6397_irq_domain_map,
};
-static int mt6397_irq_pm_notifier(struct notifier_block *notifier,
- unsigned long pm_event, void *unused)
+int mt6397_irq_suspend(struct mt6397_chip *chip)
{
- struct mt6397_chip *chip =
- container_of(notifier, struct mt6397_chip, pm_nb);
unsigned int i;
- switch (pm_event) {
- case PM_SUSPEND_PREPARE:
- for (i = 0; i < chip->num_irq_regs; i++)
- regmap_write(chip->regmap, chip->int_con[i],
- chip->wake_mask[i]);
- enable_irq_wake(chip->irq);
- break;
+ if (!chip || !chip->num_irq_regs)
+ return 0;
- case PM_POST_SUSPEND:
- for (i = 0; i < chip->num_irq_regs; i++)
- regmap_write(chip->regmap, chip->int_con[i],
- chip->irq_masks_cur[i]);
- disable_irq_wake(chip->irq);
- break;
+ /* Apply wake_mask in suspend_late after all child .suspend() hooks arm IRQs */
+ mutex_lock(&chip->irqlock);
+ for (i = 0; i < chip->num_irq_regs; i++)
+ regmap_write(chip->regmap, chip->int_con[i],
+ chip->wake_mask[i]);
+ mutex_unlock(&chip->irqlock);
+ enable_irq_wake(chip->irq);
- default:
- break;
- }
+ return 0;
+}
+EXPORT_SYMBOL_GPL(mt6397_irq_suspend);
- return NOTIFY_DONE;
+int mt6397_irq_resume(struct mt6397_chip *chip)
+{
+ unsigned int i;
+
+ if (!chip || !chip->num_irq_regs)
+ return 0;
+
+ disable_irq_wake(chip->irq);
+ mutex_lock(&chip->irqlock);
+ for (i = 0; i < chip->num_irq_regs; i++)
+ regmap_write(chip->regmap, chip->int_con[i],
+ chip->irq_masks_cur[i]);
+ mutex_unlock(&chip->irqlock);
+
+ return 0;
}
+EXPORT_SYMBOL_GPL(mt6397_irq_resume);
int mt6397_irq_init(struct mt6397_chip *chip)
{
@@ -220,7 +227,6 @@
for (i = 0; i < chip->num_irq_regs; i++)
regmap_write(chip->regmap, chip->int_con[i], 0x0);
- chip->pm_nb.notifier_call = mt6397_irq_pm_notifier;
chip->irq_domain = irq_domain_create_linear(dev_fwnode(chip->dev),
chip->num_irq_regs * 16,
&mt6397_irq_domain_ops, chip);
@@ -239,6 +245,5 @@
return ret;
}
- register_pm_notifier(&chip->pm_nb);
return 0;
}
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -10,6 +10,7 @@
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
+#include <linux/pm.h>
#include <linux/regmap.h>
#include <linux/mfd/core.h>
#include <linux/mfd/mt6323/core.h>
@@ -512,11 +513,30 @@
};
MODULE_DEVICE_TABLE(platform, mt6397_id);
+static int mt6397_suspend_late(struct device *dev)
+{
+ struct mt6397_chip *chip = dev_get_drvdata(dev);
+
+ return mt6397_irq_suspend(chip);
+}
+
+static int mt6397_resume_early(struct device *dev)
+{
+ struct mt6397_chip *chip = dev_get_drvdata(dev);
+
+ return mt6397_irq_resume(chip);
+}
+
+static const struct dev_pm_ops mt6397_pm_ops = {
+ LATE_SYSTEM_SLEEP_PM_OPS(mt6397_suspend_late, mt6397_resume_early)
+};
+
static struct platform_driver mt6397_driver = {
.probe = mt6397_probe,
.driver = {
.name = "mt6397",
.of_match_table = mt6397_of_match,
+ .pm = pm_sleep_ptr(&mt6397_pm_ops),
},
.id_table = mt6397_id,
};
--- a/drivers/soc/mediatek/mt6797-spm-sleep.c
+++ b/drivers/soc/mediatek/mt6797-spm-sleep.c
@@ -161,6 +161,7 @@
#define PCM_FSM_IM_STATE(v) (((v) >> 7) & 7)
/* How long the IM fetch may take before the PCM kick (D5q) */
#define SODI_IM_WAIT_US 200
+#define SLEEP_IM_WAIT_US 1000
#define PCM_RF_SYNC_R0 BIT(16)
#define PCM_RF_SYNC_R7 BIT(23)
#define PCM_PWRIO_R0_R7 0x81
@@ -179,8 +180,8 @@
#define S1_FLAGS 0x000902b1
#define FLAG_EN_SEGMENT2 BIT(18)
-/* Wake sources: PCM timer and EINT */
-#define S1_WAKE_SRC (BIT(0) | BIT(6))
+/* Wake sources: PCM timer, EINT, and PCM watchdog safety wake */
+#define S1_WAKE_SRC (BIT(0) | BIT(6) | WAKE_PCM_WDT)
/*
* The vendor's MT6797 SODI wake sources (WAKE_SRC_FOR_SODI, D4): PCM timer,
@@ -410,6 +411,8 @@
bool im_reuse; /* IM slave mode when the program is resident (D5q) */
bool r7_vendor; /* r7 starts from SPM_R7_VENDOR (D5r) */
bool vec_clear; /* PCM_EVENT_VECTOR_EN 0 before the kick (D5r) */
+ u32 im_wait_us; /* wait budget for IM fetch settle */
+ u32 backstop_ms; /* CPU0 physical timer backstop margin */
bool ready;
};
@@ -1027,7 +1030,8 @@
v = PCM_TIMER_EN;
if (sc->pcm_wdt) {
wdt_val = spm_rd(PCM_WDT_VAL);
- spm_wr(PCM_WDT_VAL, sc->ticks + SODI_PCM_WDT_MARGIN);
+ spm_wr(PCM_WDT_VAL,
+ min_t(u64, (u64)sc->ticks + SODI_PCM_WDT_MARGIN, U32_MAX));
v |= PCM_WDT_BITS;
}
spm_wr(PCM_CON1, spm_rd(PCM_CON1) | SPM_KEY | v);
@@ -1053,26 +1057,31 @@
spm_wr(SPM_CLK_CON, spm_rd(SPM_CLK_CON) | SPM_LOCK_INFRA_DCM);
/* D5q: has the IM fetch settled? Refuse the period if not */
- for (i = 0; ; i++) {
- s.wake.im_fsm1 = spm_rd(PCM_FSM_STA);
- if (!sc->im_wait || i >= SODI_IM_WAIT_US ||
- PCM_FSM_IM_STATE(s.wake.im_fsm1) ==
- PCM_FSM_IM_STATE(PCM_FSM_STA_DEF))
- break;
- udelay(1);
- }
- s.wake.im_us = i;
- if (sc->im_wait && i >= SODI_IM_WAIT_US) {
- s.wake.im_stuck = true;
- spm_restore();
- if (sc->pcm_wdt) {
- spm_wr(PCM_CON1, SPM_KEY | (spm_rd(PCM_CON1) & ~PCM_WDT_BITS) | con1);
- spm_wr(PCM_WDT_VAL, wdt_val);
+ {
+ u32 im_lim = sc->im_wait_us ? sc->im_wait_us : SODI_IM_WAIT_US;
+
+ for (i = 0; ; i++) {
+ s.wake.im_fsm1 = spm_rd(PCM_FSM_STA);
+ if (!sc->im_wait || i >= im_lim ||
+ PCM_FSM_IM_STATE(s.wake.im_fsm1) ==
+ PCM_FSM_IM_STATE(PCM_FSM_STA_DEF))
+ break;
+ udelay(1);
+ }
+ s.wake.im_us = i;
+ if (sc->im_wait && i >= im_lim) {
+ s.wake.im_stuck = true;
+ spm_restore();
+ if (sc->pcm_wdt) {
+ spm_wr(PCM_CON1,
+ SPM_KEY | (spm_rd(PCM_CON1) & ~PCM_WDT_BITS) | con1);
+ spm_wr(PCM_WDT_VAL, wdt_val);
+ }
+ writel(axi[0], s.mcucfg + MP0_AXI_CONFIG);
+ writel(axi[1], s.mcucfg + MP1_AXI_CONFIG);
+ writel(axi[2], s.mcucfg + MP2_AXI_CONFIG);
+ return -ETIMEDOUT;
}
- writel(axi[0], s.mcucfg + MP0_AXI_CONFIG);
- writel(axi[1], s.mcucfg + MP1_AXI_CONFIG);
- writel(axi[2], s.mcucfg + MP2_AXI_CONFIG);
- return -ETIMEDOUT;
}
if (sc->vec_clear)
@@ -1111,17 +1120,18 @@
s.gicd + GICD_ISENABLER + 4 * (SPM_GIC_INTID / 32));
/*
- * SODI: CPU0's physical timer is a backstop, 100 ms after the PCM timer
- * should end the period, so a program that never returns leaves CPU0
- * able to record its state instead of waiting for ever (D5i). Its PPI
- * stays enabled through the GIC mask.
+ * CPU0's physical timer is a backstop after when the PCM timer should
+ * end the period (100 ms for SODI, 5 s for mem suspend), so a program
+ * that never returns leaves CPU0 able to record its state instead of
+ * waiting for ever (D5i). Its PPI stays enabled through the GIC mask.
*/
- if (sc->cirq) {
+ if (sc->backstop_ms) {
cntp_cval = read_sysreg(cntp_cval_el0);
cntp_ctl = read_sysreg(cntp_ctl_el0);
write_sysreg(__arch_counter_get_cntpct() +
mul_u64_u64_div_u64(sc->ticks, arch_timer_get_cntfrq(), 32768) +
- arch_timer_get_cntfrq() / 10, cntp_cval_el0);
+ mul_u64_u64_div_u64(sc->backstop_ms, arch_timer_get_cntfrq(), MSEC_PER_SEC),
+ cntp_cval_el0);
write_sysreg(ARCH_TIMER_CTRL_ENABLE, cntp_ctl_el0);
isb();
}
@@ -1139,14 +1149,14 @@
s.im_resident = sc->im_ptr;
break;
}
- if (sc->cirq && (read_sysreg(cntp_ctl_el0) & ARCH_TIMER_CTRL_IT_STAT)) {
+ if (sc->backstop_ms && (read_sysreg(cntp_ctl_el0) & ARCH_TIMER_CTRL_IT_STAT)) {
s.wake.backstop = true;
break;
}
}
if (sc->idle)
ct_cpuidle_exit();
- if (sc->cirq) {
+ if (sc->backstop_ms) {
write_sysreg(cntp_ctl, cntp_ctl_el0);
write_sysreg(cntp_cval, cntp_cval_el0);
isb();
@@ -2093,6 +2103,10 @@
s.sleep.flags = s.flags;
s.sleep.wake_src = S1_WAKE_SRC;
s.sleep.slots = true;
+ s.sleep.pcm_wdt = true;
+ s.sleep.im_wait = true;
+ s.sleep.im_wait_us = SLEEP_IM_WAIT_US;
+ s.sleep.backstop_ms = 5000;
ret = spm_load_program(&s.pdev->dev, SPM_FW_NAME, spm_fw_sha256, 0, &s.sleep);
if (ret)
goto err;
@@ -2102,6 +2116,8 @@
s.sodi.src2_mask = 0x08ff009f;
s.sodi.wfi_count = 8;
s.sodi.cirq = true;
+ s.sodi.im_wait_us = SODI_IM_WAIT_US;
+ s.sodi.backstop_ms = 100;
s.cirq = ioremap(CIRQ_PHYS, 0x400);
s.afe = ioremap(AFE_PHYS, 0x1000);
np = of_find_compatible_node(NULL, NULL, "mediatek,mt6797-audio");
+1
View File
@@ -10,3 +10,4 @@
0010-mt6797-ccci-md1-boot-hs-v2-and-rpc.patch 0010-mt6797-ccci-md1-boot-hs-v2-and-rpc.patch
0011-gemini-lid-sync-filter-and-debounce.patch 0011-gemini-lid-sync-filter-and-debounce.patch
0012-gemini-lid-wake-and-fg-taper-fix.patch 0012-gemini-lid-wake-and-fg-taper-fix.patch
0013-gemini-pmic-wake-and-spm-safety.patch
Binary file not shown.
Binary file not shown.
+2 -1
View File
@@ -26,7 +26,7 @@ extern "C" {
#define GEMUI_PTR_SCROLL_UP 3 #define GEMUI_PTR_SCROLL_UP 3
#define GEMUI_PTR_SCROLL_DOWN 4 #define GEMUI_PTR_SCROLL_DOWN 4
#define GEMUI_MAX_HITS 192 #define GEMUI_MAX_HITS 256
#define GEMUI_MAX_FDS 16 #define GEMUI_MAX_FDS 16
typedef struct { typedef struct {
@@ -115,6 +115,7 @@ Window gemui_window(const gemui_app_t *app);
const gemui_theme_t *gemui_theme(const gemui_app_t *app); const gemui_theme_t *gemui_theme(const gemui_app_t *app);
int gemui_width(const gemui_app_t *app); int gemui_width(const gemui_app_t *app);
int gemui_height(const gemui_app_t *app); int gemui_height(const gemui_app_t *app);
bool gemui_clipboard_get(gemui_app_t *app, char *out, size_t out_sz);
int gemui_scale_px(const gemui_app_t *app, int logical_px); int gemui_scale_px(const gemui_app_t *app, int logical_px);
int gemui_add_fd(gemui_app_t *app, int fd, gemui_fd_cb cb, void *userdata); int gemui_add_fd(gemui_app_t *app, int fd, gemui_fd_cb cb, void *userdata);
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -306,7 +306,7 @@ for rel in ("etc/os-release", "usr/lib/os-release", "etc/issue", "etc/motd"):
f.write(txt) f.write(txt)
make_pkg( make_pkg(
"geminux-config", pkg_ver, "geminux-config", pkg_ver,
"Geminux system configs, OpenRC units, ALSA UCM2, XKB layout, 21 themes, and udev/power rules", "Geminux system configs, OpenRC units, ALSA UCM2, XKB layout, 22 themes, and udev/power rules",
cstage, cstage,
depends=[ depends=[
f"geminux-kernel-modules=7.3.5-r0", f"geminux-kernel-modules=7.3.5-r0",
+1
View File
@@ -683,6 +683,7 @@ def main():
os.path.join(BASE_DIR, "patches", "kernel", "series"): ( os.path.join(BASE_DIR, "patches", "kernel", "series"): (
"0009-mt6797-wlan-drop-free-stability.patch", "0009-mt6797-wlan-drop-free-stability.patch",
"0012-gemini-lid-wake-and-fg-taper-fix.patch", "0012-gemini-lid-wake-and-fg-taper-fix.patch",
"0013-gemini-pmic-wake-and-spm-safety.patch",
), ),
os.path.join(overlay_dir, "etc", "profile.d", "10-geminux-env.sh"): ( os.path.join(overlay_dir, "etc", "profile.d", "10-geminux-env.sh"): (
"export NO_AT_BRIDGE=1", "export NO_AT_BRIDGE=1",
+58 -2
View File
@@ -42,7 +42,8 @@ def parse_xres(path):
def main(): def main():
themes = sorted(glob.glob(os.path.join(THEMES_DIR, "*.xth"))) themes = sorted(glob.glob(os.path.join(THEMES_DIR, "*.xth")))
assert len(themes) >= 20, f"Expected >= 20 themes, found {len(themes)}" assert len(themes) >= 22, f"Expected >= 22 themes, found {len(themes)}"
assert any(os.path.basename(th) == "Anodized.xth" for th in themes), "Missing Anodized.xth"
with tempfile.TemporaryDirectory(prefix="geminux-dunst-test-") as tmp: with tempfile.TemporaryDirectory(prefix="geminux-dunst-test-") as tmp:
for idx, th in enumerate(themes): for idx, th in enumerate(themes):
@@ -224,7 +225,62 @@ def main():
first_name = f"Geminux-{parse_xres(themes[0])['theme.name']}" first_name = f"Geminux-{parse_xres(themes[0])['theme.name']}"
assert f"color_scheme_path=/home/user/.config/qt6ct/colors/{first_name}.conf" in skel_qt assert f"color_scheme_path=/home/user/.config/qt6ct/colors/{first_name}.conf" in skel_qt
print(f"[PASS] Verified {len(themes)} .xth themes, dunst synchronization, and GTK2/3/4/Qt/Tk theme generation") xth_hdr = os.path.join(BASE_DIR, "src", "geminux-apps", "geminux-xth.h")
xth_c = os.path.join(tmp, "test_xth.c")
xth_bin = os.path.join(tmp, "test_xth")
xth_out = os.path.join(tmp, "Custom_Test.xth")
imp_dir = os.path.join(tmp, "imp_themes")
os.makedirs(imp_dir, exist_ok=True)
with open(xth_c, "w", encoding="utf-8") as cf:
cf.write(
'#include <assert.h>\n'
'#include <stdio.h>\n'
'#include <string.h>\n'
f'#include "{xth_hdr}"\n'
'int main(void) {\n'
' geminux_xth_t x, y;\n'
' geminux_xth_init_anodized(&x);\n'
' assert(x.base_font_size == 32 && x.dwm_borderpx == 4 && x.is_dark == 1);\n'
' assert(strcmp(x.name, "Anodized") == 0);\n'
' snprintf(x.name, sizeof(x.name), "Custom Test");\n'
' snprintf(x.colors[GEMINUX_XTH_BG_BAR], 16, "#112233");\n'
' geminux_xth_sync_derived(&x);\n'
' assert(strcmp(x.colors[GEMINUX_XTH_DWM_NORM_BG], "#112233") == 0);\n'
' assert(geminux_xth_contrast_ratio("#ffffff", "#000000") > 20.0);\n'
' char clean[64];\n'
' geminux_xth_sanitize_name(" My Theme..!! ", clean, sizeof(clean));\n'
' assert(strcmp(clean, "My_Theme") == 0);\n'
f' assert(geminux_xth_save_file("{xth_out}", &x));\n'
f' assert(geminux_xth_load_file("{xth_out}", &y));\n'
' assert(y.base_font_size == 32 && y.dwm_borderpx == 4);\n'
' assert(strcmp(y.name, "Custom_Test") == 0);\n'
' assert(strcmp(y.colors[GEMINUX_XTH_DWM_NORM_BG], "#112233") == 0);\n'
' char dest[600];\n'
f' assert(geminux_xth_import_file("{xth_out}", "{imp_dir}", "Imported One", dest, sizeof(dest)));\n'
' geminux_xth_t z;\n'
' assert(geminux_xth_load_file(dest, &z));\n'
' assert(strcmp(z.name, "Imported_One") == 0);\n'
' return 0;\n'
'}\n'
)
subprocess.run(["cc", "-std=gnu99", "-Wall", "-Wextra", "-Werror", xth_c, "-o", xth_bin, "-lm"], check=True)
subprocess.run([xth_bin], check=True)
saved_vals = parse_xres(xth_out)
assert saved_vals.get("Xft.dpi") == "192"
assert saved_vals.get("Xcursor.size") == "64"
assert saved_vals.get("dwm.borderpx") == "4"
assert saved_vals.get("dwm.normbgcolor") == "#112233"
xth_home = os.path.join(tmp, "xth_home")
os.makedirs(xth_home, exist_ok=True)
xth_dunstrc = os.path.join(tmp, "Custom_Test.dunstrc")
xth_env = dict(gtk_env, HOME=xth_home, GEMINUX_XRESOURCES=xth_out, GEMINUX_DUNSTRC=xth_dunstrc)
subprocess.run([SYNC_SCRIPT, "--no-restart"], env=xth_env, check=True)
subprocess.run([GTK_SYNC_SCRIPT, "--no-reload"], env=xth_env, check=True)
assert os.path.isfile(xth_dunstrc)
assert os.path.isfile(os.path.join(xth_home, ".themes/Geminux-Custom_Test/gtk-3.0/gtk.css"))
print(f"[PASS] Verified {len(themes)} .xth themes, geminux-xth.h, dunst synchronization, and GTK2/3/4/Qt/Tk theme generation")
return 0 return 0
+8 -2
View File
@@ -116,6 +116,8 @@ void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
unsigned int lpad, const char *text, int invert) { unsigned int lpad, const char *text, int invert) {
char buf[1024]; char buf[1024];
int orig_x = x;
unsigned int orig_w = w;
int ty, render = x || y || w || h; int ty, render = x || y || w || h;
unsigned int ew, eh; unsigned int ew, eh;
XftDraw *d = NULL; XftDraw *d = NULL;
@@ -132,7 +134,7 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
DefaultVisual(drw->dpy, drw->screen), DefaultVisual(drw->dpy, drw->screen),
DefaultColormap(drw->dpy, drw->screen)); DefaultColormap(drw->dpy, drw->screen));
x += (int)lpad; x += (int)lpad;
if (w > lpad) w -= lpad; w = (w > lpad) ? (w - lpad) : 0;
} }
size_t len = strlen(text); size_t len = strlen(text);
@@ -149,6 +151,10 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
buf[len] = '\0'; buf[len] = '\0';
drw_font_getexts(drw->fonts, buf, (unsigned int)len, &ew, &eh); drw_font_getexts(drw->fonts, buf, (unsigned int)len, &ew, &eh);
} }
if (ew > w) {
len = 0;
buf[0] = '\0';
}
if (render && d) { if (render && d) {
pango_layout_set_text(drw->fonts->layout, buf, -1); pango_layout_set_text(drw->fonts->layout, buf, -1);
ty = y + (int)(h - eh) / 2; ty = y + (int)(h - eh) / 2;
@@ -160,7 +166,7 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
} }
if (d) XftDrawDestroy(d); if (d) XftDrawDestroy(d);
return x + (render ? (int)w : 0); return render ? (orig_x + (int)orig_w) : x;
} }
int drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h, int drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h,
+8 -2
View File
@@ -111,6 +111,8 @@ void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
unsigned int lpad, const char *text, int invert, Bool markup) { unsigned int lpad, const char *text, int invert, Bool markup) {
char buf[1024]; char buf[1024];
int orig_x = x;
unsigned int orig_w = w;
int ty, render = x || y || w || h; int ty, render = x || y || w || h;
unsigned int ew, eh; unsigned int ew, eh;
XftDraw *d = NULL; XftDraw *d = NULL;
@@ -127,7 +129,7 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
DefaultVisual(drw->dpy, drw->screen), DefaultVisual(drw->dpy, drw->screen),
DefaultColormap(drw->dpy, drw->screen)); DefaultColormap(drw->dpy, drw->screen));
x += (int)lpad; x += (int)lpad;
if (w > lpad) w -= lpad; w = (w > lpad) ? (w - lpad) : 0;
} }
size_t len = strlen(text); size_t len = strlen(text);
@@ -144,6 +146,10 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
buf[len] = '\0'; buf[len] = '\0';
drw_font_getexts(drw->font, buf, (unsigned int)len, &ew, &eh, markup); drw_font_getexts(drw->font, buf, (unsigned int)len, &ew, &eh, markup);
} }
if (ew > w) {
len = 0;
buf[0] = '\0';
}
if (render && d) { if (render && d) {
if (markup) if (markup)
@@ -161,7 +167,7 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
} }
if (d) XftDrawDestroy(d); if (d) XftDrawDestroy(d);
return x + (render ? (int)w : 0); return render ? (orig_x + (int)orig_w) : x;
} }
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) { void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) {
+1019 -144
View File
File diff suppressed because it is too large. Load diff
+3
View File
@@ -38,6 +38,9 @@ geminux-net: geminux-net.c geminux-wifi-list.h geminux-bt-list.h ../geminux-daem
geminux-audio: geminux-audio.c geminux-audio-parse.h ../libgemui/gemui.h geminux-audio: geminux-audio.c geminux-audio-parse.h ../libgemui/gemui.h
$(CC) $(CFLAGS) -o $@ $< $(LIBS) $(CC) $(CFLAGS) -o $@ $< $(LIBS)
geminux-themes: geminux-themes.c geminux-xth.h ../libgemui/gemui.h
$(CC) $(CFLAGS) -o $@ $< $(LIBS) -lm
geminux-%: geminux-%.c ../libgemui/gemui.h geminux-%: geminux-%.c ../libgemui/gemui.h
$(CC) $(CFLAGS) -o $@ $< $(LIBS) $(CC) $(CFLAGS) -o $@ $< $(LIBS)
File diff suppressed because it is too large. Load diff
+541
View File
@@ -0,0 +1,541 @@
/*
* Geminux Unified .xth Theme Parser, Validator & Atomic Writer (header-only POSIX C99/C11)
*/
#ifndef GEMINUX_XTH_H
#define GEMINUX_XTH_H
#include <ctype.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum {
GEMINUX_XTH_BG_MAIN = 0,
GEMINUX_XTH_BG_BAR,
GEMINUX_XTH_BG_HEADER,
GEMINUX_XTH_BG_FOOTER,
GEMINUX_XTH_BG_OVERLAY,
GEMINUX_XTH_BG_ALT_EVEN,
GEMINUX_XTH_BG_ALT_ODD,
GEMINUX_XTH_BG_INPUT,
GEMINUX_XTH_BG_INPUT_FOCUS,
GEMINUX_XTH_BG_BUTTON,
GEMINUX_XTH_BG_SEARCH,
GEMINUX_XTH_BG_BUBBLE_IN,
GEMINUX_XTH_BG_BUBBLE_OUT,
GEMINUX_XTH_BG_TOAST,
GEMINUX_XTH_FG_MAIN,
GEMINUX_XTH_FG_BRIGHT,
GEMINUX_XTH_FG_MUTED,
GEMINUX_XTH_SEL_BG,
GEMINUX_XTH_SEL_FG,
GEMINUX_XTH_ACCENT,
GEMINUX_XTH_ACCENT_ALT,
GEMINUX_XTH_HIGHLIGHT,
GEMINUX_XTH_BORDER,
GEMINUX_XTH_DIVIDER,
GEMINUX_XTH_SUCCESS,
GEMINUX_XTH_INFO,
GEMINUX_XTH_WARNING,
GEMINUX_XTH_DANGER,
GEMINUX_XTH_DANGER_BG,
GEMINUX_XTH_DWM_NORM_BG,
GEMINUX_XTH_DWM_NORM_FG,
GEMINUX_XTH_DWM_NORM_BD,
GEMINUX_XTH_DWM_SEL_BG,
GEMINUX_XTH_DWM_SEL_FG,
GEMINUX_XTH_DWM_SEL_BD,
GEMINUX_XTH_DMENU_BG,
GEMINUX_XTH_DMENU_FG,
GEMINUX_XTH_DMENU_SEL_BG,
GEMINUX_XTH_DMENU_SEL_FG,
GEMINUX_XTH_DMENU_OUT_BG,
GEMINUX_XTH_DMENU_OUT_FG,
GEMINUX_XTH_ST_BG,
GEMINUX_XTH_ST_FG,
GEMINUX_XTH_ST_CURSOR,
GEMINUX_XTH_ST_REVCURSOR,
GEMINUX_XTH_ST_COLOR0,
GEMINUX_XTH_ST_COLOR15 = GEMINUX_XTH_ST_COLOR0 + 15,
GEMINUX_XTH_COLOR_COUNT
};
#define GEMINUX_XTH_MAX_EXTRA 64
typedef struct {
const char *key;
const char *label;
const char *def_hex;
} geminux_xth_slot_t;
typedef struct {
char name[64];
int is_dark;
char font_face[96];
char ui_font_face[96];
char icon_font_face[96];
char icon_theme[64];
char qt_theme[64];
int base_font_size;
int dwm_borderpx;
char colors[GEMINUX_XTH_COLOR_COUNT][16];
char extra_keys[GEMINUX_XTH_MAX_EXTRA][64];
char extra_vals[GEMINUX_XTH_MAX_EXTRA][256];
int n_extra;
} geminux_xth_t;
static const geminux_xth_slot_t GEMINUX_XTH_SLOTS[GEMINUX_XTH_COLOR_COUNT] = {
{"theme.bgMain", "Main background", "#08090b"},
{"theme.bgBar", "Bar background", "#0e1014"},
{"theme.bgHeader", "Header background", "#12151a"},
{"theme.bgFooter", "Footer background", "#0b0d11"},
{"theme.bgOverlay", "Overlay / Popup", "#171b22"},
{"theme.bgAltEven", "Row even", "#101318"},
{"theme.bgAltOdd", "Row odd", "#14181f"},
{"theme.bgInput", "Input background", "#161a21"},
{"theme.bgInputFocus", "Input focused bg", "#1e232c"},
{"theme.bgButton", "Button background", "#1c212a"},
{"theme.bgSearch", "Search background", "#191e27"},
{"theme.bgBubbleIn", "Bubble in", "#181d25"},
{"theme.bgBubbleOut", "Bubble out", "#252c38"},
{"theme.bgToast", "Toast background", "#1c222b"},
{"theme.fgMain", "Main text", "#e4e8ee"},
{"theme.fgBright", "Bright text", "#f5f7fa"},
{"theme.fgMuted", "Muted text", "#89929f"},
{"theme.selBg", "Selection bg", "#38414f"},
{"theme.selFg", "Selection text", "#f5f7fa"},
{"theme.accent", "Primary accent", "#cfd6e0"},
{"theme.accentAlt", "Secondary accent", "#e5eaf0"},
{"theme.highlight", "Focus / Highlight", "#e2bc72"},
{"theme.border", "Border", "#2d3440"},
{"theme.divider", "Divider", "#20252f"},
{"theme.success", "Success", "#79cf9c"},
{"theme.info", "Info", "#9eb3c8"},
{"theme.warning", "Warning", "#e2bc72"},
{"theme.danger", "Danger", "#e07a7a"},
{"theme.dangerBg", "Danger background", "#3f1d20"},
{"dwm.normbgcolor", "DWM bar normal bg", "#0e1014"},
{"dwm.normfgcolor", "DWM bar normal text", "#e4e8ee"},
{"dwm.normbordercolor", "DWM inactive border", "#2d3440"},
{"dwm.selbgcolor", "DWM bar selected bg", "#38414f"},
{"dwm.selfgcolor", "DWM bar selected text", "#f5f7fa"},
{"dwm.selbordercolor", "DWM active border", "#cfd6e0"},
{"dmenu.background", "dmenu background", "#12151a"},
{"dmenu.foreground", "dmenu text", "#e4e8ee"},
{"dmenu.selbackground", "dmenu selected bg", "#38414f"},
{"dmenu.selforeground", "dmenu selected text", "#f5f7fa"},
{"dmenu.outbackground", "dmenu marked bg", "#191e27"},
{"dmenu.outforeground", "dmenu marked text", "#cfd6e0"},
{"st.background", "st background", "#08090b"},
{"st.foreground", "st foreground", "#e4e8ee"},
{"st.cursorColor", "st cursor", "#cfd6e0"},
{"st.revCursorColor", "st reverse cursor", "#08090b"},
{"st.color0", "ANSI 0 (Black)", "#08090b"},
{"st.color1", "ANSI 1 (Red)", "#d97878"},
{"st.color2", "ANSI 2 (Green)", "#79cf9c"},
{"st.color3", "ANSI 3 (Yellow)", "#e2bc72"},
{"st.color4", "ANSI 4 (Blue)", "#8ba6c4"},
{"st.color5", "ANSI 5 (Magenta)", "#b39bc8"},
{"st.color6", "ANSI 6 (Cyan)", "#84b8be"},
{"st.color7", "ANSI 7 (White)", "#d5dce4"},
{"st.color8", "ANSI 8 (Bright Black)", "#5b6370"},
{"st.color9", "ANSI 9 (Bright Red)", "#eb9494"},
{"st.color10", "ANSI 10 (Bright Green)","#96deb3"},
{"st.color11", "ANSI 11 (Bright Yel)", "#edd092"},
{"st.color12", "ANSI 12 (Bright Blue)", "#a6bdd6"},
{"st.color13", "ANSI 13 (Bright Mag)", "#cab5dc"},
{"st.color14", "ANSI 14 (Bright Cyan)", "#a2cdd2"},
{"st.color15", "ANSI 15 (Bright White)","#f5f7fa"}
};
static inline int geminux_xth_hex_nibble(char c) {
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
return -1;
}
static inline bool geminux_xth_parse_hex(const char *s, int *r, int *g, int *b) {
if (!s) return false;
while (*s == ' ' || *s == '\t') s++;
if (*s == '#') s++;
size_t len = strlen(s);
while (len > 0 && (s[len - 1] == ' ' || s[len - 1] == '\t' || s[len - 1] == '\r' || s[len - 1] == '\n')) len--;
if (len == 6) {
int d[6];
for (int i = 0; i < 6; i++) {
d[i] = geminux_xth_hex_nibble(s[i]);
if (d[i] < 0) return false;
}
if (r) *r = (d[0] << 4) | d[1];
if (g) *g = (d[2] << 4) | d[3];
if (b) *b = (d[4] << 4) | d[5];
return true;
}
if (len == 3) {
int d[3];
for (int i = 0; i < 3; i++) {
d[i] = geminux_xth_hex_nibble(s[i]);
if (d[i] < 0) return false;
}
if (r) *r = (d[0] << 4) | d[0];
if (g) *g = (d[1] << 4) | d[1];
if (b) *b = (d[2] << 4) | d[2];
return true;
}
return false;
}
static inline void geminux_xth_format_hex(int r, int g, int b, char *out, size_t sz) {
if (r < 0) r = 0;
if (r > 255) r = 255;
if (g < 0) g = 0;
if (g > 255) g = 255;
if (b < 0) b = 0;
if (b > 255) b = 255;
snprintf(out, sz, "#%02x%02x%02x", r, g, b);
}
static inline double geminux_xth_rel_lum(const char *hex) {
int r = 0, g = 0, b = 0;
if (!geminux_xth_parse_hex(hex, &r, &g, &b)) return 0.0;
double ch[3] = {r / 255.0, g / 255.0, b / 255.0};
for (int i = 0; i < 3; i++) {
ch[i] = (ch[i] <= 0.03928) ? (ch[i] / 12.92) : pow((ch[i] + 0.055) / 1.055, 2.4);
}
return 0.2126 * ch[0] + 0.7152 * ch[1] + 0.0722 * ch[2];
}
static inline double geminux_xth_contrast_ratio(const char *hex_a, const char *hex_b) {
double l1 = geminux_xth_rel_lum(hex_a);
double l2 = geminux_xth_rel_lum(hex_b);
if (l1 < l2) {
double tmp = l1;
l1 = l2;
l2 = tmp;
}
return (l1 + 0.05) / (l2 + 0.05);
}
static inline void geminux_xth_sanitize_name(const char *raw, char *out, size_t sz) {
if (!out || sz == 0) return;
out[0] = '\0';
if (!raw) return;
size_t j = 0;
for (const char *p = raw; *p && j + 1 < sz; p++) {
unsigned char ch = (unsigned char)*p;
if (isalnum(ch) || ch == '-' || ch == '_') {
out[j++] = (char)ch;
} else if (ch == ' ' || ch == '.') {
if (j > 0 && out[j - 1] != '_') out[j++] = '_';
}
}
while (j > 0 && out[j - 1] == '_') j--;
out[j] = '\0';
if (strcmp(out, ".") == 0 || strcmp(out, "..") == 0) out[0] = '\0';
}
static inline void geminux_xth_init_anodized(geminux_xth_t *x) {
if (!x) return;
memset(x, 0, sizeof(*x));
snprintf(x->name, sizeof(x->name), "Anodized");
x->is_dark = 1;
snprintf(x->font_face, sizeof(x->font_face), "Fira Code");
snprintf(x->ui_font_face, sizeof(x->ui_font_face), "Roboto");
snprintf(x->icon_font_face, sizeof(x->icon_font_face), "DejaVuSansM Nerd Font");
snprintf(x->icon_theme, sizeof(x->icon_theme), "Adwaita");
snprintf(x->qt_theme, sizeof(x->qt_theme), "Fusion");
x->base_font_size = 32;
x->dwm_borderpx = 4;
for (int i = 0; i < GEMINUX_XTH_COLOR_COUNT; i++) {
snprintf(x->colors[i], sizeof(x->colors[i]), "%s", GEMINUX_XTH_SLOTS[i].def_hex);
}
}
static inline void geminux_xth_sync_derived(geminux_xth_t *x) {
if (!x) return;
snprintf(x->colors[GEMINUX_XTH_DWM_NORM_BG], 16, "%s", x->colors[GEMINUX_XTH_BG_BAR]);
snprintf(x->colors[GEMINUX_XTH_DWM_NORM_FG], 16, "%s", x->colors[GEMINUX_XTH_FG_MAIN]);
snprintf(x->colors[GEMINUX_XTH_DWM_NORM_BD], 16, "%s", x->colors[GEMINUX_XTH_BORDER]);
snprintf(x->colors[GEMINUX_XTH_DWM_SEL_BG], 16, "%s", x->colors[GEMINUX_XTH_SEL_BG]);
snprintf(x->colors[GEMINUX_XTH_DWM_SEL_FG], 16, "%s", x->colors[GEMINUX_XTH_SEL_FG]);
snprintf(x->colors[GEMINUX_XTH_DWM_SEL_BD], 16, "%s", x->colors[GEMINUX_XTH_ACCENT]);
snprintf(x->colors[GEMINUX_XTH_DMENU_BG], 16, "%s", x->colors[GEMINUX_XTH_BG_HEADER]);
snprintf(x->colors[GEMINUX_XTH_DMENU_FG], 16, "%s", x->colors[GEMINUX_XTH_FG_MAIN]);
snprintf(x->colors[GEMINUX_XTH_DMENU_SEL_BG], 16, "%s", x->colors[GEMINUX_XTH_SEL_BG]);
snprintf(x->colors[GEMINUX_XTH_DMENU_SEL_FG], 16, "%s", x->colors[GEMINUX_XTH_SEL_FG]);
snprintf(x->colors[GEMINUX_XTH_DMENU_OUT_BG], 16, "%s", x->colors[GEMINUX_XTH_BG_SEARCH]);
snprintf(x->colors[GEMINUX_XTH_DMENU_OUT_FG], 16, "%s", x->colors[GEMINUX_XTH_ACCENT]);
snprintf(x->colors[GEMINUX_XTH_ST_BG], 16, "%s", x->colors[GEMINUX_XTH_BG_MAIN]);
snprintf(x->colors[GEMINUX_XTH_ST_FG], 16, "%s", x->colors[GEMINUX_XTH_FG_MAIN]);
snprintf(x->colors[GEMINUX_XTH_ST_CURSOR], 16, "%s", x->colors[GEMINUX_XTH_ACCENT]);
snprintf(x->colors[GEMINUX_XTH_ST_REVCURSOR], 16, "%s", x->colors[GEMINUX_XTH_BG_MAIN]);
}
static inline int geminux_xth_find_slot(const char *key) {
if (!key) return -1;
for (int i = 0; i < GEMINUX_XTH_COLOR_COUNT; i++) {
if (strcmp(GEMINUX_XTH_SLOTS[i].key, key) == 0) return i;
}
return -1;
}
static inline char *geminux_xth_trim(char *s) {
while (*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n') s++;
size_t len = strlen(s);
while (len > 0 && (s[len - 1] == ' ' || s[len - 1] == '\t' || s[len - 1] == '\r' || s[len - 1] == '\n')) {
s[--len] = '\0';
}
return s;
}
static inline bool geminux_xth_load_file(const char *path, geminux_xth_t *out) {
if (!path || !path[0] || !out) return false;
FILE *f = fopen(path, "rb");
if (!f) return false;
unsigned char probe[512];
size_t nread = fread(probe, 1, sizeof(probe), f);
if (nread == 0) {
fclose(f);
return false;
}
for (size_t i = 0; i < nread; i++) {
if (probe[i] == '\0') {
fclose(f);
return false;
}
}
rewind(f);
geminux_xth_t tmp;
geminux_xth_init_anodized(&tmp);
tmp.name[0] = '\0';
int has_is_dark = -1;
int kv_count = 0;
bool has_theme_key = false;
char line[512];
while (fgets(line, sizeof(line), f)) {
char *s = geminux_xth_trim(line);
if (!s[0] || s[0] == '!' || s[0] == '#') continue;
char *colon = strchr(s, ':');
if (!colon || colon == s) continue;
*colon = '\0';
char *k = geminux_xth_trim(s);
char *v = geminux_xth_trim(colon + 1);
if (!k[0] || !v[0]) continue;
kv_count++;
if (strncmp(k, "theme.", 6) == 0) has_theme_key = true;
int slot = geminux_xth_find_slot(k);
if (slot >= 0) {
int r = 0, g = 0, b = 0;
if (geminux_xth_parse_hex(v, &r, &g, &b)) {
geminux_xth_format_hex(r, g, b, tmp.colors[slot], sizeof(tmp.colors[slot]));
}
continue;
}
if (strcmp(k, "theme.name") == 0) {
snprintf(tmp.name, sizeof(tmp.name), "%s", v);
} else if (strcmp(k, "theme.isDark") == 0) {
has_is_dark = (atoi(v) != 0) ? 1 : 0;
} else if (strcmp(k, "theme.fontFace") == 0) {
snprintf(tmp.font_face, sizeof(tmp.font_face), "%s", v);
} else if (strcmp(k, "theme.uiFontFace") == 0) {
snprintf(tmp.ui_font_face, sizeof(tmp.ui_font_face), "%s", v);
} else if (strcmp(k, "theme.iconFontFace") == 0) {
snprintf(tmp.icon_font_face, sizeof(tmp.icon_font_face), "%s", v);
} else if (strcmp(k, "theme.iconTheme") == 0) {
snprintf(tmp.icon_theme, sizeof(tmp.icon_theme), "%s", v);
} else if (strcmp(k, "theme.qtTheme") == 0) {
snprintf(tmp.qt_theme, sizeof(tmp.qt_theme), "%s", v);
} else if (strcmp(k, "theme.baseFontSize") == 0) {
int sz = atoi(v);
if (sz >= 16 && sz <= 64) tmp.base_font_size = sz;
} else if (strcmp(k, "dwm.borderpx") == 0) {
int bw = atoi(v);
if (bw >= 1 && bw <= 10) tmp.dwm_borderpx = bw;
} else if (strcmp(k, "dwm.background") == 0 || strcmp(k, "dwm.foreground") == 0 ||
strcmp(k, "dwm.border") == 0 || strcmp(k, "dwm.selbackground") == 0 ||
strcmp(k, "dwm.selforeground") == 0 || strcmp(k, "dwm.selborder") == 0) {
int r = 0, g = 0, b = 0;
if (geminux_xth_parse_hex(v, &r, &g, &b)) {
int alias_idx = (strcmp(k, "dwm.background") == 0) ? GEMINUX_XTH_DWM_NORM_BG
: (strcmp(k, "dwm.foreground") == 0) ? GEMINUX_XTH_DWM_NORM_FG
: (strcmp(k, "dwm.border") == 0) ? GEMINUX_XTH_DWM_NORM_BD
: (strcmp(k, "dwm.selbackground") == 0) ? GEMINUX_XTH_DWM_SEL_BG
: (strcmp(k, "dwm.selforeground") == 0) ? GEMINUX_XTH_DWM_SEL_FG
: GEMINUX_XTH_DWM_SEL_BD;
geminux_xth_format_hex(r, g, b, tmp.colors[alias_idx], 16);
}
} else if (strcmp(k, "theme.gtkTheme") == 0 || strcmp(k, "*TkTheme") == 0 ||
strcmp(k, "Xft.dpi") == 0 || strcmp(k, "Xft.antialias") == 0 ||
strcmp(k, "Xft.hinting") == 0 || strcmp(k, "Xft.hintstyle") == 0 ||
strcmp(k, "Xft.rgba") == 0 || strcmp(k, "Xcursor.theme") == 0 ||
strcmp(k, "Xcursor.size") == 0 || strcmp(k, "dwm.font") == 0 ||
strcmp(k, "dmenu.font") == 0 || strcmp(k, "dmenu.highlight") == 0 ||
strcmp(k, "st.font") == 0 || strcmp(k, "st.termname") == 0) {
/* Managed automatically when serialized */
} else if (tmp.n_extra < GEMINUX_XTH_MAX_EXTRA) {
bool dup = false;
for (int ei = 0; ei < tmp.n_extra; ei++) {
if (strcmp(tmp.extra_keys[ei], k) == 0) {
snprintf(tmp.extra_vals[ei], sizeof(tmp.extra_vals[ei]), "%s", v);
dup = true;
break;
}
}
if (!dup) {
snprintf(tmp.extra_keys[tmp.n_extra], sizeof(tmp.extra_keys[0]), "%s", k);
snprintf(tmp.extra_vals[tmp.n_extra], sizeof(tmp.extra_vals[0]), "%s", v);
tmp.n_extra++;
}
}
}
fclose(f);
if (kv_count == 0 || !has_theme_key) return false;
if (!tmp.name[0]) {
const char *slash = strrchr(path, '/');
const char *base = slash ? slash + 1 : path;
char raw_name[64];
snprintf(raw_name, sizeof(raw_name), "%s", base);
size_t bl = strlen(raw_name);
if (bl > 4 && strcmp(raw_name + bl - 4, ".xth") == 0) raw_name[bl - 4] = '\0';
geminux_xth_sanitize_name(raw_name, tmp.name, sizeof(tmp.name));
if (!tmp.name[0]) snprintf(tmp.name, sizeof(tmp.name), "Custom");
}
if (has_is_dark >= 0) {
tmp.is_dark = has_is_dark;
} else {
tmp.is_dark = (geminux_xth_rel_lum(tmp.colors[GEMINUX_XTH_BG_MAIN]) < 0.20) ? 1 : 0;
}
*out = tmp;
return true;
}
static inline bool geminux_xth_save_file(const char *path, const geminux_xth_t *x) {
if (!path || !path[0] || !x) return false;
char safe_name[64];
geminux_xth_sanitize_name(x->name, safe_name, sizeof(safe_name));
if (!safe_name[0]) return false;
int base = (x->base_font_size >= 16 && x->base_font_size <= 64) ? x->base_font_size : 32;
int dwm_px = base + 6;
int dmenu_px = base + 8;
int st_px = base + 12;
int bpx = (x->dwm_borderpx >= 1 && x->dwm_borderpx <= 10) ? x->dwm_borderpx : 4;
const char *ff = x->font_face[0] ? x->font_face : "Fira Code";
const char *uf = x->ui_font_face[0] ? x->ui_font_face : "Roboto";
const char *ic = x->icon_font_face[0] ? x->icon_font_face : "DejaVuSansM Nerd Font";
const char *qt = x->qt_theme[0] ? x->qt_theme : "Fusion";
const char *it = x->icon_theme[0] ? x->icon_theme : "Adwaita";
char tmp_path[640];
int tn = snprintf(tmp_path, sizeof(tmp_path), "%s.tmp", path);
if (tn <= 0 || (size_t)tn >= sizeof(tmp_path)) return false;
FILE *f = fopen(tmp_path, "w");
if (!f) return false;
fprintf(f, "! Geminux Unified Theme: %s (%s)\n", safe_name, x->is_dark ? "Dark" : "Light");
fprintf(f, "theme.name: %s\n", safe_name);
fprintf(f, "theme.isDark: %d\n", x->is_dark ? 1 : 0);
fprintf(f, "theme.fontFace: %s\n", ff);
fprintf(f, "theme.uiFontFace: %s\n", uf);
fprintf(f, "theme.iconFontFace: %s\n", ic);
fprintf(f, "theme.baseFontSize: %d\n", base);
fprintf(f, "theme.gtkTheme: Geminux-%s\n", safe_name);
fprintf(f, "theme.qtTheme: %s\n", qt);
fprintf(f, "theme.iconTheme: %s\n", it);
fprintf(f, "*TkTheme: gtkTtk\n\n");
fprintf(f, "Xft.dpi: 192\n");
fprintf(f, "Xft.antialias: 1\n");
fprintf(f, "Xft.hinting: 1\n");
fprintf(f, "Xft.hintstyle: hintslight\n");
fprintf(f, "Xft.rgba: rgb\n");
fprintf(f, "Xcursor.theme: default\n");
fprintf(f, "Xcursor.size: 64\n\n");
for (int i = 0; i <= GEMINUX_XTH_DANGER_BG; i++) {
fprintf(f, "%s: %s\n", GEMINUX_XTH_SLOTS[i].key, x->colors[i]);
}
fprintf(f, "\ndwm.borderpx: %d\n", bpx);
fprintf(f, "dwm.font: %s, %s %dpx\n", ff, ic, dwm_px);
fprintf(f, "dwm.background: %s\n", x->colors[GEMINUX_XTH_DWM_NORM_BG]);
fprintf(f, "dwm.foreground: %s\n", x->colors[GEMINUX_XTH_DWM_NORM_FG]);
fprintf(f, "dwm.border: %s\n", x->colors[GEMINUX_XTH_DWM_NORM_BD]);
fprintf(f, "dwm.selbackground: %s\n", x->colors[GEMINUX_XTH_DWM_SEL_BG]);
fprintf(f, "dwm.selforeground: %s\n", x->colors[GEMINUX_XTH_DWM_SEL_FG]);
fprintf(f, "dwm.selborder: %s\n", x->colors[GEMINUX_XTH_DWM_SEL_BD]);
for (int i = GEMINUX_XTH_DWM_NORM_BG; i <= GEMINUX_XTH_DWM_SEL_BD; i++) {
fprintf(f, "%s: %s\n", GEMINUX_XTH_SLOTS[i].key, x->colors[i]);
}
fprintf(f, "\ndmenu.font: %s, %s %dpx\n", ff, ic, dmenu_px);
for (int i = GEMINUX_XTH_DMENU_BG; i <= GEMINUX_XTH_DMENU_OUT_FG; i++) {
fprintf(f, "%s: %s\n", GEMINUX_XTH_SLOTS[i].key, x->colors[i]);
}
fprintf(f, "dmenu.highlight: %s\n", x->colors[GEMINUX_XTH_HIGHLIGHT]);
fprintf(f, "\nst.font: %s:pixelsize=%d:style=Regular:antialias=true:autohint=true\n", ff, st_px);
fprintf(f, "st.termname: xterm-256color\n");
for (int i = GEMINUX_XTH_ST_BG; i <= GEMINUX_XTH_ST_COLOR15; i++) {
fprintf(f, "%s: %s\n", GEMINUX_XTH_SLOTS[i].key, x->colors[i]);
}
if (x->n_extra > 0) {
fprintf(f, "\n");
for (int i = 0; i < x->n_extra; i++) {
fprintf(f, "%s: %s\n", x->extra_keys[i], x->extra_vals[i]);
}
}
if (fclose(f) != 0) {
remove(tmp_path);
return false;
}
if (rename(tmp_path, path) != 0) {
remove(tmp_path);
return false;
}
return true;
}
static inline bool geminux_xth_import_file(const char *src_path, const char *dest_dir,
const char *override_name,
char *dest_out, size_t dest_sz) {
if (!src_path || !dest_dir || !dest_dir[0]) return false;
geminux_xth_t x;
if (!geminux_xth_load_file(src_path, &x)) return false;
char safe_name[64];
geminux_xth_sanitize_name((override_name && override_name[0]) ? override_name : x.name,
safe_name, sizeof(safe_name));
if (!safe_name[0]) return false;
snprintf(x.name, sizeof(x.name), "%s", safe_name);
char dest[600];
int dn = snprintf(dest, sizeof(dest), "%s/%s.xth", dest_dir, safe_name);
if (dn <= 0 || (size_t)dn >= sizeof(dest)) return false;
if (!geminux_xth_save_file(dest, &x)) return false;
if (dest_out && dest_sz > 0) {
size_t dlen = strlen(dest);
if (dlen >= dest_sz) dlen = dest_sz - 1;
memcpy(dest_out, dest, dlen);
dest_out[dlen] = '\0';
}
return true;
}
#endif /* GEMINUX_XTH_H */
+34 -22
View File
@@ -1001,23 +1001,21 @@ static void refresh_lid_state(powerd_ctx_t *ctx) {
/* gpio-keys SW_LID applies a 64 ms debounce timer on wakeup; wait up to /* gpio-keys SW_LID applies a 64 ms debounce timer on wakeup; wait up to
* timeout_ms using poll() so a lid-open wake sees SW_LID == 0 before we * timeout_ms using poll() so a lid-open wake sees SW_LID == 0 before we
* decide whether to light the backlight. Returns true if an input/lid wake * decide whether to light the backlight. Only a lid transition (closed->open)
* event was observed or the lid is open. */ * or actual input event counts as wake input when resumed with lid open. */
static bool wait_post_resume_lid_events(powerd_ctx_t *ctx, int timeout_ms) { static bool wait_post_resume_lid_events(powerd_ctx_t *ctx, bool was_lid_closed, int timeout_ms) {
bool saw_wake_input = false; bool saw_wake_input = false;
refresh_lid_state(ctx); refresh_lid_state(ctx);
if (ctx->num_ev <= 0) return !ctx->policy.lid_closed; if (was_lid_closed && !ctx->policy.lid_closed) saw_wake_input = true;
if (ctx->num_ev <= 0 || saw_wake_input) return saw_wake_input;
uint64_t deadline = ctx->policy.lid_closed ? (monotonic_ms() + (uint64_t)timeout_ms) : 0; uint64_t deadline = monotonic_ms() + (uint64_t)timeout_ms;
struct pollfd pfds[MAX_EVDEVS]; struct pollfd pfds[MAX_EVDEVS];
for (;;) { for (;;) {
int slice = 0;
if (ctx->policy.lid_closed) {
uint64_t now = monotonic_ms(); uint64_t now = monotonic_ms();
if (now >= deadline) break; if (now >= deadline) break;
slice = (int)(deadline - now); int slice = (int)(deadline - now);
if (slice > 20) slice = 20; if (slice > 20) slice = 20;
}
for (int i = 0; i < ctx->num_ev; i++) { for (int i = 0; i < ctx->num_ev; i++) {
pfds[i].fd = ctx->ev_fds[i]; pfds[i].fd = ctx->ev_fds[i];
@@ -1035,7 +1033,7 @@ static bool wait_post_resume_lid_events(powerd_ctx_t *ctx, int timeout_ms) {
while (read(ctx->ev_fds[i], &iev, sizeof(iev)) == (ssize_t)sizeof(iev)) { while (read(ctx->ev_fds[i], &iev, sizeof(iev)) == (ssize_t)sizeof(iev)) {
if (iev.type == EV_SW && iev.code == SW_LID) { if (iev.type == EV_SW && iev.code == SW_LID) {
ctx->policy.lid_closed = (iev.value != 0); ctx->policy.lid_closed = (iev.value != 0);
if (!ctx->policy.lid_closed) saw_wake_input = true; if (!ctx->policy.lid_closed && was_lid_closed) saw_wake_input = true;
} else if ((iev.type == EV_KEY && iev.value != 0) || } else if ((iev.type == EV_KEY && iev.value != 0) ||
iev.type == EV_REL || iev.type == EV_ABS) { iev.type == EV_REL || iev.type == EV_ABS) {
ctx->last_input_ms = monotonic_ms(); ctx->last_input_ms = monotonic_ms();
@@ -1044,10 +1042,8 @@ static bool wait_post_resume_lid_events(powerd_ctx_t *ctx, int timeout_ms) {
} }
} }
refresh_lid_state(ctx); refresh_lid_state(ctx);
if (!ctx->policy.lid_closed) { if (was_lid_closed && !ctx->policy.lid_closed) saw_wake_input = true;
saw_wake_input = true; if (saw_wake_input) break;
break;
}
} }
return saw_wake_input; return saw_wake_input;
} }
@@ -1120,6 +1116,9 @@ static void trigger_suspend(powerd_ctx_t *ctx) {
apply_cpu_sysfs(ctx, false); apply_cpu_sysfs(ctx, false);
return; return;
} }
refresh_lid_state(ctx);
bool was_lid_closed = ctx->policy.lid_closed;
bool prev_ac = ctx->policy.on_ac_power;
exit_low_power_standby(ctx); exit_low_power_standby(ctx);
prepare_consys_for_suspend(ctx); prepare_consys_for_suspend(ctx);
prepare_cpus_for_suspend(); prepare_cpus_for_suspend();
@@ -1143,14 +1142,26 @@ static void trigger_suspend(powerd_ctx_t *ctx) {
} }
ctx->low_power_standby = false; ctx->low_power_standby = false;
restore_cpus_after_resume(ctx); restore_cpus_after_resume(ctx);
bool saw_wake_input = suspended ? wait_post_resume_lid_events(ctx, 90) : !ctx->policy.lid_closed; bool saw_wake_input = suspended ? wait_post_resume_lid_events(ctx, was_lid_closed, 90)
: (was_lid_closed && !ctx->policy.lid_closed);
refresh_ac_and_hdmi(ctx); refresh_ac_and_hdmi(ctx);
if (!prev_ac && ctx->policy.on_ac_power) {
saw_wake_input = true;
}
ctx->suspend_ebusy_on_ac = (!suspended && ctx->policy.on_ac_power); ctx->suspend_ebusy_on_ac = (!suspended && ctx->policy.on_ac_power);
if (!ctx->policy.lid_closed || !geminux_should_suspend_on_lid(&ctx->policy) || bool want_resleep_open = !was_lid_closed && !ctx->policy.lid_closed && !saw_wake_input &&
ctx->suspend_ebusy_on_ac) { !ctx->policy.on_ac_power && !ctx->policy.hdmi_connected &&
ctx->policy.inhibit_count == 0;
bool want_resleep_closed = ctx->policy.lid_closed && !saw_wake_input &&
geminux_should_suspend_on_lid(&ctx->policy);
bool quiet_timer_resleep = suspended && !ctx->suspend_ebusy_on_ac &&
(want_resleep_closed || want_resleep_open);
if (!quiet_timer_resleep &&
(!ctx->policy.lid_closed || !geminux_should_suspend_on_lid(&ctx->policy) ||
ctx->suspend_ebusy_on_ac)) {
restore_consys_after_resume(ctx); restore_consys_after_resume(ctx);
} }
if (!ctx->policy.lid_closed && (suspended || saw_wake_input)) { if (!ctx->policy.lid_closed && (saw_wake_input || !quiet_timer_resleep)) {
ctx->suspend_ebusy_on_ac = false; ctx->suspend_ebusy_on_ac = false;
ctx->idle_stage = IDLE_STAGE_ACTIVE; ctx->idle_stage = IDLE_STAGE_ACTIVE;
ctx->last_input_ms = monotonic_ms(); ctx->last_input_ms = monotonic_ms();
@@ -1160,9 +1171,7 @@ static void trigger_suspend(powerd_ctx_t *ctx) {
} else { } else {
toggle_backlight(ctx, false); toggle_backlight(ctx, false);
ctx->idle_stage = IDLE_STAGE_LOCKED_BLANK; ctx->idle_stage = IDLE_STAGE_LOCKED_BLANK;
if (suspended && !ctx->suspend_ebusy_on_ac && if (quiet_timer_resleep) {
(ctx->policy.lid_closed ? geminux_should_suspend_on_lid(&ctx->policy)
: (!ctx->policy.on_ac_power && !saw_wake_input))) {
arm_timer_ms(ctx->tmr_fd, 2000); arm_timer_ms(ctx->tmr_fd, 2000);
} else { } else {
arm_timer_ms(ctx->tmr_fd, 0); arm_timer_ms(ctx->tmr_fd, 0);
@@ -1418,7 +1427,10 @@ int main(void) {
uint64_t exp = 0; uint64_t exp = 0;
while (read(ctx.tmr_fd, &exp, sizeof(exp)) > 0) {} while (read(ctx.tmr_fd, &exp, sizeof(exp)) > 0) {}
refresh_ac_and_hdmi(&ctx); refresh_ac_and_hdmi(&ctx);
if (ctx.policy.lid_closed && geminux_should_suspend_on_lid(&ctx.policy)) { if ((ctx.policy.lid_closed && geminux_should_suspend_on_lid(&ctx.policy)) ||
(!ctx.policy.lid_closed && ctx.idle_stage == IDLE_STAGE_LOCKED_BLANK &&
!ctx.policy.on_ac_power && ctx.policy.inhibit_count == 0 &&
!ctx.policy.hdmi_connected)) {
trigger_suspend(&ctx); trigger_suspend(&ctx);
} else { } else {
exit_low_power_standby(&ctx); exit_low_power_standby(&ctx);
+145 -10
View File
@@ -49,6 +49,7 @@ struct gemui_app {
Atom utf8_string; Atom utf8_string;
Atom net_wm_state; Atom net_wm_state;
Atom net_wm_state_fs; Atom net_wm_state_fs;
Atom sel_prop;
XIM xim; XIM xim;
XIC xic; XIC xic;
bool fullscreen_override; bool fullscreen_override;
@@ -265,15 +266,6 @@ void gemui_theme_reload(gemui_app_t *app) {
XrmInitialize(); XrmInitialize();
gemui_theme_defaults(&app->theme); gemui_theme_defaults(&app->theme);
const char *xrm_str = XResourceManagerString(app->dpy);
if (xrm_str) {
XrmDatabase mem_db = XrmGetStringDatabase(xrm_str);
if (mem_db) {
gemui_apply_xrm_db(mem_db, &app->theme);
XrmDestroyDatabase(mem_db);
}
}
const char *home = getenv("HOME"); const char *home = getenv("HOME");
char path[512]; char path[512];
if (home && home[0]) { if (home && home[0]) {
@@ -293,6 +285,31 @@ void gemui_theme_reload(gemui_app_t *app) {
XrmDestroyDatabase(fdb); XrmDestroyDatabase(fdb);
} }
} }
/* Always read XA_RESOURCE_MANAGER directly so live xrdb -load updates win over
disk fallbacks or stale XResourceManagerString() startup caches. */
Atom actual_type = None;
int actual_format = 0;
unsigned long nitems = 0, bytes_after = 0;
unsigned char *prop = NULL;
if (XGetWindowProperty(app->dpy, app->root, XA_RESOURCE_MANAGER,
0L, 262144L, False, XA_STRING, &actual_type,
&actual_format, &nitems, &bytes_after, &prop) == Success && prop) {
if (actual_type == XA_STRING && actual_format == 8 && nitems > 0) {
char *buf = malloc(nitems + 1);
if (buf) {
memcpy(buf, prop, nitems);
buf[nitems] = '\0';
XrmDatabase mem_db = XrmGetStringDatabase(buf);
free(buf);
if (mem_db) {
gemui_apply_xrm_db(mem_db, &app->theme);
XrmDestroyDatabase(mem_db);
}
}
}
XFree(prop);
}
} }
static void gemui_ensure_backbuf(gemui_app_t *app) { static void gemui_ensure_backbuf(gemui_app_t *app) {
@@ -408,6 +425,7 @@ gemui_app_t *gemui_create(const char *res_name, const char *title,
StructureNotifyMask | FocusChangeMask; StructureNotifyMask | FocusChangeMask;
if (fullscreen_override) { if (fullscreen_override) {
swa.override_redirect = True; swa.override_redirect = True;
swa.event_mask |= VisibilityChangeMask;
} }
unsigned long mask = CWBackPixmap | CWEventMask | (fullscreen_override ? CWOverrideRedirect : 0); unsigned long mask = CWBackPixmap | CWEventMask | (fullscreen_override ? CWOverrideRedirect : 0);
@@ -447,8 +465,13 @@ gemui_app_t *gemui_create(const char *res_name, const char *title,
app->utf8_string = XInternAtom(dpy, "UTF8_STRING", False); app->utf8_string = XInternAtom(dpy, "UTF8_STRING", False);
app->net_wm_state = XInternAtom(dpy, "_NET_WM_STATE", False); app->net_wm_state = XInternAtom(dpy, "_NET_WM_STATE", False);
app->net_wm_state_fs = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); app->net_wm_state_fs = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
app->sel_prop = XInternAtom(dpy, "GEMUI_CLIP_DATA", False);
XSetWMProtocols(dpy, app->win, &app->wm_delete, 1); XSetWMProtocols(dpy, app->win, &app->wm_delete, 1);
XSelectInput(dpy, app->root,
fullscreen_override ? (PropertyChangeMask | SubstructureNotifyMask)
: PropertyChangeMask);
if (fullscreen_override) { if (fullscreen_override) {
XChangeProperty(dpy, app->win, app->net_wm_state, XA_ATOM, 32, XChangeProperty(dpy, app->win, app->net_wm_state, XA_ATOM, 32,
PropModeReplace, (unsigned char *)&app->net_wm_state_fs, 1); PropModeReplace, (unsigned char *)&app->net_wm_state_fs, 1);
@@ -509,6 +532,55 @@ const gemui_theme_t *gemui_theme(const gemui_app_t *app) { return app ? &app->th
int gemui_width(const gemui_app_t *app) { return app ? app->w : 0; } int gemui_width(const gemui_app_t *app) { return app ? app->w : 0; }
int gemui_height(const gemui_app_t *app) { return app ? app->h : 0; } int gemui_height(const gemui_app_t *app) { return app ? app->h : 0; }
static bool gemui_read_selection(gemui_app_t *app, Atom sel, Atom target, char *out, size_t out_sz) {
XDeleteProperty(app->dpy, app->win, app->sel_prop);
XConvertSelection(app->dpy, sel, target, app->sel_prop, app->win, CurrentTime);
XFlush(app->dpy);
uint64_t deadline = gemui_now_ms() + 150ULL;
int xfd = ConnectionNumber(app->dpy);
XEvent nev;
bool got = false;
while (gemui_now_ms() < deadline) {
XEventsQueued(app->dpy, QueuedAfterReading);
if (XCheckTypedWindowEvent(app->dpy, app->win, SelectionNotify, &nev)) {
got = true;
break;
}
struct pollfd pfd = { .fd = xfd, .events = POLLIN };
poll(&pfd, 1, 20);
}
if (!got || nev.xselection.property == None) return false;
Atom da = None;
int di = 0;
unsigned long n = 0, after = 0;
unsigned char *prop = NULL;
bool ok = false;
if (XGetWindowProperty(app->dpy, app->win, app->sel_prop, 0L, (long)(out_sz / 4 + 16),
True, AnyPropertyType, &da, &di, &n, &after, &prop) == Success && prop) {
if (di == 8 && n > 0) {
size_t copy = n < out_sz - 1 ? n : out_sz - 1;
memcpy(out, prop, copy);
out[copy] = '\0';
ok = true;
}
XFree(prop);
}
return ok;
}
bool gemui_clipboard_get(gemui_app_t *app, char *out, size_t out_sz) {
if (!app || !out || out_sz == 0) return false;
out[0] = '\0';
Atom clip = XInternAtom(app->dpy, "CLIPBOARD", False);
if (gemui_read_selection(app, clip, app->utf8_string, out, out_sz)) return true;
if (gemui_read_selection(app, clip, XA_STRING, out, out_sz)) return true;
if (gemui_read_selection(app, XA_PRIMARY, app->utf8_string, out, out_sz)) return true;
if (gemui_read_selection(app, XA_PRIMARY, XA_STRING, out, out_sz)) return true;
return false;
}
int gemui_scale_px(const gemui_app_t *app, int logical_px) { int gemui_scale_px(const gemui_app_t *app, int logical_px) {
int dpi = app ? app->theme.dpi : 180; int dpi = app ? app->theme.dpi : 180;
return (logical_px * dpi + 48) / 96; return (logical_px * dpi + 48) / 96;
@@ -660,6 +732,32 @@ void gemui_flush_draw(gemui_app_t *app) {
gemui_render_frame(app); gemui_render_frame(app);
} }
static void gemui_keep_fullscreen_on_top(gemui_app_t *app) {
if (!app || !app->fullscreen_override || !app->mapped || !app->dpy || app->win == None) return;
Window root_ret = None, parent_ret = None;
Window *children = NULL;
unsigned int nchildren = 0;
int (*old_handler)(Display *, XErrorEvent *) = XSetErrorHandler(gemui_ignore_xerror);
if (!XQueryTree(app->dpy, app->root, &root_ret, &parent_ret, &children, &nchildren)) {
XSetErrorHandler(old_handler);
return;
}
Window top_viewable = None;
for (int i = (int)nchildren - 1; i >= 0; i--) {
Window cw = children[i];
XWindowAttributes wa;
if (!XGetWindowAttributes(app->dpy, cw, &wa) || wa.map_state != IsViewable) continue;
top_viewable = cw;
break;
}
if (top_viewable != None && top_viewable != app->win) {
XRaiseWindow(app->dpy, app->win);
XFlush(app->dpy);
}
if (children) XFree(children);
XSetErrorHandler(old_handler);
}
static void gemui_handle_x_events(gemui_app_t *app) { static void gemui_handle_x_events(gemui_app_t *app) {
while (XPending(app->dpy) > 0 && app->running) { while (XPending(app->dpy) > 0 && app->running) {
XEvent ev; XEvent ev;
@@ -671,6 +769,7 @@ static void gemui_handle_x_events(gemui_app_t *app) {
if (ev.xexpose.count == 0) app->need_redraw = true; if (ev.xexpose.count == 0) app->need_redraw = true;
break; break;
case ConfigureNotify: case ConfigureNotify:
if (ev.xconfigure.window == app->win) {
if (ev.xconfigure.width != app->w || ev.xconfigure.height != app->h) { if (ev.xconfigure.width != app->w || ev.xconfigure.height != app->h) {
app->w = ev.xconfigure.width; app->w = ev.xconfigure.width;
app->h = ev.xconfigure.height; app->h = ev.xconfigure.height;
@@ -679,6 +778,31 @@ static void gemui_handle_x_events(gemui_app_t *app) {
} }
app->need_redraw = true; app->need_redraw = true;
} }
} else if (app->fullscreen_override) {
gemui_keep_fullscreen_on_top(app);
}
break;
case MapNotify:
if (app->fullscreen_override && ev.xmap.window != app->win) {
gemui_keep_fullscreen_on_top(app);
}
break;
case VisibilityNotify:
if (app->fullscreen_override && ev.xvisibility.window == app->win &&
ev.xvisibility.state != VisibilityUnobscured) {
gemui_keep_fullscreen_on_top(app);
}
break;
case PropertyNotify:
if (ev.xproperty.window == app->root &&
ev.xproperty.atom == XA_RESOURCE_MANAGER &&
ev.xproperty.state != PropertyDelete) {
gemui_theme_reload(app);
if (app->handlers.on_theme) {
app->handlers.on_theme(app, app->userdata);
}
app->need_redraw = true;
}
break; break;
case ClientMessage: case ClientMessage:
if ((Atom)ev.xclient.data.l[0] == app->wm_delete) { if ((Atom)ev.xclient.data.l[0] == app->wm_delete) {
@@ -892,6 +1016,7 @@ static int gemui_draw_pango(cairo_t *cr, const char *face, int px_size,
pango_layout_set_font_description(layout, desc); pango_layout_set_font_description(layout, desc);
pango_layout_set_width(layout, r.w * PANGO_SCALE); pango_layout_set_width(layout, r.w * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
pango_layout_set_height(layout, 0);
pango_layout_set_single_paragraph_mode(layout, True); pango_layout_set_single_paragraph_mode(layout, True);
if (align == GEMUI_ALIGN_CENTER) { if (align == GEMUI_ALIGN_CENTER) {
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
@@ -905,9 +1030,13 @@ static int gemui_draw_pango(cairo_t *cr, const char *face, int px_size,
int tw = 0, th = 0; int tw = 0, th = 0;
pango_layout_get_pixel_size(layout, &tw, &th); pango_layout_get_pixel_size(layout, &tw, &th);
int dy = r.y + (r.h - th) / 2; int dy = r.y + (r.h - th) / 2;
cairo_save(cr);
cairo_rectangle(cr, r.x, r.y - 4, r.w, r.h + 8);
cairo_clip(cr);
gemui_set_source(cr, c); gemui_set_source(cr, c);
cairo_move_to(cr, r.x, dy); cairo_move_to(cr, r.x, dy);
pango_cairo_show_layout(cr, layout); pango_cairo_show_layout(cr, layout);
cairo_restore(cr);
pango_font_description_free(desc); pango_font_description_free(desc);
if (!g_active_layout) g_object_unref(layout); if (!g_active_layout) g_object_unref(layout);
@@ -962,7 +1091,13 @@ void gemui_draw_button(gemui_app_t *app, cairo_t *cr, gemui_rect_t r,
if (!app) return; if (!app) return;
const gemui_theme_t *t = &app->theme; const gemui_theme_t *t = &app->theme;
gemui_color_t bg = active ? t->sel_bg : (primary ? t->accent : t->bg_button); gemui_color_t bg = active ? t->sel_bg : (primary ? t->accent : t->bg_button);
gemui_color_t fg = (active || primary) ? t->sel_fg : t->fg_bright; double bg_lum = 0.299 * bg.r + 0.587 * bg.g + 0.114 * bg.b;
double bgm_lum = 0.299 * t->bg_main.r + 0.587 * t->bg_main.g + 0.114 * t->bg_main.b;
double fgm_lum = 0.299 * t->fg_main.r + 0.587 * t->fg_main.g + 0.114 * t->fg_main.b;
gemui_color_t dark_ink = (bgm_lum < 0.35) ? t->bg_main
: (fgm_lum < 0.35) ? t->fg_main
: (gemui_color_t){0.031, 0.035, 0.043, 1.0, 0xff08090bU};
gemui_color_t fg = (bg_lum > 0.58) ? dark_ink : ((active || primary) ? t->sel_fg : t->fg_bright);
gemui_color_t bd = focused ? t->highlight : (active ? t->sel_bg : t->border); gemui_color_t bd = focused ? t->highlight : (active ? t->sel_bg : t->border);
gemui_fill_round(cr, r, 10, bg); gemui_fill_round(cr, r, 10, bg);
+2 -1
View File
@@ -26,7 +26,7 @@ extern "C" {
#define GEMUI_PTR_SCROLL_UP 3 #define GEMUI_PTR_SCROLL_UP 3
#define GEMUI_PTR_SCROLL_DOWN 4 #define GEMUI_PTR_SCROLL_DOWN 4
#define GEMUI_MAX_HITS 192 #define GEMUI_MAX_HITS 256
#define GEMUI_MAX_FDS 16 #define GEMUI_MAX_FDS 16
typedef struct { typedef struct {
@@ -115,6 +115,7 @@ Window gemui_window(const gemui_app_t *app);
const gemui_theme_t *gemui_theme(const gemui_app_t *app); const gemui_theme_t *gemui_theme(const gemui_app_t *app);
int gemui_width(const gemui_app_t *app); int gemui_width(const gemui_app_t *app);
int gemui_height(const gemui_app_t *app); int gemui_height(const gemui_app_t *app);
bool gemui_clipboard_get(gemui_app_t *app, char *out, size_t out_sz);
int gemui_scale_px(const gemui_app_t *app, int logical_px); int gemui_scale_px(const gemui_app_t *app, int logical_px);
int gemui_add_fd(gemui_app_t *app, int fd, gemui_fd_cb cb, void *userdata); int gemui_add_fd(gemui_app_t *app, int fd, gemui_fd_cb cb, void *userdata);
+92 -22
View File
@@ -272,6 +272,7 @@ static int frccap = 0;
static char *usedfont = NULL; static char *usedfont = NULL;
static double usedfontsize = 0; static double usedfontsize = 0;
static double defaultfontsize = 0; static double defaultfontsize = 0;
static volatile sig_atomic_t st_reload_requested = 0;
static char *opt_class = NULL; static char *opt_class = NULL;
static char **opt_cmd = NULL; static char **opt_cmd = NULL;
@@ -690,6 +691,11 @@ propnotify(XEvent *e)
Atom clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0); Atom clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
xpev = &e->xproperty; xpev = &e->xproperty;
if (xpev->window == XRootWindow(xw.dpy, xw.scr)) {
if (xpev->atom == XA_RESOURCE_MANAGER && xpev->state != PropertyDelete)
st_reload_requested = 1;
return;
}
if (xpev->state == PropertyNewValue && if (xpev->state == PropertyNewValue &&
(xpev->atom == XA_PRIMARY || (xpev->atom == XA_PRIMARY ||
xpev->atom == clipboard)) { xpev->atom == clipboard)) {
@@ -1395,6 +1401,8 @@ xinit(int cols, int rows)
xw.selectionmode = XInternAtom(xw.dpy, "_ST_SELMODE", False); xw.selectionmode = XInternAtom(xw.dpy, "_ST_SELMODE", False);
updateselectionmodeatom(); updateselectionmodeatom();
XSelectInput(xw.dpy, XRootWindow(xw.dpy, xw.scr), PropertyChangeMask);
/* pointer cursor setup and blank cursor for hide-while-typing */ /* pointer cursor setup and blank cursor for hide-while-typing */
{ {
int ev_base = 0, err_base = 0; int ev_base = 0, err_base = 0;
@@ -2332,7 +2340,6 @@ resize(XEvent *e)
cresize(e->xconfigure.width, e->xconfigure.height); cresize(e->xconfigure.width, e->xconfigure.height);
} }
static volatile sig_atomic_t st_reload_requested = 0;
static char st_theme_font[256] = ""; static char st_theme_font[256] = "";
static char st_theme_bg[32] = ""; static char st_theme_bg[32] = "";
static char st_theme_fg[32] = ""; static char st_theme_fg[32] = "";
@@ -2354,7 +2361,7 @@ run(void)
int w = win.w, h = win.h; int w = win.w, h = win.h;
fd_set rfd; fd_set rfd;
int xfd = XConnectionNumber(xw.dpy), ttyfd, xev, drawing; int xfd = XConnectionNumber(xw.dpy), ttyfd, xev, drawing;
struct timespec seltv, *tv, now, lastblink, trigger; struct timespec seltv, *tv, now, lastblink, trigger = {0};
double timeout; double timeout;
/* Waiting for window mapping */ /* Waiting for window mapping */
@@ -2377,16 +2384,34 @@ run(void)
ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd); ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd);
cresize(w, h); cresize(w, h);
signal(SIGUSR1, st_sigusr1); {
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = st_sigusr1;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGUSR1, &sa, NULL);
}
for (timeout = -1, drawing = 0, lastblink = (struct timespec){0};;) { for (timeout = -1, drawing = 0, lastblink = (struct timespec){0};;) {
if (st_reload_requested) { if (st_reload_requested) {
XColor xmousefg = {0}, xmousebg = {0};
st_reload_requested = 0; st_reload_requested = 0;
drawing = 0;
timeout = -1;
config_init(); config_init();
xloadcols(); xloadcols();
XSetWindowBackground(xw.dpy, xw.win, dc.col[defaultbg].pixel);
xmousefg.red = dc.col[mousefg].color.red;
xmousefg.green = dc.col[mousefg].color.green;
xmousefg.blue = dc.col[mousefg].color.blue;
xmousebg.red = dc.col[mousebg].color.red;
xmousebg.green = dc.col[mousebg].color.green;
xmousebg.blue = dc.col[mousebg].color.blue;
XRecolorCursor(xw.dpy, xw.vpointer, &xmousefg, &xmousebg);
xunloadfonts(); xunloadfonts();
hbunloadfonts(); usedfont = opt_font ? opt_font : font;
xloadfonts(opt_font ? opt_font : font, 0); xloadfonts(usedfont, 0);
cresize(win.w, win.h); cresize(win.w, win.h);
redraw(); redraw();
XFlush(xw.dpy); XFlush(xw.dpy);
@@ -2437,6 +2462,8 @@ run(void)
if (handler[ev.type]) if (handler[ev.type])
(handler[ev.type])(&ev); (handler[ev.type])(&ev);
} }
if (st_reload_requested)
continue;
/* /*
* To reduce flicker and tearing, when new content or event * To reduce flicker and tearing, when new content or event
@@ -2480,8 +2507,15 @@ run(void)
} }
} }
static int st_defaults_saved = 0;
static const char *default_colorname[LEN(colorname)];
static char *default_font = NULL;
static char *default_termname = NULL;
static char *default_shell = NULL;
static char *st_res_alloc[LEN(resources)];
int int
resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst) resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst, char **alloc_slot)
{ {
char **sdst = dst; char **sdst = dst;
int *idst = dst; int *idst = dst;
@@ -2489,8 +2523,8 @@ resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
char fullname[256]; char fullname[256];
char fullclass[256]; char fullclass[256];
char *type; char *type = NULL;
XrmValue ret; XrmValue ret = {0};
snprintf(fullname, sizeof(fullname), "%s.%s", snprintf(fullname, sizeof(fullname), "%s.%s",
opt_name ? opt_name : "st", name); opt_name ? opt_name : "st", name);
@@ -2498,14 +2532,22 @@ resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
opt_class ? opt_class : "St", name); opt_class ? opt_class : "St", name);
fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0'; fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0';
XrmGetResource(db, fullname, fullclass, &type, &ret); if (!XrmGetResource(db, fullname, fullclass, &type, &ret) ||
if (ret.addr == NULL || strncmp("String", type, 64)) ret.addr == NULL || !type || strncmp("String", type, 64))
return 1; return 1;
switch (rtype) { switch (rtype) {
case STRING: case STRING: {
*sdst = strdup(ret.addr); char *dup = strdup(ret.addr);
if (dup) {
*sdst = dup;
if (alloc_slot) {
free(*alloc_slot);
*alloc_slot = dup;
}
}
break; break;
}
case INTEGER: case INTEGER:
*idst = strtoul(ret.addr, NULL, 10); *idst = strtoul(ret.addr, NULL, 10);
break; break;
@@ -2520,6 +2562,7 @@ void
config_init(void) config_init(void)
{ {
XrmDatabase db = NULL; XrmDatabase db = NULL;
XrmDatabase mdb = NULL;
ResourcePref *p; ResourcePref *p;
Atom actual_type = None; Atom actual_type = None;
int actual_format = 0; int actual_format = 0;
@@ -2528,6 +2571,23 @@ config_init(void)
char *type = NULL; char *type = NULL;
XrmValue ret; XrmValue ret;
if (!st_defaults_saved) {
memcpy(default_colorname, colorname, sizeof(default_colorname));
default_font = font;
default_termname = termname;
default_shell = shell;
st_defaults_saved = 1;
} else {
for (size_t ri = 0; ri < LEN(resources); ri++) {
free(st_res_alloc[ri]);
st_res_alloc[ri] = NULL;
}
memcpy(colorname, default_colorname, sizeof(default_colorname));
font = default_font;
termname = default_termname;
shell = default_shell;
}
XrmInitialize(); XrmInitialize();
{ {
const char *home = getenv("HOME"); const char *home = getenv("HOME");
@@ -2535,23 +2595,33 @@ config_init(void)
snprintf(path, sizeof(path), "%s/.Xresources", (home && home[0]) ? home : "/home/user"); snprintf(path, sizeof(path), "%s/.Xresources", (home && home[0]) ? home : "/home/user");
db = XrmGetFileDatabase(path); db = XrmGetFileDatabase(path);
} }
if (!db && XGetWindowProperty(xw.dpy, DefaultRootWindow(xw.dpy), XA_RESOURCE_MANAGER, if (XGetWindowProperty(xw.dpy, DefaultRootWindow(xw.dpy), XA_RESOURCE_MANAGER,
0L, 65536L, False, XA_STRING, &actual_type, 0L, 262144L, False, XA_STRING, &actual_type,
&actual_format, &nitems, &bytes_after, &prop) == Success && prop) { &actual_format, &nitems, &bytes_after, &prop) == Success && prop) {
if (actual_type == XA_STRING && actual_format == 8 && nitems > 0) if (actual_type == XA_STRING && actual_format == 8 && nitems > 0) {
db = XrmGetStringDatabase((const char *)prop); char *buf = malloc(nitems + 1);
if (buf) {
memcpy(buf, prop, nitems);
buf[nitems] = '\0';
mdb = XrmGetStringDatabase(buf);
free(buf);
}
}
XFree(prop); XFree(prop);
} }
if (!db) { if (mdb) {
char *resm = XResourceManagerString(xw.dpy); if (db)
if (resm) XrmMergeDatabases(mdb, &db);
db = XrmGetStringDatabase(resm); else
db = mdb;
} }
if (!db) if (!db)
return; return;
for (p = resources; p < resources + LEN(resources); p++) for (size_t ri = 0; ri < LEN(resources); ri++) {
resource_load(db, p->name, p->type, p->dst); p = &resources[ri];
resource_load(db, p->name, p->type, p->dst, &st_res_alloc[ri]);
}
/* Also honor unified theme.* keys if st.* keys were omitted */ /* Also honor unified theme.* keys if st.* keys were omitted */
if (!(XrmGetResource(db, "st.font", "*", &type, &ret) && ret.addr && ret.addr[0])) { if (!(XrmGetResource(db, "st.font", "*", &type, &ret) && ret.addr && ret.addr[0])) {