2023-11-13 09:33:28 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
2024-07-09 11:42:07 -04:00
|
|
|
# SPDX-FileCopyrightText: 2023 - 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
|
2023-11-13 09:33:28 -05:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
## Write KWin rules for window of specific domain to be in specific activity.
|
|
|
|
# shellcheck disable=SC1090,SC2317
|
|
|
|
set -eu
|
|
|
|
|
2024-07-10 08:36:05 -04:00
|
|
|
file="${XDG_CONFIG_HOME:=${HOME}/.config}/kwinrulesrc"
|
2023-11-13 09:33:28 -05:00
|
|
|
|
|
|
|
usage(){
|
|
|
|
echo "Usage: ${0##*/} <group> <activity>
|
|
|
|
Example: ${0##*/} personal personal
|
|
|
|
Example: ${0##*/} fun personal
|
|
|
|
Example: ${0##*/} work work
|
|
|
|
If domain is work, dvm-work, disp-work and work-something will all be present
|
|
|
|
in the work activity" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
writeconf(){
|
|
|
|
group="$1"
|
|
|
|
key="$2"
|
|
|
|
value="$3"
|
|
|
|
|
2024-07-10 08:36:05 -04:00
|
|
|
group_id="$(grep -B1 -- "^Description=${group}$" "${file}" | head -1 |
|
2024-07-09 11:42:07 -04:00
|
|
|
tr -d "[" | tr -d "]")"
|
2023-11-13 09:33:28 -05:00
|
|
|
if test -z "${group_id}"; then
|
2024-07-10 08:36:05 -04:00
|
|
|
highest_id="$(grep -- "\[[0-9]\+\]" "${file}" | tr -d "[" | tr -d "]" |
|
2024-07-09 11:42:07 -04:00
|
|
|
sort | tail -1)"
|
2023-11-13 09:33:28 -05:00
|
|
|
if test -n "${highest_id}"; then
|
|
|
|
group_id="$((highest_id+1))"
|
|
|
|
else
|
|
|
|
group_id="0"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-07-10 08:36:05 -04:00
|
|
|
kwriteconfig --file "${file}" --group "${group_id}" --key "${key}" \
|
|
|
|
"${value}"
|
2023-11-13 09:33:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
writeconf_group(){
|
|
|
|
chosen_group="$1"
|
|
|
|
chosen_activity="$2"
|
2024-07-10 08:36:05 -04:00
|
|
|
writeconf "${chosen_group}" Description "${chosen_group}"
|
|
|
|
if test -n "${chosen_activity}"; then
|
2023-11-13 09:33:28 -05:00
|
|
|
chosen_activity_id="$(kactivities-cli --list-activities |
|
2024-07-10 08:36:05 -04:00
|
|
|
awk -v activity="${chosen_activity}" '$3 ~ activity {print $2}')"
|
|
|
|
if test -z "${chosen_activity_id}"; then
|
|
|
|
printf '%s\n' "Invalid activity name: ${chosen_activity}"
|
2023-11-13 09:33:28 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
2024-07-10 08:36:05 -04:00
|
|
|
writeconf "${chosen_group}" activity "${chosen_activity_id}"
|
|
|
|
writeconf "${chosen_group}" activityrule 2
|
2023-11-13 09:33:28 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
## Regex: https://doc.qt.io/qt-6/qregularexpression.html
|
2024-07-10 08:36:05 -04:00
|
|
|
writeconf "${chosen_group}" title \
|
|
|
|
"^\\[(disp-|dvm-)?${chosen_group}(-\\S+)?\\] .*"
|
|
|
|
writeconf "${chosen_group}" titlematch 3
|
|
|
|
writeconf "${chosen_group}" wmclass "${chosen_group}"
|
|
|
|
writeconf "${chosen_group}" wmclasscomplete false
|
|
|
|
writeconf "${chosen_group}" wmclassmatch 2
|
2023-11-13 09:33:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
case "${1-}" in
|
2024-07-10 08:36:05 -04:00
|
|
|
""|-h|--?help) usage;;
|
|
|
|
*) ;;
|
2023-11-13 09:33:28 -05:00
|
|
|
esac
|
|
|
|
case "${2-}" in
|
2024-07-10 08:36:05 -04:00
|
|
|
"") usage;;
|
|
|
|
*) ;;
|
2023-11-13 09:33:28 -05:00
|
|
|
esac
|
|
|
|
|
|
|
|
writeconf_group "${1}" "${2}"
|
|
|
|
dbus-send --type=signal /KWin org.kde.KWin.reloadConfig
|