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:
Myned 2020-05-17 00:18:28 -04:00
parent 451bb6518c
commit 5f87a61177
No known key found for this signature in database
GPG Key ID: 24318A323F309244
2 changed files with 48 additions and 33 deletions

View File

@ -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>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;WARNING! Entries require valid RegEx to function, otherwise they will silently fail. You can check syntax and matches using &lt;a href=&quot;https://regexr.com&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#268bd2;&quot;&gt;RegExr&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</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>

View File

@ -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&)
{
}
}
}