Skip to content

Commit bc5fedb

Browse files
ShadyNawaraCalcProgrammer1
authored andcommitted
Hide dock icon on minimize macOS
1 parent 6cd4dc8 commit bc5fedb

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

OpenRGB.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,11 +1421,13 @@ macx {
14211421

14221422
HEADERS += \
14231423
AutoStart/AutoStart-MacOS.h \
1424+
qt/macutils.h \
14241425

14251426
SOURCES += \
14261427
dependencies/hueplusplus-1.0.0/src/LinHttpHandler.cpp \
14271428
serial_port/find_usb_serial_port_linux.cpp \
14281429
AutoStart/AutoStart-MacOS.cpp \
1430+
qt/macutils.mm \
14291431

14301432
# Use mbedtls v2 instead of latest
14311433
MBEDTLS_PREFIX = $$system(brew --prefix mbedtls@2)

main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222
#include "OpenRGBDialog2.h"
2323

24+
#ifdef __APPLE__
25+
#include "macutils.h"
26+
#endif
27+
2428
using namespace std::chrono_literals;
2529

2630
/*-------------------------------------------------------------*\
@@ -339,6 +343,9 @@ int main(int argc, char* argv[])
339343

340344
if(ret_flags & RET_FLAG_START_MINIMIZED)
341345
{
346+
#ifdef __APPLE__
347+
MacUtils::ToggleApplicationDocklessState(false);
348+
#endif
342349
dlg.hide();
343350
}
344351
else

qt/OpenRGBDialog2.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#include <QCloseEvent>
1919
#include <QStyleFactory>
2020

21+
#ifdef __APPLE__
22+
#include "macutils.h"
23+
#endif
24+
2125
using namespace Ui;
2226

2327
static QString GetIconString(device_type type, bool dark)
@@ -486,6 +490,9 @@ void OpenRGBDialog2::closeEvent(QCloseEvent *event)
486490

487491
if (IsMinimizeOnClose() && !this->isHidden())
488492
{
493+
#ifdef __APPLE__
494+
MacUtils::ToggleApplicationDocklessState(false);
495+
#endif
489496
hide();
490497
event->ignore();
491498
}
@@ -1382,10 +1389,16 @@ void OpenRGBDialog2::on_ShowHide()
13821389
{
13831390
if(isHidden())
13841391
{
1392+
#ifdef __APPLE__
1393+
MacUtils::ToggleApplicationDocklessState(true);
1394+
#endif
13851395
show();
13861396
}
13871397
else
13881398
{
1399+
#ifdef __APPLE__
1400+
MacUtils::ToggleApplicationDocklessState(false);
1401+
#endif
13891402
hide();
13901403
}
13911404
}

qt/macutils.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef MACUTILS_H
2+
#define MACUTILS_H
3+
4+
class MacUtils
5+
{
6+
public:
7+
static void ToggleApplicationDocklessState(bool showDock);
8+
};
9+
10+
#endif // MACUTILS_H

qt/macutils.mm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#import <Cocoa/Cocoa.h>
2+
#include "macutils.h"
3+
4+
void MacUtils::ToggleApplicationDocklessState(bool showDock)
5+
{
6+
ProcessApplicationTransformState transformState = showDock ? ProcessApplicationTransformState(kProcessTransformToForegroundApplication) : ProcessApplicationTransformState(kProcessTransformToUIElementApplication);
7+
ProcessSerialNumber psn = { 0, kCurrentProcess };
8+
TransformProcessType(&psn, transformState);
9+
}

0 commit comments

Comments
 (0)