Bug 414635 - Very strange code at main.cpp
Summary: Very strange code at main.cpp
Status: RESOLVED NOT A BUG
Alias: None
Product: Spectacle
Classification: Applications
Component: General (show other bugs)
Version: 19.11.80
Platform: Debian stable Linux
: NOR normal
Target Milestone: ---
Assignee: Boudhayan Gupta
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-28 20:30 UTC by Askar Safin
Modified: 2019-11-30 09:44 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Askar Safin 2019-11-28 20:30:43 UTC
I am attempting to understand how Spectacle works. So I read its code. I found the following very strange code in Main.cpp in current master ( 4370c5484972a02497bf4bb479f4cc1586b6924c , https://github.com/KDE/spectacle/blob/4370c5484972a02497bf4bb479f4cc1586b6924c/src/Main.cpp ):

    } else if (lCmdLineParser.isSet(QStringLiteral("windowundercursor"))) {
        lCaptureMode = Spectacle::CaptureMode::TransientWithParent;
    } else if (lCmdLineParser.isSet(QStringLiteral("transientonly"))) {
        lCaptureMode = Spectacle::CaptureMode::WindowUnderCursor;

This seems like a typo. It seems the following code should be:

    } else if (lCmdLineParser.isSet(QStringLiteral("windowundercursor"))) {
        lCaptureMode = Spectacle::CaptureMode::WindowUnderCursor;
    } else if (lCmdLineParser.isSet(QStringLiteral("transientonly"))) {
        lCaptureMode = Spectacle::CaptureMode::TransientWithParent;

Even if this is not typo, please add some comment, which will explain such strange code. Or (better) rename something to help people, who read you code.

I am reading code of Spectacle, because I'm trying to capture video from screen in my very unusual scenario, see https://bugs.kde.org/show_bug.cgi?id=412731 if you are interested
Comment 1 David Redondo 2019-11-30 09:44:14 UTC
Hello Askar, that code is indeed correct. You can think here of a transient just as a window. Note that a popup is also a single window. What this does it maps from the user facing option to the options in the code. For the user a popup is not a different window compared to the parent window hence the mapping from windowundercursor to transientwithparent. 
I agree it can be confusing and others had the same  thoughts  as you in the past (compare https://phabricator.kde.org/D23891)