How to Add a Global Hotkey to Flameshot on Ubuntu 16.04
This guide shows how to compile Flameshot on Ubuntu 16.04, integrate the qxtglobalshortcut5 library, register a custom global shortcut (e.g., Ctrl+F5), and use the enhanced tool while noting remaining limitations such as focus‑loss windows and input‑method support.
When working on Linux, many users need a screenshot tool that also supports simple editing and a global hotkey. Flameshot is a popular open‑source Qt‑based utility that lacks a built‑in global shortcut, which makes it inconvenient for workflows that require capturing windows that disappear as soon as they lose focus.
Preparation and Installation
First, download the pre‑built Flameshot package (e.g., from the provided KDocs link) and launch it; clicking Take Screenshot will open the capture window. The default shortcut becomes available only after the first manual capture, and on Ubuntu 16.04 you may need to use Qt 5.5 compiled binaries for the shortcut to work.
Compiling Flameshot on Ubuntu 16.04
Install the required Qt development packages:
sudo apt-get install qt5-default
sudo apt-get install qttools5-dev-tools
sudo apt-get install libqt5svg5-dev
sudo apt-get install libqt5x11extras5-dev
sudo apt-get install qtbase5-private-devClone the Flameshot source code:
git clone https://github.com/lupoDharkael/flameshot.gitBuild the project:
cd flameshot
mkdir build
cd build
qmake ../
make -j$(nproc)
sudo ln -sf `pwd`/flameshot /usr/bin/flameshotAdding Global‑Hotkey Support
1. Clone the qxtglobalshortcut5 library:
cd ..
git clone https://github.com/ddqd/qxtglobalshortcut5.git2. Include the library in the Flameshot project by adding the line include(qxtglobalshortcut5/qxt.pri) to flameshot.pro:
QT += core gui widgets network svg
unix:!macx { QT += dbus }
CONFIG += c++11 link_pkgconfig
include(qxtglobalshortcut5/qxt.pri) # added line
TARGET = flameshot
TEMPLATE = app3. Register the shortcut in src/core/controller.cpp (inside the constructor):
Controller::Controller() : m_captureWindow(nullptr) {
qApp->setQuitOnLastWindowClosed(false);
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
if (!ConfigHandler().disabledTrayIconValue()) {
enableTrayIcon();
}
// Register global hotkey
QxtGlobalShortcut* shortcut1 = new QxtGlobalShortcut(QKeySequence("Ctrl+F5"), this);
connect(shortcut1, SIGNAL(activated()), this, SLOT(shortcutActiveCapture()));
#elif defined(Q_OS_WIN)
enableTrayIcon();
// Windows‑specific handling omitted
#endif
QString StyleSheet = CaptureButton::globalStyleSheet();
qApp->setStyleSheet(StyleSheet);
}4. Declare the slot in src/core/controller.h and implement it in src/core/controller.cpp:
// In controller.h
private slots:
void shortcutActiveCapture(); // added
// In controller.cpp
void Controller::shortcutActiveCapture() {
this->startVisualCapture(0, QString());
}5. Re‑run the build steps (run qmake ../ and make) to produce a new executable that responds to Ctrl+F5 for instant screenshot capture.
Known Limitations
The global shortcut works for most windows, but it cannot capture dialogs that disappear the moment they lose focus (e.g., context menus or tooltips). This is a limitation of X11’s XGrabKey mechanism rather than the library itself; achieving higher priority would require driver‑level interventions.
Additionally, the current implementation only supports English input; integrating Chinese or other input methods would require loading ibus/fcitx plugins, which is not covered here.
Images
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
