Bug 378463

Summary: Use window title to suggest file names
Product: [Applications] Spectacle Reporter: skaumo
Component: GeneralAssignee: Boudhayan Gupta <me>
Status: RESOLVED FIXED    
Severity: wishlist CC: infroma, null
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 18.04.0

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

Summary:
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
Screenshot.png

Closes T8036
FIXED-IN: 18.04.0

Test Plan:
Steps:
# 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

https://commits.kde.org/spectacle/d47ab66eb9a2a0ce7a62dabbc3bf632898186b8e