Skip to content

Commit f2d52f2

Browse files
authored
Replace USE_WAYLAND_GRIM build option with useGrimAdapter setting (flameshot-org#3919)
1 parent be54ae9 commit f2d52f2

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

flameshot.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
;; Whether the tray icon is disabled (bool)
5252
;disabledTrayIcon=false
5353
;
54+
;; Use grim-based wayland universal screenshot adapter
55+
;useGrimAdapter=false
56+
;
5457
;; Disable Grim Warning notification
5558
;disabledGrimWarning=true
5659
;

src/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,10 @@ target_link_libraries(
220220
)
221221

222222
if (USE_WAYLAND_CLIPBOARD)
223-
if(!USE_WAYLAND_GRIM)
224-
message(WARNING "You activated the USE_WAYLAND_CLIPBOARD option, but did not activate the USE_WAYLAND_GRIM option. Flameshot will use the dbus protocol to support wayland. If you use wlroots-based wayland, it is recommended to enable USE_WAYLAND_GRIM")
225-
endif()
226223
target_compile_definitions(flameshot PRIVATE USE_WAYLAND_CLIPBOARD=1)
227224
target_link_libraries(flameshot KF5::GuiAddons)
228225
endif()
229226

230-
if (USE_WAYLAND_GRIM)
231-
target_compile_definitions(flameshot PRIVATE USE_WAYLAND_GRIM=1)
232-
endif()
233-
234227
if (APPLE)
235228
set(MACOSX_BUNDLE_IDENTIFIER "org.flameshot")
236229
set_target_properties(

src/utils/confighandler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static QMap<class QString, QSharedPointer<ValueHandler>>
7979
OPTION("showDesktopNotification" ,Bool ( true )),
8080
OPTION("showAbortNotification" ,Bool ( true )),
8181
OPTION("disabledTrayIcon" ,Bool ( false )),
82+
OPTION("useGrimAdapter" ,Bool ( false )),
8283
OPTION("disabledGrimWarning" ,Bool ( false )),
8384
OPTION("historyConfirmationToDelete" ,Bool ( true )),
8485
#if !defined(DISABLE_UPDATE_CHECKER)

src/utils/confighandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class ConfigHandler : public QObject
8989
CONFIG_GETTER_SETTER(showAbortNotification, setShowAbortNotification, bool)
9090
CONFIG_GETTER_SETTER(filenamePattern, setFilenamePattern, QString)
9191
CONFIG_GETTER_SETTER(disabledTrayIcon, setDisabledTrayIcon, bool)
92+
CONFIG_GETTER_SETTER(useGrimAdapter, useGrimAdapter, bool)
9293
CONFIG_GETTER_SETTER(disabledGrimWarning, disabledGrimWarning, bool)
9394
CONFIG_GETTER_SETTER(drawThickness, setDrawThickness, int)
9495
CONFIG_GETTER_SETTER(drawFontSize, setDrawFontSize, int)

src/utils/screengrabber.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ ScreenGrabber::ScreenGrabber(QObject* parent)
2929

3030
void ScreenGrabber::generalGrimScreenshot(bool& ok, QPixmap& res)
3131
{
32-
#ifdef USE_WAYLAND_GRIM
3332
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
33+
if (!ConfigHandler().useGrimAdapter()) {
34+
return;
35+
}
36+
3437
QString runDir =
3538
QProcessEnvironment::systemEnvironment().value("XDG_RUNTIME_DIR");
3639
QString imgPath = runDir + "/flameshot.ppm";
@@ -53,7 +56,6 @@ void ScreenGrabber::generalGrimScreenshot(bool& ok, QPixmap& res)
5356
"capture component is missing, please install it!");
5457
}
5558
#endif
56-
#endif
5759
}
5860

5961
void ScreenGrabber::freeDesktopPortal(bool& ok, QPixmap& res)
@@ -162,26 +164,26 @@ QPixmap ScreenGrabber::grabEntireDesktop(bool& ok)
162164
case DesktopInfo::SWAY:
163165
case DesktopInfo::HYPRLAND:
164166
case DesktopInfo::OTHER: {
165-
#ifndef USE_WAYLAND_GRIM
166-
if (!ConfigHandler().disabledGrimWarning()) {
167-
AbstractLogger::warning() << tr(
168-
"If the USE_WAYLAND_GRIM option is not activated, the "
169-
"dbus protocol will be used. It should be noted that "
170-
"using the dbus protocol under wayland is not "
171-
"recommended. It is recommended to recompile with the "
172-
"USE_WAYLAND_GRIM flag to activate the grim-based "
173-
"general wayland screenshot adapter");
167+
if (!ConfigHandler().useGrimAdapter()) {
168+
if (!ConfigHandler().disabledGrimWarning()) {
169+
AbstractLogger::warning() << tr(
170+
"If the useGrimAdapter setting is not enabled, the "
171+
"dbus protocol will be used. It should be noted that "
172+
"using the dbus protocol under wayland is not "
173+
"recommended. It is recommended to enable the "
174+
"useGrimAdapter setting in flameshot.ini to activate "
175+
"the grim-based general wayland screenshot adapter");
176+
}
177+
freeDesktopPortal(ok, res);
178+
} else {
179+
if (!ConfigHandler().disabledGrimWarning()) {
180+
AbstractLogger::warning() << tr(
181+
"grim's screenshot component is implemented based on "
182+
"wlroots, it may not be used in GNOME or similar "
183+
"desktop environments");
184+
}
185+
generalGrimScreenshot(ok, res);
174186
}
175-
freeDesktopPortal(ok, res);
176-
#else
177-
if (!ConfigHandler().disabledGrimWarning()) {
178-
AbstractLogger::warning() << tr(
179-
"grim's screenshot component is implemented based on "
180-
"wlroots, it may not be used in GNOME or similar "
181-
"desktop environments");
182-
}
183-
generalGrimScreenshot(ok, res);
184-
#endif
185187
break;
186188
}
187189
default:

0 commit comments

Comments
 (0)