dbus_glfw.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //========================================================================
  2. // GLFW 3.4 XKB - www.glfw.org
  3. //------------------------------------------------------------------------
  4. // Copyright (c) 2018 Kovid Goyal <kovid@kovidgoyal.net>
  5. //
  6. // This software is provided 'as-is', without any express or implied
  7. // warranty. In no event will the authors be held liable for any damages
  8. // arising from the use of this software.
  9. //
  10. // Permission is granted to anyone to use this software for any purpose,
  11. // including commercial applications, and to alter it and redistribute it
  12. // freely, subject to the following restrictions:
  13. //
  14. // 1. The origin of this software must not be misrepresented; you must not
  15. // claim that you wrote the original software. If you use this software
  16. // in a product, an acknowledgment in the product documentation would
  17. // be appreciated but is not required.
  18. //
  19. // 2. Altered source versions must be plainly marked as such, and must not
  20. // be misrepresented as being the original software.
  21. //
  22. // 3. This notice may not be removed or altered from any source
  23. // distribution.
  24. //
  25. //========================================================================
  26. #pragma once
  27. #include <dbus/dbus.h>
  28. #include "backend_utils.h"
  29. static inline void cleanup_msg(void *p) { DBusMessage *m = *(DBusMessage**)p; if (m) dbus_message_unref(m); m = NULL; }
  30. #define RAII_MSG(name, initializer) __attribute__((cleanup(cleanup_msg))) DBusMessage *name = initializer
  31. typedef void(*dbus_pending_callback)(DBusMessage *msg, const char* err, void* data);
  32. typedef struct {
  33. EventLoopData* eld;
  34. } _GLFWDBUSData;
  35. bool glfw_dbus_init(_GLFWDBUSData *dbus, EventLoopData *eld);
  36. void glfw_dbus_terminate(_GLFWDBUSData *dbus);
  37. DBusConnection* glfw_dbus_connect_to(const char *path, const char* err_msg, const char* name, bool register_on_bus);
  38. void glfw_dbus_close_connection(DBusConnection *conn);
  39. bool
  40. call_method_with_msg(DBusConnection *conn, DBusMessage *msg, int timeout, dbus_pending_callback callback, void *user_data);
  41. bool
  42. glfw_dbus_call_method_no_reply(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...);
  43. bool
  44. glfw_dbus_call_method_with_reply(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, int timeout_ms, dbus_pending_callback callback, void *user_data, ...);
  45. void glfw_dbus_dispatch(DBusConnection *);
  46. void glfw_dbus_session_bus_dispatch(void);
  47. bool glfw_dbus_get_args(DBusMessage *msg, const char *failmsg, ...);
  48. int glfw_dbus_match_signal(DBusMessage *msg, const char *interface, ...);
  49. DBusConnection* glfw_dbus_session_bus(void);