Blender  V3.3
GHOST_TaskbarX11.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "GHOST_TaskbarX11.h"
8 
9 #include <cassert>
10 #include <cstdio>
11 #include <cstdlib>
12 #include <dlfcn.h>
13 
14 using unity_get_entry_t = void *(*)(const char *);
15 using unity_set_progress_t = void (*)(void *, double);
16 using unity_set_progress_visible_t = void (*)(void *, int);
17 using unity_event_loop_t = int (*)(void *, int);
18 
23 
24 static bool libunity_initialized = false;
25 static bool libunity_available = false;
26 static void *libunity_handle = nullptr;
27 
29 {
30  if (libunity_handle) {
31  dlclose(libunity_handle);
32  libunity_handle = nullptr;
33  }
34 }
35 
37 {
39  return libunity_available;
40  }
41 
42  libunity_initialized = true;
43 
44  const char *libunity_names[] = {
45  "libunity.so.4", "libunity.so.6", "libunity.so.9", "libunity.so", nullptr};
46  for (int i = 0; libunity_names[i]; i++) {
47  libunity_handle = dlopen(libunity_names[i], RTLD_LAZY);
48  if (libunity_handle) {
49  break;
50  }
51  }
52 
53  if (!libunity_handle) {
54  return false;
55  }
56 
58  "unity_launcher_entry_get_for_desktop_id");
59  if (!unity_get_entry) {
60  fprintf(stderr, "failed to load libunity: %s\n", dlerror());
61  return false;
62  }
64  "unity_launcher_entry_set_progress");
65  if (!unity_set_progress) {
66  fprintf(stderr, "failed to load libunity: %s\n", dlerror());
67  return false;
68  }
70  libunity_handle, "unity_launcher_entry_set_progress_visible");
72  fprintf(stderr, "failed to load libunity: %s\n", dlerror());
73  return false;
74  }
75  unity_event_loop = (unity_event_loop_t)dlsym(libunity_handle, "g_main_context_iteration");
76  if (!unity_event_loop) {
77  fprintf(stderr, "failed to load libunity: %s\n", dlerror());
78  return false;
79  }
80 
81  atexit(GHOST_TaskBarX11::free);
82 
83  libunity_available = true;
84  return true;
85 }
86 
88 {
89  if (GHOST_TaskBarX11::init()) {
90  handle = unity_get_entry(name);
91  }
92  else {
93  handle = nullptr;
94  }
95 }
96 
98 {
99  return (handle != nullptr);
100 }
101 
102 void GHOST_TaskBarX11::set_progress(double progress)
103 {
104  assert(is_valid());
105  unity_set_progress(handle, progress);
106 }
107 
109 {
110  assert(is_valid());
111  unity_set_progress_visible(handle, enabled ? 1 : 0);
112  unity_event_loop(nullptr, 0);
113 }
typedef double(DMatrix)[4][4]
static unity_event_loop_t unity_event_loop
void(*)(void *, double) unity_set_progress_t
static bool libunity_available
int(*)(void *, int) unity_event_loop_t
void(*)(void *, int) unity_set_progress_visible_t
static unity_set_progress_visible_t unity_set_progress_visible
static bool libunity_initialized
void *(*)(const char *) unity_get_entry_t
static unity_set_progress_t unity_set_progress
static unity_get_entry_t unity_get_entry
static void * libunity_handle
GHOST_TaskBarX11(const char *name)
void set_progress(double progress)
void set_progress_enabled(bool enabled)
static bool init()
static void free()
SyclQueue void void size_t num_bytes void
bool enabled