2015-05-06 00:50:57 +00:00
|
|
|
/* Meta-implementation for dynamically-constructing user's preferred
|
|
|
|
* platform interface
|
|
|
|
*/
|
|
|
|
|
2015-08-18 19:40:26 +00:00
|
|
|
#define APPLICATION_UNIX_CPP
|
2015-11-02 10:07:15 +00:00
|
|
|
#include "ApplicationXlib.hpp"
|
2015-08-18 19:40:26 +00:00
|
|
|
#include "ApplicationWayland.hpp"
|
2015-05-06 00:50:57 +00:00
|
|
|
|
2015-08-18 22:43:30 +00:00
|
|
|
#include <memory>
|
2015-05-13 22:21:13 +00:00
|
|
|
#include <dbus/dbus.h>
|
2017-12-29 07:54:26 +00:00
|
|
|
#include <cstdio>
|
2015-05-13 22:21:13 +00:00
|
|
|
|
2018-01-02 05:09:15 +00:00
|
|
|
/* No icon by default */
|
|
|
|
extern "C" const uint8_t MAINICON_NETWM[] __attribute__ ((weak)) = {};
|
|
|
|
extern "C" const size_t MAINICON_NETWM_SZ __attribute__ ((weak)) = 0;
|
|
|
|
|
2015-10-28 01:47:55 +00:00
|
|
|
DBusConnection* RegisterDBus(const char* appName, bool& isFirst)
|
2015-05-13 22:21:13 +00:00
|
|
|
{
|
|
|
|
isFirst = true;
|
|
|
|
DBusError err = {};
|
|
|
|
dbus_error_init(&err);
|
|
|
|
|
|
|
|
/* connect to the bus and check for errors */
|
|
|
|
DBusConnection* conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
|
|
|
|
if (dbus_error_is_set(&err))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "DBus Connection Error (%s)\n", err.message);
|
|
|
|
dbus_error_free(&err);
|
|
|
|
}
|
|
|
|
if (NULL == conn)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* request our name on the bus and check for errors */
|
|
|
|
char busName[256];
|
|
|
|
snprintf(busName, 256, "boo.%s.unique", appName);
|
|
|
|
int ret = dbus_bus_request_name(conn, busName, DBUS_NAME_FLAG_DO_NOT_QUEUE , &err);
|
|
|
|
if (dbus_error_is_set(&err))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "DBus Name Error (%s)\n", err.message);
|
|
|
|
dbus_error_free(&err);
|
|
|
|
dbus_connection_close(conn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret)
|
|
|
|
isFirst = false;
|
|
|
|
|
|
|
|
return conn;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-05-06 00:50:57 +00:00
|
|
|
namespace boo
|
|
|
|
{
|
|
|
|
|
2018-05-20 06:11:49 +00:00
|
|
|
IApplication* APP = nullptr;
|
2015-11-01 00:14:32 +00:00
|
|
|
int ApplicationRun(IApplication::EPlatformType platform,
|
|
|
|
IApplicationCallback& cb,
|
2017-11-13 07:19:49 +00:00
|
|
|
std::string_view uniqueName,
|
|
|
|
std::string_view friendlyName,
|
|
|
|
std::string_view pname,
|
2015-11-01 00:14:32 +00:00
|
|
|
const std::vector<std::string>& args,
|
2018-01-10 06:15:18 +00:00
|
|
|
std::string_view gfxApi,
|
2018-01-07 09:25:30 +00:00
|
|
|
uint32_t samples,
|
|
|
|
uint32_t anisotropy,
|
2018-01-16 06:29:43 +00:00
|
|
|
bool deepColor,
|
2015-11-01 00:14:32 +00:00
|
|
|
bool singleInstance)
|
2015-05-06 00:50:57 +00:00
|
|
|
{
|
2017-11-13 07:19:49 +00:00
|
|
|
std::string thrName = std::string(friendlyName) + " Main Thread";
|
2017-11-08 02:24:07 +00:00
|
|
|
logvisor::RegisterThreadName(thrName.c_str());
|
2015-08-18 22:50:52 +00:00
|
|
|
if (APP)
|
2015-11-01 00:14:32 +00:00
|
|
|
return 1;
|
2015-11-21 01:12:22 +00:00
|
|
|
if (platform == IApplication::EPlatformType::Wayland)
|
2018-01-22 07:33:47 +00:00
|
|
|
APP = new ApplicationWayland(cb, uniqueName, friendlyName, pname, args, gfxApi, samples, anisotropy, deepColor, singleInstance);
|
2015-11-21 01:12:22 +00:00
|
|
|
else if (platform == IApplication::EPlatformType::Xlib ||
|
|
|
|
platform == IApplication::EPlatformType::Auto)
|
2018-01-22 07:33:47 +00:00
|
|
|
APP = new ApplicationXlib(cb, uniqueName, friendlyName, pname, args, gfxApi, samples, anisotropy, deepColor, singleInstance);
|
2015-08-18 22:50:52 +00:00
|
|
|
else
|
2015-11-01 00:14:32 +00:00
|
|
|
return 1;
|
2018-05-20 06:11:49 +00:00
|
|
|
int ret = APP->run();
|
|
|
|
delete APP;
|
|
|
|
APP = nullptr;
|
|
|
|
return ret;
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|