Port Win32 Discord integration to Linux and macOS
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
# WIN32 marks us as a GUI app on Windows
|
||||
add_executable(86Box WIN32 MACOSX_BUNDLE 86box.c config.c log.c random.c timer.c io.c acpi.c apm.c
|
||||
dma.c ddma.c nmi.c pic.c pit.c port_6x.c port_92.c ppi.c pci.c mca.c usb.c fifo8.c
|
||||
dma.c ddma.c discord.c nmi.c pic.c pit.c port_6x.c port_92.c ppi.c pci.c mca.c usb.c fifo8.c
|
||||
device.c nvr.c nvr_at.c nvr_ps2.c)
|
||||
|
||||
if(CPPTHREADS)
|
||||
|
@@ -19,18 +19,23 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <windows.h>
|
||||
#include <time.h>
|
||||
#define HAVE_STDARG_H
|
||||
#include <86box/86box.h>
|
||||
#include "cpu.h"
|
||||
#include "cpu/cpu.h"
|
||||
#include <86box/machine.h>
|
||||
#include <86box/plat.h>
|
||||
#include <86box/plat_dynld.h>
|
||||
#include <86box/win_discord.h>
|
||||
#include <86box/discord.h>
|
||||
#include <discord_game_sdk.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define PATH_DISCORD_DLL "discord_game_sdk.dll"
|
||||
#elif defined __APPLE__
|
||||
#define PATH_DISCORD_DLL "discord_game_sdk.dylib"
|
||||
#else
|
||||
#define PATH_DISCORD_DLL "discord_game_sdk.so"
|
||||
#endif
|
||||
|
||||
int discord_loaded = 0;
|
||||
|
||||
@@ -74,7 +79,7 @@ discord_update_activity(int paused)
|
||||
if(discord_activities == NULL)
|
||||
return;
|
||||
|
||||
discord_log("win_discord: discord_update_activity(paused=%d)\n", paused);
|
||||
discord_log("discord: discord_update_activity(paused=%d)\n", paused);
|
||||
|
||||
memset(&activity, 0x00, sizeof(activity));
|
||||
|
||||
@@ -85,13 +90,13 @@ discord_update_activity(int paused)
|
||||
|
||||
if (strlen(vm_name) < 100)
|
||||
{
|
||||
sprintf_s(activity.details, sizeof(activity.details), "Running \"%s\"", vm_name);
|
||||
sprintf_s(activity.state, sizeof(activity.state), "%s (%s/%s)", strchr(machine_getname(), ']') + 2, cpufamily, cpu_s->name);
|
||||
snprintf(activity.details, sizeof(activity.details), "Running \"%s\"", vm_name);
|
||||
snprintf(activity.state, sizeof(activity.state), "%s (%s/%s)", strchr(machine_getname(), ']') + 2, cpufamily, cpu_s->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(activity.details, strchr(machine_getname(), ']') + 2, sizeof(activity.details) - 1);
|
||||
sprintf_s(activity.state, sizeof(activity.state), "%s/%s", cpufamily, cpu_s->name);
|
||||
snprintf(activity.state, sizeof(activity.state), "%s/%s", cpufamily, cpu_s->name);
|
||||
}
|
||||
|
||||
activity.timestamps.start = time(NULL);
|
||||
@@ -139,7 +144,7 @@ discord_load()
|
||||
|
||||
if (discord_handle == NULL)
|
||||
{
|
||||
discord_log("win_discord: couldn't load " PATH_DISCORD_DLL "\n");
|
||||
discord_log("discord: couldn't load " PATH_DISCORD_DLL "\n");
|
||||
discord_close();
|
||||
|
||||
return(0);
|
||||
@@ -165,7 +170,7 @@ discord_init()
|
||||
result = discord_create(DISCORD_VERSION, ¶ms, &discord_core);
|
||||
if (result != DiscordResult_Ok)
|
||||
{
|
||||
discord_log("win_discord: DiscordCreate returned %d\n", result);
|
||||
discord_log("discord: DiscordCreate returned %d\n", result);
|
||||
discord_close();
|
||||
return;
|
||||
}
|
@@ -17,6 +17,11 @@
|
||||
#ifndef WIN_DISCORD_H
|
||||
# define WIN_DISCORD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern int discord_loaded;
|
||||
|
||||
extern int discord_load();
|
||||
@@ -25,4 +30,8 @@ extern void discord_close();
|
||||
extern void discord_update_activity(int paused);
|
||||
extern void discord_run_callbacks();
|
||||
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@@ -26,6 +26,7 @@ Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin)
|
||||
#include <86box/plat.h>
|
||||
#include <86box/ui.h>
|
||||
#include <86box/video.h>
|
||||
#include <86box/discord.h>
|
||||
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
@@ -127,6 +128,7 @@ int main(int argc, char* argv[]) {
|
||||
return 6;
|
||||
}
|
||||
|
||||
discord_load();
|
||||
main_window = new MainWindow();
|
||||
main_window->show();
|
||||
app.installEventFilter(main_window);
|
||||
@@ -148,10 +150,24 @@ int main(int argc, char* argv[]) {
|
||||
// plat_pause(0);
|
||||
if (settings_only) dopause = 1;
|
||||
QTimer onesec;
|
||||
QTimer discordupdate;
|
||||
QObject::connect(&onesec, &QTimer::timeout, &app, [] {
|
||||
pc_onesec();
|
||||
});
|
||||
onesec.start(1000);
|
||||
if (discord_loaded) {
|
||||
QTimer::singleShot(1000, &app, [] {
|
||||
if (enable_discord) {
|
||||
discord_init();
|
||||
discord_update_activity(dopause);
|
||||
} else
|
||||
discord_close();
|
||||
});
|
||||
QObject::connect(&discordupdate, &QTimer::timeout, &app, [] {
|
||||
discord_run_callbacks();
|
||||
});
|
||||
discordupdate.start(0);
|
||||
}
|
||||
|
||||
/* Initialize the rendering window, or fullscreen. */
|
||||
auto main_thread = std::thread([] {
|
||||
|
@@ -13,6 +13,7 @@ extern "C" {
|
||||
#include <86box/config.h>
|
||||
#include <86box/keyboard.h>
|
||||
#include <86box/plat.h>
|
||||
#include <86box/discord.h>
|
||||
#include <86box/video.h>
|
||||
#include <86box/vid_ega.h>
|
||||
#include <86box/version.h>
|
||||
@@ -152,6 +153,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
ui->actionHiDPI_scaling->setChecked(dpi_scale);
|
||||
ui->actionHide_status_bar->setChecked(hide_status_bar);
|
||||
ui->actionUpdate_status_bar_icons->setChecked(update_icons);
|
||||
ui->actionEnable_Discord_integration->setChecked(enable_discord);
|
||||
|
||||
#if defined Q_OS_WINDOWS || defined Q_OS_MACOS
|
||||
/* Make the option visible only if ANGLE is loaded. */
|
||||
@@ -420,7 +422,8 @@ void MainWindow::on_actionSettings_triggered() {
|
||||
plat_pause(currentPause);
|
||||
if (settings_only) {
|
||||
cpu_thread_run = 0;
|
||||
close();
|
||||
config_save();
|
||||
QApplication::quit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1392,3 +1395,14 @@ void MainWindow::on_actionPreferences_triggered()
|
||||
progsettings.exec();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionEnable_Discord_integration_triggered(bool checked)
|
||||
{
|
||||
enable_discord = checked;
|
||||
if(enable_discord) {
|
||||
discord_init();
|
||||
discord_update_activity(dopause);
|
||||
} else
|
||||
discord_close();
|
||||
}
|
||||
|
||||
|
@@ -103,6 +103,8 @@ private slots:
|
||||
|
||||
void on_actionPreferences_triggered();
|
||||
|
||||
void on_actionEnable_Discord_integration_triggered(bool checked);
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
void keyReleaseEvent(QKeyEvent* event) override;
|
||||
|
@@ -73,6 +73,8 @@
|
||||
<addaction name="actionSettings"/>
|
||||
<addaction name="actionUpdate_status_bar_icons"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionEnable_Discord_integration"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionTake_screenshot"/>
|
||||
<addaction name="actionSound_gain"/>
|
||||
<addaction name="separator"/>
|
||||
@@ -554,6 +556,14 @@
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionEnable_Discord_integration">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Enable &Discord integration</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
@@ -67,6 +67,7 @@ extern "C" {
|
||||
#include <86box/plat_dynld.h>
|
||||
#include <86box/config.h>
|
||||
#include <86box/ui.h>
|
||||
#include <86box/discord.h>
|
||||
|
||||
#include "../cpu/cpu.h"
|
||||
#include <86box/plat.h>
|
||||
@@ -339,7 +340,7 @@ plat_pause(int p)
|
||||
wchar_t title[512];
|
||||
|
||||
if ((p == 0) && (time_sync & TIME_SYNC_ENABLED))
|
||||
nvr_time_sync();
|
||||
nvr_time_sync();
|
||||
|
||||
dopause = p;
|
||||
if (p) {
|
||||
@@ -350,6 +351,7 @@ plat_pause(int p)
|
||||
} else {
|
||||
ui_window_title(oldtitle);
|
||||
}
|
||||
discord_update_activity(dopause);
|
||||
}
|
||||
|
||||
// because we can't include nvr.h because it's got fields named new
|
||||
|
@@ -20,7 +20,7 @@ add_library(plat OBJECT win.c win_dynld.c win_cdrom.c win_keyboard.c
|
||||
|
||||
add_library(ui OBJECT win_ui.c win_icon.c win_stbar.c win_sdl.c win_dialog.c win_about.c
|
||||
win_settings.c win_devconf.c win_snd_gain.c win_specify_dim.c win_new_floppy.c
|
||||
win_jsconf.c win_media_menu.c win_preferences.c win_discord.c glad.c win_opengl.c
|
||||
win_jsconf.c win_media_menu.c win_preferences.c glad.c win_opengl.c
|
||||
win_opengl_glslp.c 86Box.rc)
|
||||
|
||||
if(NOT CPPTHREADS)
|
||||
|
Reference in New Issue
Block a user