static gboolean clipboard_request(SpiceMainChannel *main, guint selection, guint type, gpointer user_data) { g_return_val_if_fail(SPICE_IS_GTK_SESSION(user_data), FALSE); SpiceGtkSession *self = user_data; SpiceGtkSessionPrivate *s = self->priv; GdkAtom atom; GtkClipboard* cb; int m; if (read_only(self)) return FALSE; cb = get_clipboard_from_selection(s, selection); g_return_val_if_fail(cb != NULL, FALSE); for (m = 0; m < SPICE_N_ELEMENTS(atom2agent); m++) { if (atom2agent[m].vdagent == type) break; } g_return_val_if_fail(m < SPICE_N_ELEMENTS(atom2agent), FALSE); atom = gdk_atom_intern_static_string(atom2agent[m].xatom); gtk_clipboard_request_contents(cb, atom, clipboard_received_cb, weak_ref(G_OBJECT(self))); return TRUE; }
weak_ref weak_ref::create(lua_State * L) { boost::shared_ptr<int> ref(new int(LUA_NOREF)); lua_newtable(L); lua_pushinteger(L, 1); lua_pushvalue(L, -3); lua_settable(L, -3); lua_pushinteger(L, 2); new (lua_newuserdata(L, sizeof(boost::shared_ptr<int>))) boost::shared_ptr<int>(ref); lua_newtable(L); lua_pushliteral(L, "__gc"); lua_pushcfunction(L, __gc); lua_settable(L, -3); lua_setmetatable(L, -2); lua_settable(L, -3); *ref = luaL_ref(L, LUA_REGISTRYINDEX); lua_pop(L, 1); return weak_ref(boost::weak_ptr<int>(ref)); }
/** * spice_gtk_session_copy_to_guest: * @self: * * Copy client-side clipboard to guest clipboard. * * Since 0.8 **/ void spice_gtk_session_copy_to_guest(SpiceGtkSession *self) { g_return_if_fail(SPICE_IS_GTK_SESSION(self)); g_return_if_fail(read_only(self) == FALSE); SpiceGtkSessionPrivate *s = self->priv; int selection = VD_AGENT_CLIPBOARD_SELECTION_CLIPBOARD; if (s->clip_hasdata[selection] && !s->clip_grabbed[selection]) { gtk_clipboard_request_targets(s->clipboard, clipboard_get_targets, weak_ref(G_OBJECT(self))); } }
static obs_hotkey_pair_id register_hotkey_pair_internal( obs_hotkey_registerer_t type, void *registerer, void *(*weak_ref)(void*), struct obs_context_data *context, const char *name0, const char *description0, const char *name1, const char *description1, obs_hotkey_active_func func0, obs_hotkey_active_func func1, void *data0, void *data1) { if (!lock()) return OBS_INVALID_HOTKEY_PAIR_ID; obs_hotkey_pair_t *pair = create_hotkey_pair(context, func0, func1, data0, data1); pair->id[0] = obs_hotkey_register_internal( type, weak_ref(registerer), context, name0, description0, obs_hotkey_pair_first_func, pair); pair->id[1] = obs_hotkey_register_internal( type, weak_ref(registerer), context, name1, description1, obs_hotkey_pair_second_func, pair); size_t idx; if (find_id(pair->id[0], &idx)) obs->hotkeys.hotkeys.array[idx].pair_partner_id = pair->id[1]; if (find_id(pair->id[1], &idx)) obs->hotkeys.hotkeys.array[idx].pair_partner_id = pair->id[0]; obs_hotkey_pair_id id = pair->pair_id; unlock(); return id; }
static void clipboard_owner_change(GtkClipboard *clipboard, GdkEventOwnerChange *event, gpointer user_data) { g_return_if_fail(SPICE_IS_GTK_SESSION(user_data)); SpiceGtkSession *self = user_data; SpiceGtkSessionPrivate *s = self->priv; int selection; selection = get_selection_from_clipboard(s, clipboard); g_return_if_fail(selection != -1); if (s->main == NULL) return; if (s->clip_grabbed[selection]) { s->clip_grabbed[selection] = FALSE; if (spice_main_agent_test_capability(s->main, VD_AGENT_CAP_CLIPBOARD_BY_DEMAND)) spice_main_clipboard_selection_release(s->main, selection); } switch (event->reason) { case GDK_OWNER_CHANGE_NEW_OWNER: if (gtk_clipboard_get_owner(clipboard) == G_OBJECT(self)) break; s->clipboard_by_guest[selection] = FALSE; s->clip_hasdata[selection] = TRUE; if (s->auto_clipboard_enable && !read_only(self)) gtk_clipboard_request_targets(clipboard, clipboard_get_targets, weak_ref(G_OBJECT(self))); break; default: s->clip_hasdata[selection] = FALSE; break; } }
void inject_backref(lua_State* L, T* p, wrap_base*) { weak_ref(get_main_thread(L), 1).swap(wrap_access::ref(*p)); }
weak_ref& weak_ref::operator=(weak_ref const& other) { weak_ref(other).swap(*this); return *this; }