int
X11_SetClipboardText(_THIS, const char *text)
{
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
    Atom format;
    Window window;
    Atom XA_CLIPBOARD = XInternAtom(display, "CLIPBOARD", 0);

    /* Get the SDL window that will own the selection */
    window = GetWindow(_this);
    if (window == None) {
        return SDL_SetError("Couldn't find a window to own the selection");
    }

    /* Save the selection on the root window */
    format = TEXT_FORMAT;
    XChangeProperty(display, DefaultRootWindow(display),
        XA_CUT_BUFFER0, format, 8, PropModeReplace,
        (const unsigned char *)text, SDL_strlen(text));

    if (XA_CLIPBOARD != None &&
        XGetSelectionOwner(display, XA_CLIPBOARD) != window) {
        XSetSelectionOwner(display, XA_CLIPBOARD, window, CurrentTime);
    }

    if (XGetSelectionOwner(display, XA_PRIMARY) != window) {
        XSetSelectionOwner(display, XA_PRIMARY, window, CurrentTime);
    }
    return 0;
}
Exemple #2
0
/**
 * \brief Tries to determine the X window with a valid selection.
 *        Default is to check
 *         - passed parameter
 *         - CLIPBOARD
 *         - XA_PRIMARY
 *         - XA_SECONDARY
 *         - XA_CUT_BUFFER0 - 7
 *        
 *         in this order.
 * 
 * \param selection The Atom type, that should be tried before any of the
 *                  fixed XA_* buffers.
 * \return The Window handle, that owns the selection or None if none was
 *         found.
 */
static Window
_get_scrap_owner (Atom *selection)
{
    int i = 0;
    static Atom buffers[] = { XA_PRIMARY, XA_SECONDARY, XA_CUT_BUFFER0,
        XA_CUT_BUFFER1, XA_CUT_BUFFER2, XA_CUT_BUFFER3, XA_CUT_BUFFER4,
        XA_CUT_BUFFER5, XA_CUT_BUFFER6, XA_CUT_BUFFER7 };

    Window owner = XGetSelectionOwner (_sdldisplay, *selection);
    if (owner != None)
        return owner;

    owner = XGetSelectionOwner (_sdldisplay, _atom_CLIPBOARD);
    if (owner != None)
        return owner;

    while (i < 10)
    {
        owner = XGetSelectionOwner (_sdldisplay, buffers[i]);
        if (owner != None)
        {
            *selection = buffers[i];
            return owner;
        }
        i++;
    }
    
    return None;
}
bool
XWindowsClipboard::motifLockClipboard() const
{
	// fail if anybody owns the lock (even us, so this is non-recursive)
    Window lockOwner = XGetSelectionOwner(m_display, m_atomMotifClipLock);
	if (lockOwner != None) {
		LOG((CLOG_DEBUG1 "motif lock owner 0x%08x", lockOwner));
		return false;
	}

	// try to grab the lock
	// FIXME -- is this right?  there's a race condition here --
	// A grabs successfully, B grabs successfully, A thinks it
	// still has the grab until it gets a SelectionClear.
	Time time = XWindowsUtil::getCurrentTime(m_display, m_window);
	XSetSelectionOwner(m_display, m_atomMotifClipLock, m_window, time);
    lockOwner = XGetSelectionOwner(m_display, m_atomMotifClipLock);
	if (lockOwner != m_window) {
		LOG((CLOG_DEBUG1 "motif lock owner 0x%08x", lockOwner));
		return false;
	}

	LOG((CLOG_DEBUG1 "locked motif clipboard"));
	return true;
}
Exemple #4
0
MSStatus MSWidget::ownSelection(Atom selection_)
{
  if (selection_==XA_PRIMARY)
   {
     if (server()->primarySelectionOwner()!=this)
      {
        //We need to actively notify the current primary owner if it happens to be a widget
        //within the same application.  This is because the X Server does not send a
        //selectionClear if the current primary owner and the window that is trying
        //to acquire primary ownership are created by the same app.
        if (server()->primarySelectionOwner()!=0)
         {
           if ((unsigned long)(server()->widgetHashTable()->lookup(server()->primarySelectionOwner()->window()))!=
               server()->widgetHashTable()->notFound())
            {
              selectionClearNotify(server()->primarySelectionOwner(),0);
            }
         }
        server()->primarySelectionOwner(0);
        XSetSelectionOwner(display(),selection_,_window,CurrentTime);
        Window win=XGetSelectionOwner(display(),selection_);
        if (window()==win)
	  {
           server()->primarySelectionOwner(this);
#ifdef MS_WINDOWS
	   selectionRequest(0);
#endif
           return MSSuccess;
	  }
        else
	  {
#ifdef MS_WINDOWS
	    selectionRequest(0);
	    return MSSuccess;
#else
	    return MSFailure;
#endif
	  }
      }
     else
       {
#ifdef MS_WINDOWS
	 selectionRequest(0);
#endif
	 return MSSuccess;
       }
   }
  else
   {
     XSetSelectionOwner(display(),selection_,_window,CurrentTime);
     Window win=XGetSelectionOwner(display(),selection_);
     if (window()==win) return MSSuccess;
     else return MSFailure;
   }
}
Exemple #5
0
void UrlBar::becomeClipboardOwner()
{
    m_copiedText = m_url;

    XSetSelectionOwner(m_display, m_clipboardAtom, m_window, CurrentTime);
    if (XGetSelectionOwner(m_display, m_clipboardAtom) != m_window)
        fprintf(stderr, "Could not set clipboard ownership.\n");

    XSetSelectionOwner(m_display, XA_PRIMARY, m_window, CurrentTime);
    if (XGetSelectionOwner(m_display, XA_PRIMARY) != m_window)
        fprintf(stderr, "Could not set primary selection ownership.\n");
}
Exemple #6
0
char*
_xgetsnarf(void)
{
	uchar *data;
	Atom clipboard;
	XWindow w;

	qlock(&clip.lk);
	/*
	 * Have we snarfed recently and the X server hasn't caught up?
	 */
	if(_x.putsnarf != _x.assertsnarf)
		goto mine;

	/*
	 * Is there a primary selection (highlighted text in an xterm)?
	 */
	clipboard = XA_PRIMARY;
	w = XGetSelectionOwner(_x.display, XA_PRIMARY);
	if(w == _x.drawable){
	mine:
		data = (uchar*)strdup(clip.buf);
		goto out;
	}

	/*
	 * If not, is there a clipboard selection?
	 */
	if(w == None && _x.clipboard != None){
		clipboard = _x.clipboard;
		w = XGetSelectionOwner(_x.display, _x.clipboard);
		if(w == _x.drawable)
			goto mine;
	}

	/*
	 * If not, give up.
	 */
	if(w == None){
		data = nil;
		goto out;
	}
		
	if((data = _xgetsnarffrom(w, clipboard, _x.utf8string, 10, 100)) == nil)
	if((data = _xgetsnarffrom(w, clipboard, XA_STRING, 10, 100)) == nil){
		/* nothing left to do */
	}

out:
	qunlock(&clip.lk);
	return (char*)data;
}
String SystemClipboard::getTextFromClipboard()
{
    String content;
    ScopedXDisplay xDisplay;

    if (auto display = xDisplay.display)
    {
        ClipboardHelpers::initSelectionAtoms (display);

        /* 1) try to read from the "CLIPBOARD" selection first (the "high
           level" clipboard that is supposed to be filled by ctrl-C
           etc). When a clipboard manager is running, the content of this
           selection is preserved even when the original selection owner
           exits.

           2) and then try to read from "PRIMARY" selection (the "legacy" selection
           filled by good old x11 apps such as xterm)
        */
        Atom selection = XA_PRIMARY;
        Window selectionOwner = None;

        if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
        {
            selection = ClipboardHelpers::atom_CLIPBOARD;
            selectionOwner = XGetSelectionOwner (display, selection);
        }

        if (selectionOwner != None)
        {
            if (selectionOwner == juce_messageWindowHandle)
            {
                content = ClipboardHelpers::localClipboardContent;
            }
            else
            {
                // first try: we want an utf8 string
                bool ok = ClipboardHelpers::requestSelectionContent (display, content,
                                                                     selection, ClipboardHelpers::atom_UTF8_STRING);

                if (! ok)
                {
                    // second chance, ask for a good old locale-dependent string ..
                    ok = ClipboardHelpers::requestSelectionContent (display, content,
                                                                    selection, XA_STRING);
                }
            }
        }
    }

    return content;
}
bool
XWindowsClipboard::motifOwnsClipboard() const
{
	// get the current selection owner
	// FIXME -- this can't be right.  even if the window is destroyed
	// Motif will still have a valid clipboard.  how can we tell if
	// some other client owns CLIPBOARD?
	Window owner = XGetSelectionOwner(m_display, m_selection);
	if (owner == None) {
		return false;
	}

	// get the Motif clipboard header property from the root window
	Atom target;
	SInt32 format;
	String data;
	Window root = RootWindow(m_display, DefaultScreen(m_display));
	if (!XWindowsUtil::getWindowProperty(m_display, root,
								m_atomMotifClipHeader,
								&data, &target, &format, False)) {
		return false;
	}

	// check the owner window against the current clipboard owner
	const MotifClipHeader* header =
						reinterpret_cast<const MotifClipHeader*>(data.data());
	if (data.size() >= sizeof(MotifClipHeader) &&
		header->m_id == kMotifClipHeader) {
		if (static_cast<Window>(header->m_selectionOwner) == owner) {
			return true;
		}
	}

	return false;
}
Exemple #9
0
static void dndDrop(XClientMessageEvent *evt)
{
  dprintf((stderr, "dndDrop\n"));

  if (xdndSourceWindow != xdndDrop_sourceWindow(evt))
    dprintf((stderr, "dndDrop: wrong source window\n"));
  else if (xdndWillAccept)
    {
      Window owner;
      dprintf((stderr, "converting selection\n"));
      if (!(owner= XGetSelectionOwner(stDisplay, XdndSelection)))
	fprintf(stderr, "dndDrop: XGetSelectionOwner failed\n");
      else
	XConvertSelection(stDisplay, XdndSelection, XdndTextUriList, XdndSelectionAtom, stWindow, xdndDrop_time(evt));
      if (uxDropFileCount)
	{
	  int i;
	  assert(uxDropFileNames);
	  for (i= 0;  i < uxDropFileCount;  ++i)
	    free(uxDropFileNames[i]);
	  free(uxDropFileNames);
	  uxDropFileCount= 0;
	  uxDropFileNames= 0;
	}
    }
  else
    dprintf((stderr, "refusing selection -- finishing\n"));

  dndSendFinished(evt->window);
  dndLeave(evt);

  xdndState= XdndStateIdle;
}
bool
XWindowsClipboard::empty()
{
	assert(m_open);

	LOG((CLOG_DEBUG "empty clipboard %d", m_id));

	// assert ownership of clipboard
	XSetSelectionOwner(m_display, m_selection, m_window, m_time);
	if (XGetSelectionOwner(m_display, m_selection) != m_window) {
		LOG((CLOG_DEBUG "failed to grab clipboard %d", m_id));
		return false;
	}

	// clear all data.  since we own the data now, the cache is up
	// to date.
	clearCache();
	m_cached = true;

	// FIXME -- actually delete motif clipboard items?
	// FIXME -- do anything to motif clipboard properties?

	// save time
	m_timeOwned = m_time;
	m_timeLost  = 0;

	// we're the owner now
	m_owner = true;
	LOG((CLOG_DEBUG "grabbed clipboard %d", m_id));

	return true;
}
Exemple #11
0
static void setTrayIcon(QWidget &widget)
{
    /* System Tray Protocol Specification. */

    Display *dpy = qt_xdisplay();

    Screen *screen = XDefaultScreenOfDisplay(dpy);
    int iScreen = XScreenNumberOfScreen(screen);
    char szAtom[32];
    snprintf(szAtom, sizeof(szAtom), "_NET_SYSTEM_TRAY_S%d", iScreen);
    Atom selectionAtom = XInternAtom(dpy, szAtom, False);
    XGrabServer(dpy);
    Window managerWin = XGetSelectionOwner(dpy, selectionAtom);
    if (managerWin != None)
        XSelectInput(dpy, managerWin, StructureNotifyMask);
    XUngrabServer(dpy);
    XFlush(dpy);
    if (managerWin != None) {
        XEvent ev;
        memset(&ev, 0, sizeof(ev));
        ev.xclient.type = ClientMessage;
        ev.xclient.window = managerWin;
        ev.xclient.message_type = XInternAtom(dpy, "_NET_SYSTEM_TRAY_OPCODE", False);
        ev.xclient.format = 32;
        ev.xclient.data.l[0] = CurrentTime;
        ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
        ev.xclient.data.l[2] = widget.winId();
        ev.xclient.data.l[3] = 0;
        ev.xclient.data.l[4] = 0;
        XSendEvent(dpy, managerWin, False, NoEventMask, &ev);
        XSync(dpy, False);
    }
}
Exemple #12
0
int
main(int argc, char **argv)
{
	Display *dpy;
	Window window;
	GC gc;
	XEvent e;
	Atom atom;

	if (argc < 2) {
		fprintf(stderr, "usage: xgetselectionowner <selection_name>\n");
		exit(1);
	}

	dpy = XOpenDisplay(NULL);
	if (dpy == NULL)
		errx(1, "failed to open X display");

	atom = XInternAtom(dpy, argv[1], False);
	window = XGetSelectionOwner(dpy, atom);

	printf("window=%p\n", (void *) window);

	XCloseDisplay(dpy);

	return 0;
}
Exemple #13
0
void _glfwPlatformDestroyWindow(_GLFWwindow* window)
{
    if (window->monitor)
        leaveFullscreenMode(window);

    _glfwDestroyContext(window);

    if (window->x11.handle)
    {
        if (window->x11.handle ==
            XGetSelectionOwner(_glfw.x11.display, _glfw.x11.CLIPBOARD))
        {
            _glfwPushSelectionToManager(window);
        }

        XDeleteContext(_glfw.x11.display, window->x11.handle, _glfw.x11.context);
        XUnmapWindow(_glfw.x11.display, window->x11.handle);
        XDestroyWindow(_glfw.x11.display, window->x11.handle);
        window->x11.handle = (Window) 0;
    }

    if (window->x11.colormap)
    {
        XFreeColormap(_glfw.x11.display, window->x11.colormap);
        window->x11.colormap = (Colormap) 0;
    }
}
Exemple #14
0
int
TrayFindDock(Display *dpy, TrayWindow* tray)
{
    if (tray->window == None) {
        tray->bTrayMapped = False;
        return 0;
    }

    XGrabServer(dpy);

    tray->dockWindow = XGetSelectionOwner(dpy, tray->atoms[ATOM_SELECTION]);

    if (tray->dockWindow != None)
        XSelectInput(dpy, tray->dockWindow,
                     StructureNotifyMask | PropertyChangeMask);

    XUngrabServer(dpy);
    XFlush(dpy);

    if (tray->dockWindow != None) {
        TraySendOpcode(dpy, tray->dockWindow, tray, SYSTEM_TRAY_REQUEST_DOCK, tray->window, 0, 0);
        tray->bTrayMapped = True;
        return 1;
    } else {
        tray->bTrayMapped = False;
        ReleaseTrayWindow(tray);
    }

    return 0;
}
Exemple #15
0
Window find_hime_window(Display *dpy)
{
  Atom hime_addr_atom = get_hime_addr_atom(dpy);
  if (!hime_addr_atom)
    return FALSE;
  return XGetSelectionOwner(dpy, hime_addr_atom);
}
Exemple #16
0
// Checks that there is a clipboard manager running
// and that it supports clipboard persistance
bool MCScreenDC::check_clipboard_manager(void)
{
 Atom clipboard_manager;

  clipboard_manager = make_atom ("CLIPBOARD_MANAGER");
  return XGetSelectionOwner (dpy, clipboard_manager) != None;	
}
Exemple #17
0
static void
egg_tray_manager_unmanage (EggTrayManager *manager)
{
#ifdef GDK_WINDOWING_X11
  Display *display;
  guint32 timestamp;
  GtkWidget *invisible;

  if (manager->invisible == NULL)
    return;

  invisible = manager->invisible;
  g_assert (GTK_IS_INVISIBLE (invisible));
  g_assert (GTK_WIDGET_REALIZED (invisible));
  g_assert (GDK_IS_WINDOW (invisible->window));
  
  display = GDK_WINDOW_XDISPLAY (invisible->window);
  
  if (XGetSelectionOwner (display, manager->selection_atom) ==
      GDK_WINDOW_XWINDOW (invisible->window))
    {
      timestamp = gdk_x11_get_server_time (invisible->window);      
      XSetSelectionOwner (display, manager->selection_atom, None, timestamp);
    }

  gdk_window_remove_filter (invisible->window, egg_tray_manager_window_filter, manager);  

  manager->invisible = NULL; /* prior to destroy for reentrancy paranoia */
  gtk_widget_destroy (invisible);
  g_object_unref (G_OBJECT (invisible));
#endif
}
static gboolean
drw_selection_find_existing (DrwSelection *drw_selection)
{
	Display *xdisplay = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
	Window old;

	gdk_error_trap_push ();
	old = XGetSelectionOwner (xdisplay,
				  gdk_x11_get_xatom_by_name (SELECTION_NAME));
	if (old) {
		XSelectInput (xdisplay, old, StructureNotifyMask);
		drw_selection->owner_window = gdk_x11_window_foreign_new_for_display (gdk_display_get_default (), old);
	}
	XSync (xdisplay, False);

	if (gdk_error_trap_pop () == 0 && drw_selection->owner_window) {
		gdk_window_add_filter (drw_selection->owner_window,
				       drw_selection_filter, drw_selection);

		XUngrabServer (xdisplay);

		return TRUE;
	} else {
		if (drw_selection->owner_window) {
			g_object_unref (drw_selection->owner_window);
			drw_selection->owner_window = NULL;
		}

		return FALSE;
	}
}
Exemple #19
0
int main(int argc, char **argv) {
    char remote[BUF_SIZE];
    Display *display;
    Atom atom;
    Window win;

    if (argc != 2) {
        usage(argv[0]);
        return OTHER_ERROR;
    }

    if (!strcmp("--help", argv[1])) {
        usage(argv[0]);
        return 0;
    }

    sprintf(remote, "xpdf_%s", argv[1]);

    display = XOpenDisplay(NULL);
    if (!display) return OTHER_ERROR;
    atom = XInternAtom(display, remote, False);
    if (atom == None) return OTHER_ERROR;
    win = XGetSelectionOwner(display, atom);

    return (win == None) ? NOT_RUNNING : RUNNING;
}
Exemple #20
0
static boolean xf_cliprdr_is_self_owned(xfInfo* xfi)
{
	Atom type;
	uint32 id = 0;
	uint32* pid = NULL;
	int format, result = 0;
	unsigned long len, bytes_left;
	clipboardContext* cb = (clipboardContext*) xfi->clipboard_context;

	cb->owner = XGetSelectionOwner(xfi->display, cb->clipboard_atom);
	if (cb->owner != None)
	{
		result = XGetWindowProperty(xfi->display, cb->owner,
			cb->identity_atom, 0, 4, 0, XA_INTEGER,
			&type, &format, &len, &bytes_left, (unsigned char**) &pid);
	}
	if (pid)
	{
		id = *pid;
		XFree(pid);
	}
	if (cb->owner == None || cb->owner == xfi->window->handle)
	{
		return False;
	}
	if (result != Success)
	{
		return False;
	}
	return (id ? True : False);
}
Exemple #21
0
bool widgetSetClipboardText(const char *text)
{
	Window selectionOwner;

	// Make sure we are initialised
	widgetInitialiseClipboardX11();

	// Lock the connection
	info.info.x11.lock_func();

	// Copy the text into the root windows cut buffer (for Xterm compatibility)
	XStoreBytes(info.info.x11.display, text, strlen(text) + 1);

	// Set ourself as the owner of the CLIPBOARD atom
	XSetSelectionOwner(info.info.x11.display, XA_CLIPBOARD,
	                   info.info.x11.window, CurrentTime);

	// Check if we acquired ownership or not
	selectionOwner = XGetSelectionOwner(info.info.x11.display, XA_CLIPBOARD);

	// We got ownership
	if (selectionOwner == info.info.x11.window)
	{
		info.info.x11.unlock_func();
		return true;
	}
	// We did not get ownership
	else
	{
		info.info.x11.unlock_func();
		return false;
	}
}
Exemple #22
0
static BOOL xf_cliprdr_is_raw_transfer_available(xfClipboard* clipboard)
{
	Atom type;
	int format;
	int result = 0;
	unsigned long length;
	unsigned long bytes_left;
	UINT32* data = NULL;
	UINT32 is_enabled = 0;
	Window owner = None;
	xfContext* xfc = clipboard->xfc;
	owner = XGetSelectionOwner(xfc->display, clipboard->clipboard_atom);

	if (owner != None)
	{
		result = XGetWindowProperty(xfc->display, owner,
		                            clipboard->raw_transfer_atom, 0, 4, 0, XA_INTEGER,
		                            &type, &format, &length, &bytes_left, (BYTE**) &data);
	}

	if (data)
	{
		is_enabled = *data;
		XFree(data);
	}

	if ((owner == None) || (owner == xfc->drawable))
		return FALSE;

	if (result != Success)
		return FALSE;

	return is_enabled ? TRUE : FALSE;
}
Exemple #23
0
static BOOL xf_cliprdr_is_self_owned(xfInfo* xfi)
{
	Atom type;
	UINT32 id = 0;
	UINT32* pid = NULL;
	int format, result = 0;
	unsigned long length, bytes_left;
	clipboardContext* cb = (clipboardContext*) xfi->clipboard_context;

	cb->owner = XGetSelectionOwner(xfi->display, cb->clipboard_atom);

	if (cb->owner != None)
	{
		result = XGetWindowProperty(xfi->display, cb->owner,
			cb->identity_atom, 0, 4, 0, XA_INTEGER,
			&type, &format, &length, &bytes_left, (BYTE**) &pid);
	}

	if (pid)
	{
		id = *pid;
		XFree(pid);
	}

	if ((cb->owner == None) || (cb->owner == xfi->drawable))
		return FALSE;

	if (result != Success)
		return FALSE;

	return (id ? TRUE : FALSE);
}
Exemple #24
0
static void tray_widget_update_manager_window(struct _tray_widget_icon *widget_icon, gboolean dock_if_realized)
{
	if (widget_icon->manager_window != None)
		return;

	Display *display = GDK_DISPLAY_XDISPLAY(gtk_widget_get_display(GTK_WIDGET(widget_icon)));

	XGrabServer(display);
  
	widget_icon->manager_window = XGetSelectionOwner(display, widget_icon->selection_atom);

	if (widget_icon->manager_window != None)
		XSelectInput(display, widget_icon->manager_window, StructureNotifyMask | PropertyChangeMask);

	XUngrabServer(display);
	XFlush(display);
  
	if (widget_icon->manager_window == None)
		return;

	GdkWindow *gdk_window = gdk_window_lookup_for_display(gtk_widget_get_display(GTK_WIDGET(widget_icon)), widget_icon->manager_window);

	gdk_window_add_filter(gdk_window, tray_widget_filter, widget_icon);

	if (dock_if_realized && GTK_WIDGET_REALIZED(widget_icon))
		tray_widget_send_dock_request(widget_icon);

	tray_widget_get_orientation_property(widget_icon);
}
void ClipboardPoll::updateQtOwnership( SelectionData& data )
{
    Atom type;
    int format;
    unsigned long nitems;
    unsigned long after;
    unsigned char* prop = NULL;
    if( XGetWindowProperty( QX11Info::display(), QX11Info::appRootWindow( 0 ), data.sentinel_atom, 0, 2, False,
        XA_WINDOW, &type, &format, &nitems, &after, &prop ) != Success
        || type != XA_WINDOW || format != 32 || nitems != 2 || prop == NULL )
    {
#ifdef REALLY_NOISY_KLIPPER_
        kDebug() << "UPDATEQT BAD PROPERTY";
#endif
        data.owner_is_qt = false;
        if( prop != NULL )
            XFree( prop );
        return;
    }
    Window owner = reinterpret_cast< long* >( prop )[ 0 ]; // [0] is new owner, [1] is previous
    XFree( prop );
    Window current_owner = XGetSelectionOwner( QX11Info::display(), data.atom );
    data.owner_is_qt = ( owner == current_owner );
#ifdef REALLY_NOISY_KLIPPER_
    kDebug() << "owner=" << owner << "; current_owner=" << current_owner;
    kDebug() << "UPDATEQT:" << ( &data == &selection ? "selection" : "clipboard" )  << ":" << data.owner_is_qt;
#endif
}
Exemple #26
0
void selection_clear(XSelectionClearEvent ev)
{
	/* Is it _NET_SYSTEM_TRAY selection? */
	if (ev.selection == tray_data.xa_tray_selection) {
		/* Is it us who has lost the selection */
		if (ev.window == tray_data.tray) {
			LOG_INFO(("another tray detected; deactivating\n"));
			tray_data.is_active = False;
			tray_data.old_selection_owner = XGetSelectionOwner(tray_data.dpy, tray_data.xa_tray_selection);
			if (!x11_ok()) {
				LOG_INFO(("could not find proper new tray; reactivating\n"));
				tray_acquire_selection();
			};
			LOG_TRACE(("new selection owner is 0x%x\n", tray_data.old_selection_owner));
			XSelectInput(tray_data.dpy, tray_data.old_selection_owner, StructureNotifyMask);
			return;
		} else if (!tray_data.is_active) {
			/* Someone else has lost selection and tray is not active --- take over the selection */
			LOG_INFO(("another tray exited; reactivating\n"));
			tray_acquire_selection();
		} else {
			/* Just in case */
			LOG_TRACE(("WEIRD: tray is active and someone else has lost tray selection\n"));
		}
	}
}
Exemple #27
0
static bool register_cm(Display* dpy)
{
	Window w;
	Atom a;
	a = XInternAtom (dpy, "_NET_WM_CM_S0", False);
	w = XGetSelectionOwner (dpy, a);
	if (w != None)
	{
		XTextProperty tp;
		char **strs;
		int count;
		Atom winNameAtom = XInternAtom (dpy, "_NET_WM_NAME", False);
		if (!XGetTextProperty (dpy, w, &tp, winNameAtom) && !XGetTextProperty (dpy, w, &tp, XA_WM_NAME))
		{
			fprintf (stderr, "Another composite manager is already running (0x%lx)\n", (unsigned long) w);
			return false;
		}
		if (XmbTextPropertyToTextList (dpy, &tp, &strs, &count) == Success)
		{
			fprintf (stderr, "Another composite manager is already running (%s)\n", strs[0]);
			XFreeStringList (strs);
		}
		XFree (tp.value);
		return false;
	}
	w = XCreateSimpleWindow (dpy, RootWindow (dpy, 0), 0, 0, 1, 1, 0, None, None);
	Xutf8SetWMProperties (dpy, w, "xcompmgr", "xcompmgr", NULL, 0, NULL, NULL, NULL);
	XSetSelectionOwner (dpy, a, w, 0);
	return true;
}
Exemple #28
0
LogoutEffect::LogoutEffect()
    : progress(0.0)
    , displayEffect(false)
    , logoutWindow(NULL)
    , logoutWindowClosed(true)
    , logoutWindowPassed(false)
    , canDoPersistent(false)
    , ignoredWindows()
    , m_vignettingShader(NULL)
    , m_blurShader(NULL)
{
    // Persistent effect
    logoutAtom = XInternAtom(display(), "_KDE_LOGGING_OUT", False);
    effects->registerPropertyType(logoutAtom, true);

    // Block KSMServer's effect
    char net_wm_cm_name[ 100 ];
    sprintf(net_wm_cm_name, "_NET_WM_CM_S%d", DefaultScreen(display()));
    Atom net_wm_cm = XInternAtom(display(), net_wm_cm_name, False);
    Window sel = XGetSelectionOwner(display(), net_wm_cm);
    Atom hack = XInternAtom(display(), "_KWIN_LOGOUT_EFFECT", False);
    XChangeProperty(display(), sel, hack, hack, 8, PropModeReplace, (unsigned char*)&hack, 1);
    // the atom is not removed when effect is destroyed, this is temporary anyway

    blurTexture = NULL;
    blurTarget = NULL;
    reconfigure(ReconfigureAll);
    connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), this, SLOT(slotWindowAdded(KWin::EffectWindow*)));
    connect(effects, SIGNAL(windowClosed(KWin::EffectWindow*)), this, SLOT(slotWindowClosed(KWin::EffectWindow*)));
    connect(effects, SIGNAL(windowDeleted(KWin::EffectWindow*)), this, SLOT(slotWindowDeleted(KWin::EffectWindow*)));
    connect(effects, SIGNAL(propertyNotify(KWin::EffectWindow*,long)), this, SLOT(slotPropertyNotify(KWin::EffectWindow*,long)));
}
Exemple #29
0
/*
 * detect_get_clipboard - try and get the CLIPBOARD_NAME clipboard
 *
 * Returns TRUE if successfully retrieved and FALSE otherwise.
 */
gboolean detect_get_clipboard()
{
    static const GtkTargetEntry targets[] = { {CLIPBOARD_NAME, 0, 0} };
    gboolean retval = FALSE;
    GtkClipboard *clipboard;
    Atom atom;

    atom = gdk_x11_get_xatom_by_name(CLIPBOARD_NAME);

    XGrabServer(GDK_DISPLAY());

    if (XGetSelectionOwner(GDK_DISPLAY(), atom) != None)
        goto out;

    clipboard = gtk_clipboard_get(gdk_atom_intern(CLIPBOARD_NAME, FALSE));

    if (gtk_clipboard_set_with_data(
                clipboard, targets,
                G_N_ELEMENTS (targets),
                clipboard_get_func,
                clipboard_clear_func, NULL))
        retval = TRUE;

out:
    XUngrabServer (GDK_DISPLAY ());
    gdk_flush ();

    return retval;
}
Exemple #30
0
std::string X11Window::getClipboardText()
{
    Atom clipboard = XInternAtom(m_display, "CLIPBOARD", False);
    Window ownerWindow = XGetSelectionOwner(m_display, clipboard);
    if(ownerWindow == m_window)
        return m_clipboardText;

    std::string clipboardText;
    if(ownerWindow != None) {
        XConvertSelection(m_display, clipboard, XA_STRING, XA_PRIMARY, ownerWindow, CurrentTime);
        XFlush(m_display);

        // hack to wait SelectioNotify event, otherwise we will get wrong clipboard pastes
        // TODO: fix this in a correct way
        stdext::millisleep(100);

        // check for data
        Atom type;
        int format;
        ulong len, bytesLeft;
        uchar *data;
        XGetWindowProperty(m_display, ownerWindow,
                            XA_PRIMARY, 0, 10000000L, 0, XA_STRING,
                            &type,
                            &format,
                            &len,
                            &bytesLeft,
                            &data);
        if(len > 0) {
            clipboardText = stdext::utf8_to_latin1(data);
        }
    }

    return clipboardText;
}