Blender  V2.93
GHOST_TaskbarX11.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "GHOST_TaskbarX11.h"
22 
23 #include <cassert>
24 #include <cstdio>
25 #include <cstdlib>
26 #include <dlfcn.h>
27 
28 typedef void *(*unity_get_entry_t)(const char *);
29 typedef void (*unity_set_progress_t)(void *, double);
30 typedef void (*unity_set_progress_visible_t)(void *, int);
31 typedef int (*unity_event_loop_t)(void *, int);
32 
37 
38 static bool libunity_initialized = false;
39 static bool libunity_available = false;
40 static void *libunity_handle = NULL;
41 
43 {
44  if (libunity_handle) {
45  dlclose(libunity_handle);
47  }
48 }
49 
51 {
53  return libunity_available;
54  }
55 
56  libunity_initialized = true;
57 
58  const char *libunity_names[] = {
59  "libunity.so.4", "libunity.so.6", "libunity.so.9", "libunity.so", NULL};
60  for (int i = 0; libunity_names[i]; i++) {
61  libunity_handle = dlopen(libunity_names[i], RTLD_LAZY);
62  if (libunity_handle) {
63  break;
64  }
65  }
66 
67  if (!libunity_handle) {
68  return false;
69  }
70 
72  "unity_launcher_entry_get_for_desktop_id");
73  if (!unity_get_entry) {
74  fprintf(stderr, "failed to load libunity: %s\n", dlerror());
75  return false;
76  }
78  "unity_launcher_entry_set_progress");
79  if (!unity_set_progress) {
80  fprintf(stderr, "failed to load libunity: %s\n", dlerror());
81  return false;
82  }
84  libunity_handle, "unity_launcher_entry_set_progress_visible");
86  fprintf(stderr, "failed to load libunity: %s\n", dlerror());
87  return false;
88  }
89  unity_event_loop = (unity_event_loop_t)dlsym(libunity_handle, "g_main_context_iteration");
90  if (!unity_event_loop) {
91  fprintf(stderr, "failed to load libunity: %s\n", dlerror());
92  return false;
93  }
94 
95  atexit(GHOST_TaskBarX11::free);
96 
97  libunity_available = true;
98  return true;
99 }
100 
102 {
103  if (GHOST_TaskBarX11::init()) {
104  handle = unity_get_entry(name);
105  }
106  else {
107  handle = NULL;
108  }
109 }
110 
112 {
113  return (handle != NULL);
114 }
115 
116 void GHOST_TaskBarX11::set_progress(double progress)
117 {
118  assert(is_valid());
119  unity_set_progress(handle, progress);
120 }
121 
123 {
124  assert(is_valid());
125  unity_set_progress_visible(handle, enabled ? 1 : 0);
127 }
typedef double(DMatrix)[4][4]
static unity_event_loop_t unity_event_loop
static bool libunity_available
int(* unity_event_loop_t)(void *, int)
static unity_set_progress_visible_t unity_set_progress_visible
static bool libunity_initialized
static unity_set_progress_t unity_set_progress
void *(* unity_get_entry_t)(const char *)
static unity_get_entry_t unity_get_entry
void(* unity_set_progress_visible_t)(void *, int)
void(* unity_set_progress_t)(void *, double)
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()
bool enabled