mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Remove direct match from window switcher and reorganize
Direct matching before regex has the potential to interfere with some usecases. For example, if a user wants to enter regex syntax such as `shell[1]`, a direct match would return a window matching `shell[1]` exactly instead of `shell1`. Granted, the odds of the two conflicting each other are slim, but the core logic shouldn't prevent a user from utilizing regex to its full potential. One can always escape reserved characters if they want to match it directly. I have also added a warning and link to https://regexr.com in the UI should this be accepted. The rest of what has changed is simply to align with the executable switcher's matching, namely the use of `QRegularExpression` to drop the need for a try/catch block and moving the check for fullscreen to the if statement in order to remove the possibility of a race condition.
This commit is contained in:
parent
451bb6518c
commit
5f87a61177
|
|
@ -364,6 +364,39 @@
|
|||
<string>Window Title</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_44">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_58">
|
||||
<property name="toolTip">
|
||||
<string>https://regexr.com</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><html><head/><body><p>WARNING! Entries require valid RegEx to function, otherwise they will silently fail. You can check syntax and matches using <a href="https://regexr.com"><span style=" text-decoration: underline; color:#268bd2;">RegExr</span></a></p></body></html></string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::AutoText</enum>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_15">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_12">
|
||||
<item>
|
||||
|
|
|
|||
|
|
@ -228,53 +228,35 @@ void SceneSwitcher::on_ignoreWindows_currentRowChanged(int idx)
|
|||
|
||||
void SwitcherData::checkWindowTitleSwitch(bool& match, OBSWeakSource& scene, OBSWeakSource& transition)
|
||||
{
|
||||
//check if title should be ignored
|
||||
string title;
|
||||
|
||||
// Check if current window is ignored
|
||||
GetCurrentWindowTitle(title);
|
||||
for (auto& window : ignoreWindowsSwitches)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool matches = regex_match(title, regex(window));
|
||||
if (matches)
|
||||
{
|
||||
title = lastTitle;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const regex_error&)
|
||||
// True if ignored switch matches title
|
||||
bool matches = QString::fromStdString(title).contains(QRegularExpression(window.c_str()));
|
||||
if (matches)
|
||||
{
|
||||
title = lastTitle;
|
||||
break;
|
||||
}
|
||||
}
|
||||
lastTitle = title;
|
||||
|
||||
//direct match
|
||||
// Check for regex match
|
||||
for (WindowSceneSwitch& s : windowSwitches)
|
||||
{
|
||||
if (s.window == title)
|
||||
// True if window switch matches title
|
||||
bool matches = QString::fromStdString(title).contains(QRegularExpression(s.window.c_str()));
|
||||
// True if fullscreen is disabled OR window is fullscreen
|
||||
bool fullscreen = (!s.fullscreen || isFullscreen());
|
||||
if (matches && fullscreen)
|
||||
{
|
||||
match = !s.fullscreen || (s.fullscreen && isFullscreen());
|
||||
match = true;
|
||||
scene = s.scene;
|
||||
transition = s.transition;
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//regex match
|
||||
for (WindowSceneSwitch& s : windowSwitches)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool matches = regex_match(title, regex(s.window));
|
||||
if (matches)
|
||||
{
|
||||
match = !s.fullscreen || (s.fullscreen && isFullscreen());
|
||||
scene = s.scene;
|
||||
transition = s.transition;
|
||||
}
|
||||
}
|
||||
catch (const regex_error&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user