Merge pull request #278 from H-M-H/Mac

added Notifications for osx
This commit is contained in:
Dennis Felsing 2015-08-11 04:06:38 +02:00
commit 139c52b394
5 changed files with 48 additions and 1 deletions

View file

@ -283,6 +283,7 @@ function build(settings)
client_settings.link.frameworks:Add("Carbon") client_settings.link.frameworks:Add("Carbon")
client_settings.link.frameworks:Add("Cocoa") client_settings.link.frameworks:Add("Cocoa")
launcher_settings.link.frameworks:Add("Cocoa") launcher_settings.link.frameworks:Add("Cocoa")
client_settings.cc.flags:Add("-I/opt/X11/include")
else else
client_settings.link.libs:Add("X11") client_settings.link.libs:Add("X11")
client_settings.link.libs:Add("GL") client_settings.link.libs:Add("GL")
@ -329,9 +330,14 @@ function build(settings)
-- build tools (TODO: fix this so we don't get double _d_d stuff) -- build tools (TODO: fix this so we don't get double _d_d stuff)
tools_src = Collect("src/tools/*.cpp", "src/tools/*.c") tools_src = Collect("src/tools/*.cpp", "src/tools/*.c")
client_notification = {}
client_osxlaunch = {} client_osxlaunch = {}
server_osxlaunch = {} server_osxlaunch = {}
if platform == "macosx" then if platform == "macosx" then
notification_settings = client_settings:Copy()
notification_settings.cc.flags:Add("-x objective-c++")
notification_settings.cc.flags:Add("-I/System/Library/Frameworks/Foundation.framework/Versions/C/Headers")
client_notification = Compile(notification_settings, "src/osx/notification.m")
client_osxlaunch = Compile(client_settings, "src/osxlaunch/client.m") client_osxlaunch = Compile(client_settings, "src/osxlaunch/client.m")
server_osxlaunch = Compile(launcher_settings, "src/osxlaunch/server.m") server_osxlaunch = Compile(launcher_settings, "src/osxlaunch/server.m")
end end
@ -345,7 +351,7 @@ function build(settings)
-- build client, server, version server and master server -- build client, server, version server and master server
client_exe = Link(client_settings, "DDNet", game_shared, game_client, client_exe = Link(client_settings, "DDNet", game_shared, game_client,
engine, client, game_editor, zlib, pnglite, wavpack, engine, client, game_editor, zlib, pnglite, wavpack,
client_link_other, client_osxlaunch, jsonparser, libwebsockets, md5) client_link_other, client_osxlaunch, jsonparser, libwebsockets, md5, client_notification)
server_exe = Link(server_settings, "DDNet-Server", engine, server, server_exe = Link(server_settings, "DDNet-Server", engine, server,
game_shared, game_server, zlib, server_link_other, libwebsockets, md5) game_shared, game_server, zlib, server_link_other, libwebsockets, md5)

View file

@ -152,6 +152,8 @@ if use_bundle:
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>%s</string> <string>%s</string>
<key>CFBundleIdentifier</key>
<string>org.DDNetClient.app</string>
</dict> </dict>
</plist> </plist>
""" % (version)) """ % (version))

View file

@ -18,6 +18,10 @@
#include <game/client/components/sounds.h> #include <game/client/components/sounds.h>
#include <game/localization.h> #include <game/localization.h>
#ifdef CONF_PLATFORM_MACOSX
#include <osx/notification.h>
#endif
#include "chat.h" #include "chat.h"
@ -469,7 +473,13 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine)
{ {
if(Now-m_aLastSoundPlayed[CHAT_HIGHLIGHT] >= time_freq()*3/10) if(Now-m_aLastSoundPlayed[CHAT_HIGHLIGHT] >= time_freq()*3/10)
{ {
#ifdef CONF_PLATFORM_MACOSX
char aBuf[1024];
str_format(aBuf, sizeof(aBuf), "%s%s", m_aLines[m_CurrentLine].m_aName, m_aLines[m_CurrentLine].m_aText);
CNotification::notify("DDNet-Chat", aBuf);
#else
Graphics()->NotifyWindow(); Graphics()->NotifyWindow();
#endif
if(g_Config.m_SndHighlight) if(g_Config.m_SndHighlight)
{ {
m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_HIGHLIGHT, 0); m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_HIGHLIGHT, 0);

10
src/osx/notification.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef NOTIFICATION_H
#define NOTIFICATION_H
class CNotification
{
public:
static void notify(const char *pTitle, const char *pMsg);
};
#endif // NOTIFICATION_H

19
src/osx/notification.m Normal file
View file

@ -0,0 +1,19 @@
#include <NSString.h>
#include <NSUserNotification.h>
#include <Cocoa/Cocoa.h>
#include "notification.h"
void CNotification::notify(const char *pTitle, const char *pMsg)
{
NSString* title = [NSString stringWithCString:pTitle encoding:NSUTF8StringEncoding];
NSString* msg = [NSString stringWithCString:pMsg encoding:NSUTF8StringEncoding];
NSUserNotification *notification = [[NSUserNotification alloc] autorelease];
notification.title = title;
notification.informativeText = msg;
notification.soundName = NSUserNotificationDefaultSoundName;
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
[NSApp requestUserAttention:NSInformationalRequest]; // use NSCriticalRequest to annoy the user (doesn't stop bouncing)
}