[Scummvm-git-logs] scummvm master -> b0001ef9f62a02b0f7f896a9dbf397b68c152ca2

sev- noreply at scummvm.org
Mon Nov 15 16:45:57 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
b0001ef9f6 BACKENDS: MACOSX: Display OSD messages on the Touchbar


Commit: b0001ef9f62a02b0f7f896a9dbf397b68c152ca2
    https://github.com/scummvm/scummvm/commit/b0001ef9f62a02b0f7f896a9dbf397b68c152ca2
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-11-15T17:45:30+01:00

Commit Message:
BACKENDS: MACOSX: Display OSD messages on the Touchbar

Okay, so Apple now deprecated the Touchbar in their line of
MacBooks. Exciting! Time to finally add support for it!

Changed paths:
  A backends/platform/sdl/macosx/macosx-touchbar.h
  A backends/platform/sdl/macosx/macosx-touchbar.mm
    backends/graphics/opengl/opengl-graphics.cpp
    backends/graphics/surfacesdl/surfacesdl-graphics.cpp
    backends/platform/sdl/macosx/macosx.cpp
    backends/platform/sdl/module.mk


diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index ca1618e1b8..e649e27562 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -38,6 +38,9 @@
 #ifdef USE_OSD
 #include "common/tokenizer.h"
 #include "common/rect.h"
+#if defined(MACOSX)
+#include "backends/platform/sdl/macosx/macosx-touchbar.h"
+#endif
 #endif
 
 #include "graphics/conversion.h"
@@ -578,6 +581,10 @@ void OpenGLGraphicsManager::updateScreen() {
 		if (_osdMessageAlpha <= 0) {
 			delete _osdMessageSurface;
 			_osdMessageSurface = nullptr;
+
+#if defined(MACOSX)
+			macOSTouchbarUpdate(nullptr);
+#endif
 		}
 	}
 
@@ -853,6 +860,10 @@ void OpenGLGraphicsManager::osdMessageUpdateSurface() {
 
 	_osdMessageSurface->updateGLTexture();
 
+#if defined(MACOSX)
+	macOSTouchbarUpdate(_osdMessageNextData.encode().c_str());
+#endif
+
 	// Init the OSD display parameters.
 	_osdMessageAlpha = kOSDMessageInitialAlpha;
 	_osdMessageFadeStartTime = g_system->getMillis() + kOSDMessageFadeOutDelay;
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index 412e9c3d01..b0ce6af1b7 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -50,6 +50,12 @@
 #endif
 #include "common/text-to-speech.h"
 
+#ifdef USE_OSD
+#if defined(MACOSX)
+#include "backends/platform/sdl/macosx/macosx-touchbar.h"
+#endif
+#endif
+
 // SDL surface flags which got removed in SDL2.
 #if SDL_VERSION_ATLEAST(2, 0, 0)
 #define SDL_SRCCOLORKEY 0
@@ -2253,6 +2259,9 @@ void SurfaceSdlGraphicsManager::displayMessageOnOSD(const Common::U32String &msg
 	// Enable alpha blending
 	SDL_SetAlpha(_osdMessageSurface, SDL_RLEACCEL | SDL_SRCALPHA, _osdMessageAlpha);
 
+#if defined(MACOSX)
+	macOSTouchbarUpdate(msg.encode().c_str());
+#endif
 	// Ensure a full redraw takes place next time the screen is updated
 	_forceRedraw = true;
 	if (ConfMan.hasKey("tts_enabled", "scummvm") &&
@@ -2334,6 +2343,10 @@ void SurfaceSdlGraphicsManager::removeOSDMessage() {
 
 	_osdMessageSurface = nullptr;
 	_osdMessageAlpha = SDL_ALPHA_TRANSPARENT;
+
+#if defined(MACOSX)
+	macOSTouchbarUpdate(nullptr);
+#endif
 }
 
 void SurfaceSdlGraphicsManager::updateOSD() {
diff --git a/backends/platform/sdl/macosx/macosx-touchbar.h b/backends/platform/sdl/macosx/macosx-touchbar.h
new file mode 100644
index 0000000000..6edb6e4e62
--- /dev/null
+++ b/backends/platform/sdl/macosx/macosx-touchbar.h
@@ -0,0 +1,34 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef PLATFORM_SDL_MACOSX_TOUCHBAR_H
+#define PLATFORM_SDL_MACOSX_TOUCHBAR_H
+
+#if defined(MACOSX)
+
+void macOSTouchbarCreate();
+void macOSTouchbarDestroy();
+void macOSTouchbarUpdate(const char *message);
+
+#endif // MACOSX
+
+#endif
diff --git a/backends/platform/sdl/macosx/macosx-touchbar.mm b/backends/platform/sdl/macosx/macosx-touchbar.mm
new file mode 100644
index 0000000000..32485d1471
--- /dev/null
+++ b/backends/platform/sdl/macosx/macosx-touchbar.mm
@@ -0,0 +1,123 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+// Disable symbol overrides so that we can use system headers.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
+#include "backends/platform/sdl/macosx/appmenu_osx.h"
+
+#include "backends/platform/sdl/macosx/macosx-compat.h"
+#include <Cocoa/Cocoa.h>
+#include <AppKit/NSWorkspace.h>
+
+#if defined(MAC_OS_X_VERSION_10_12) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
+
+ at interface ScummVMlTouchbarDelegate : NSResponder <NSTouchBarDelegate>
+ at end
+
+ at implementation ScummVMlTouchbarDelegate
+NSColor *font_color;
+NSColor *back_color;
+NSButton *tbButton;
+
+- (instancetype)init {
+	if (self = [super init]) {
+		font_color = [NSColor whiteColor];
+		back_color = [NSColor colorWithCalibratedRed:0 green:0.8 blue:0.2 alpha:1.0f];
+
+		tbButton = [[NSButton alloc] init];
+		[[tbButton cell] setBackgroundColor:back_color];
+		[tbButton setAction:@selector(actionKey:)];
+		[tbButton setTarget:self];
+
+		[self setButton:nullptr];
+	}
+	return self;
+}
+
+- (NSTouchBar *)makeTouchBar {
+	NSTouchBar *bar = [[NSTouchBar alloc] init];
+
+	bar.delegate = self;
+	bar.customizationIdentifier = @"org.ScummVM.Touchbar.Customization";
+	bar.defaultItemIdentifiers = @[@"textButton"];
+
+	return bar;
+}
+
+- (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier {
+	NSCustomTouchBarItem *customItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:@"textButton"];
+	customItem.view = tbButton;
+	customItem.visibilityPriority = NSTouchBarItemPriorityHigh;
+
+	return customItem;
+}
+
+- (void)setButton : (const char *)title {
+	NSString *ns_title = nullptr;
+	if (title) {
+		ns_title = [NSString stringWithUTF8String:title];
+	} else {
+		ns_title = [NSString stringWithUTF8String:"ScummVM"];
+	}
+
+	NSMutableAttributedString *att_title = [[NSMutableAttributedString alloc] initWithString:ns_title];
+
+	[tbButton setAttributedTitle:att_title];
+	[tbButton invalidateIntrinsicContentSize];
+}
+
+
+ at end
+
+static ScummVMlTouchbarDelegate *g_tb_delegate = nullptr;
+
+void macOSTouchbarUpdate(const char *message) {
+	[g_tb_delegate setButton:message];
+}
+
+void macOSTouchbarCreate() {
+	if (g_tb_delegate)
+		return;
+
+	NSApplication *app = [NSApplication sharedApplication];
+	if (!app)
+		return;
+
+	g_tb_delegate = [[ScummVMlTouchbarDelegate alloc] init];
+
+	if (g_tb_delegate) {
+		g_tb_delegate.nextResponder = app.nextResponder;
+		app.nextResponder = g_tb_delegate;
+	}
+}
+
+void macOSTouchbarDestroy() {
+}
+
+#else
+
+void macOSTouchbarCreate() {}
+void macOSTouchbarDestroy() {}
+void macOSTouchbarUpdate(const char *message) {}
+
+#endif
diff --git a/backends/platform/sdl/macosx/macosx.cpp b/backends/platform/sdl/macosx/macosx.cpp
index 52945c34cf..e79216bc82 100644
--- a/backends/platform/sdl/macosx/macosx.cpp
+++ b/backends/platform/sdl/macosx/macosx.cpp
@@ -30,6 +30,7 @@
 #include "backends/audiocd/macosx/macosx-audiocd.h"
 #include "backends/platform/sdl/macosx/appmenu_osx.h"
 #include "backends/platform/sdl/macosx/macosx.h"
+#include "backends/platform/sdl/macosx/macosx-touchbar.h"
 #include "backends/platform/sdl/macosx/macosx-window.h"
 #include "backends/updates/macosx/macosx-updates.h"
 #include "backends/taskbar/macosx/macosx-taskbar.h"
@@ -60,6 +61,10 @@ void *coreMIDIthread(void *threadarg) {
 
 OSystem_MacOSX::~OSystem_MacOSX() {
 	releaseMenu();
+
+#if defined(USE_OSD)
+	macOSTouchbarDestroy();
+#endif
 }
 
 void OSystem_MacOSX::init() {
@@ -76,6 +81,10 @@ void OSystem_MacOSX::init() {
 	_dialogManager = new MacOSXDialogManager();
 #endif
 
+#if defined(USE_OSD)
+	macOSTouchbarCreate();
+#endif
+
 	// The call to query the number of MIDI devices is ubiquitously slow
 	// on the first run. This is apparent when opening Options in GUI,
 	// which takes 2-3 secs.
diff --git a/backends/platform/sdl/module.mk b/backends/platform/sdl/module.mk
index 277882afed..68f5db876c 100644
--- a/backends/platform/sdl/module.mk
+++ b/backends/platform/sdl/module.mk
@@ -14,6 +14,7 @@ ifdef MACOSX
 MODULE_OBJS += \
 	macosx/macosx-main.o \
 	macosx/macosx.o \
+	macosx/macosx-touchbar.o \
 	macosx/macosx-window.o \
 	macosx/macosx_wrapper.o \
 	macosx/appmenu_osx.o




More information about the Scummvm-git-logs mailing list