Bug 378463 - Use window title to suggest file names
Summary: Use window title to suggest file names
Alias: None
Product: Spectacle
Classification: Applications
Component: General (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: Boudhayan Gupta
Depends on:
Reported: 2017-04-05 12:01 UTC by skaumo
Modified: 2018-03-06 16:44 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 18.04.0


Note You need to log in before you can comment on or make changes to this bug.
Description skaumo 2017-04-05 12:01:35 UTC
Saving all screenshots as "Screenshot_%Y%D....png" doesn't scale too well with a large number of screenshots (think of QA people), and doesn't make it easy to find them.

Instead, in the configuration it would be nice to have the active window's title to be an available option for the suggested file name. E.G.: %W.

This way, a user (or a default setting) could set the file name template to read something as follows:

    %W %Y-%M-%D %H.%m.png

For the current window on bugs.kde.org, it would result in:

    "Enter Bug: Spectacle - Chromium - 2017-01-01 11.30.png"
Comment 1 Roman Inflianskas 2018-02-20 17:16:19 UTC
I'm going to implement this. I found that one way to get active window's title is to use xdotool. Is it OK to add additional dependency?
Comment 2 null 2018-02-20 18:58:05 UTC
Hi Roman,
good to see you here, didn't know you already picked a bug when I wrote my comment in D10683 ;)

I think skaumo got a great idea and it makes sense to implement this feature. (Some ideas in Bugzilla are not so great, so in the future just ask before starting on something, e.g. by opening a task for discussion on https://phabricator.kde.org/project/view/78/).

> one way to get active window's title is to use xdotool
In general calling external binaries is not the best idea. Could you try to find a C/C++ API for this, e.g. similar to what Spectacle is doing in "src/PlatformBackends/" to get to the image of the screen?

I think there must be a way, because e.g. KWin and Plasma's taskbar can show the window title too. Perhaps ask on IRC for tips (but keep in mind that Spectacle must work in a non-Plasma environment too).
Comment 3 Roman Inflianskas 2018-02-21 12:23:37 UTC
See https://phabricator.kde.org/D10709
Comment 4 Roman Inflianskas 2018-03-06 16:44:09 UTC
Git commit d47ab66eb9a2a0ce7a62dabbc3bf632898186b8e by Roman Inflianskas.
Committed on 06/03/2018 at 16:43.
Pushed by romaninflianskas into branch 'master'.

Add optional window title to filename templates

Add '%T' placeholder for filename pattern to insert window title.

Example filenames for pattern `%Y-%M-%D %H-%m-%S. %T`:
2018-02-21 19-11-55. romas : byobu.png
2018-02-21 19-12-20.png

Example filenames for pattern `%T`:
romas : byobu.png

Closes T8036
FIXED-IN: 18.04.0

Test Plan:
# Go to `Configure... -> Save`.
# Enter to `Default Save Filename -> Filename` tempate `%Y-%M-%D %H-%m-%S. %T`.
# Press `OK`.
# Save screenshot.
# Observe that screenshot filename matches pattern.

Examples of filenames with empty window title:
> | Input | Result |
> | --- | --- |
> | Screenshot_%T_ProjectX | Screenshot_ProjectX |
> | %T_ProjectX | ProjectX |
> | Screenshot_%T | Screenshot |
> | %T | Screenshot |

Reviewers: rkflx, #spectacle

Reviewed By: rkflx, #spectacle

Subscribers: ngraham, rkflx

Tags: #spectacle

Maniphest Tasks: T8036

Differential Revision: https://phabricator.kde.org/D10709

M  +1    -0    doc/index.docbook
M  +68   -13   src/ExportManager.cpp
M  +11   -0    src/ExportManager.h
M  +3    -1    src/Gui/SettingsDialog/SaveOptionsPage.cpp
M  +1    -0    src/PlatformBackends/ImageGrabber.h
M  +16   -2    src/PlatformBackends/X11ImageGrabber.cpp
M  +1    -0    src/PlatformBackends/X11ImageGrabber.h
M  +4    -2    src/SpectacleCore.cpp