Skip to content

Commit

Permalink
swallow: Add swallow_exception_regex (#2026)
Browse files Browse the repository at this point in the history
Currently, if a window class is specified in the swallow_regex (e.g.
Kitty) it will swallow every other window spawned by it automatically.
Many other WMs implementing this functionality allow for defining
exceptions from this rule. For instance, we want Kitty to swallow sxiv
or zathura but we do not want Kitty to swallow something like wev.

This commit adds an additional regex - swallow_exception_regex where
these exceptions can be defined. This regex is then compared against the
title of the window about to be swallowed and if it happens to be a
match, aborts the swallowing.

This works because whenever an application that could be swallowed is
launched by a terminal, the class of the terminal remains the same while
the title changes to whatever the application's name is, thus letting it
be matched against a regex.
  • Loading branch information
mrkajetanp committed Apr 12, 2023
1 parent a68feb5 commit efee6a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void CConfigManager::setDefaultVars() {
configValues["misc:disable_autoreload"].intValue = 0;
configValues["misc:enable_swallow"].intValue = 0;
configValues["misc:swallow_regex"].strValue = STRVAL_EMPTY;
configValues["misc:swallow_exception_regex"].strValue = STRVAL_EMPTY;
configValues["misc:focus_on_activate"].intValue = 0;
configValues["misc:no_direct_scanout"].intValue = 1;
configValues["misc:hide_cursor_on_touch"].intValue = 1;
Expand Down
17 changes: 10 additions & 7 deletions src/events/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ void setAnimToMove(void* data) {
void Events::listener_mapWindow(void* owner, void* data) {
CWindow* PWINDOW = (CWindow*)owner;

static auto* const PINACTIVEALPHA = &g_pConfigManager->getConfigValuePtr("decoration:inactive_opacity")->floatValue;
static auto* const PACTIVEALPHA = &g_pConfigManager->getConfigValuePtr("decoration:active_opacity")->floatValue;
static auto* const PDIMSTRENGTH = &g_pConfigManager->getConfigValuePtr("decoration:dim_strength")->floatValue;
static auto* const PSWALLOW = &g_pConfigManager->getConfigValuePtr("misc:enable_swallow")->intValue;
static auto* const PSWALLOWREGEX = &g_pConfigManager->getConfigValuePtr("misc:swallow_regex")->strValue;
static auto* const PINACTIVEALPHA = &g_pConfigManager->getConfigValuePtr("decoration:inactive_opacity")->floatValue;
static auto* const PACTIVEALPHA = &g_pConfigManager->getConfigValuePtr("decoration:active_opacity")->floatValue;
static auto* const PDIMSTRENGTH = &g_pConfigManager->getConfigValuePtr("decoration:dim_strength")->floatValue;
static auto* const PSWALLOW = &g_pConfigManager->getConfigValuePtr("misc:enable_swallow")->intValue;
static auto* const PSWALLOWREGEX = &g_pConfigManager->getConfigValuePtr("misc:swallow_regex")->strValue;
static auto* const PSWALLOWEXREGEX = &g_pConfigManager->getConfigValuePtr("misc:swallow_exception_regex")->strValue;

auto PMONITOR = g_pCompositor->m_pLastMonitor;
const auto PWORKSPACE =
Expand Down Expand Up @@ -553,8 +554,10 @@ void Events::listener_mapWindow(void* owner, void* data) {
}

if (finalFound) {
// check if it's the window we want
if (std::regex_match(g_pXWaylandManager->getAppIDClass(finalFound), rgx)) {
std::regex exc(*PSWALLOWEXREGEX);
// check if it's the window we want & not exempt from getting swallowed
if (std::regex_match(g_pXWaylandManager->getAppIDClass(finalFound), rgx) &&
!std::regex_match(g_pXWaylandManager->getTitle(finalFound), exc)) {
// swallow
PWINDOW->m_pSwallowed = finalFound;

Expand Down

0 comments on commit efee6a1

Please sign in to comment.