Пример #1
1
static void
cliprdr_get_clipboard(XEvent* e)
{
	Atom type;
	unsigned long len, bytes_left, dummy;
	int format, result;
	unsigned char *data;


	log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[cliprdr_get_clipboard]: "
			"New owner %i", e->xselection.requestor);

	XGetWindowProperty (e->xselection.display,
											e->xselection.requestor,
											e->xselection.property,
											0, 0,
											False,
											AnyPropertyType,
											&type,
											&format,
											&len, &bytes_left,
											&data);
	// Check Format list
	if (type == XA_ATOM || format == 32)
	{
		result = XGetWindowProperty (e->xselection.display, e->xselection.requestor, e->xselection.property, 0, bytes_left, 0, XA_ATOM, &type, &format, &len, &dummy, &data);
		if (result == Success)
		{
			int i = 0;
			Atom atom;
			for (i = 0; i < len ; i++)
			{
				atom = ((Atom*)data)[i];
				log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[cliprdr_get_clipboard]: "
						"format : %s", XGetAtomName(display, atom));
				if (clipboard_format_supported(&clipboard, atom))
				{
					clipboard_add_current_clipboard_format(&clipboard, atom);
				}
			}
			if (clipboard_current_clipboard_size(&clipboard) > 0)
			{
				atom = clipboard_get_current_clipboard_format(&clipboard, 0);
				log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[cliprdr_get_clipboard]: "
						"Request for format %s", XGetAtomName(display, atom));

				XConvertSelection(display, clipboard_atom, atom, xrdp_clipboard, wclip, CurrentTime);
				XSync (e->xselectionclear.display, False);
			}
			return;
		}

		log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[cliprdr_get_clipboard]: "
				"Failed to parse atom list");
		return;
	}

	// DATA is There
	log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[cliprdr_get_clipboard]: "
			"Data type : %s\n", XGetAtomName(e->xselection.display, e->xselection.property));

	if (bytes_left > 0 && clipboard_format_supported(&clipboard, e->xselection.target))
	{
		unsigned char* clipboard_data = NULL;
		int clipboard_size = 0;

		result = XGetWindowProperty(e->xselection.display, e->xselection.requestor, e->xselection.property, 0, bytes_left, 0, e->xselection.target, &type, &format, &len, &dummy, &data);
		if (result == Success)
		{
			log_message(l_config, LOG_LEVEL_DEBUG_PLUS, "vchannel_cliprdr[cliprdr_get_clipboard]: "
					"New data in clipboard: %s", data);
			int index = -1;
			index = clipboard_get_current_clipboard_format_index(&clipboard, e->xselection.target);

			// Don't forget the null terminated character
			clipboard_data = g_malloc(bytes_left + 1, 1);
			clipboard_size = bytes_left;
			g_memcpy(clipboard_data, data, bytes_left);
			log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[cliprdr_get_clipboard]: "
					"clipboard %s[%i] updated with '%s'", XGetAtomName(display, e->xselection.target), index, data);

			clipboard_add_current_clipboard_data(&clipboard, clipboard_data, clipboard_size, e->xselection.target);

			if (index < (clipboard_current_clipboard_size(&clipboard) - 1))
			{
				Atom format = clipboard_get_current_clipboard_format(&clipboard, index + 1);
				log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[cliprdr_get_clipboard]: "
						"Request for format %s", XGetAtomName(display, format));

				XConvertSelection(display, clipboard_atom, format, xrdp_clipboard, wclip, CurrentTime);
				XSync (e->xselectionclear.display, False);
			}
			else
			{
				XSetSelectionOwner(display, clipboard_atom, wclip, CurrentTime);
				XSync(display, False);
				// File content is not supported for now
				if ((! clipboard_current_clipboard_format_exist(&clipboard, format_file_gnome_atom)) && (! clipboard_current_clipboard_format_exist(&clipboard, format_file_text_uri_list_atom)))
					cliprdr_send_format_list();
			}
		}
		else
		{
			log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[cliprdr_get_clipboard]: "
					"Failed to get clipboard content");
		}
		XFree (data);
	}
}
int
main (int argc, char **argv)
{
        GdkDisplay *display = NULL;
        int estatus;
        char *child_argv[] = { LIBEXECDIR "/gnome-session-check-accelerated-helper", NULL };
        Window rootwin;
        glong is_accelerated;
        GError *error = NULL;

        gtk_init (NULL, NULL);

        display = gdk_display_get_default ();
        rootwin = gdk_x11_get_default_root_xwindow ();

        is_accelerated_atom = gdk_x11_get_xatom_by_name_for_display (display, "_GNOME_SESSION_ACCELERATED");

        {
                Atom type;
                gint format;
                gulong nitems;
                gulong bytes_after;
                guchar *data;

 read:
                gdk_x11_display_error_trap_push (display);
                XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), rootwin,
                                    is_accelerated_atom,
                                    0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems,
                                    &bytes_after, &data);
                gdk_x11_display_error_trap_pop_ignored (display);

                if (type == XA_CARDINAL) {
                        glong *is_accelerated_ptr = (glong*) data;

                        if (*is_accelerated_ptr == ACCEL_CHECK_RUNNING) {
                                /* Test in progress, wait */
                                if (wait_for_property_notify ())
                                        goto read;
                                /* else fall through and do the check ourselves */

                        } else {
                                return (*is_accelerated_ptr == 0 ? 1 : 0);
                        }
                }
        }

        /* We don't have the property or it's the wrong type.
         * Try to compute it now.
         */

        /* First indicate that a test is in progress */
        is_accelerated = ACCEL_CHECK_RUNNING;
        XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
                         rootwin,
                         is_accelerated_atom,
                         XA_CARDINAL, 32, PropModeReplace, (guchar *) &is_accelerated, 1);

        gdk_display_sync (display);

        estatus = 1;
        if (!g_spawn_sync (NULL, (char**)child_argv, NULL, 0,
                           NULL, NULL, NULL, NULL, &estatus, &error)) {
                is_accelerated = FALSE;
                g_printerr ("gnome-session-check-accelerated: Failed to run helper: %s\n", error->message);
                g_clear_error (&error);
        } else {
                is_accelerated = (estatus == 0);
                if (!is_accelerated)
                        g_printerr ("gnome-session-check-accelerated: Helper exited with code %d\n", estatus);
        }

        if (is_accelerated) {
            XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
                             rootwin,
                             is_accelerated_atom,
                             XA_CARDINAL, 32, PropModeReplace, (guchar *) &is_accelerated, 1);
        }

        gdk_display_sync (display);

        return is_accelerated ? 0 : 1;
}
Пример #3
0
struct SceneIO *
request_composer_scene(void)
{
  char *filename;
  time_t time_1, time_2;
  unsigned long nitems, left;
  int format, *ready, ready2;
  Atom type;
  
  if (TheDisplay == NULL) {
    TheDisplay = XOpenDisplay(NULL);
    GET_COMPOSER_DATA = XInternAtom(TheDisplay,
				    "Get Composer Data", FALSE);
    NAME_OF_COMPOSER_FILE = XInternAtom(TheDisplay,
					"Name of Composer File", FALSE);
    COMPOSER_DATA_READY = XInternAtom(TheDisplay,
				      "Composer Data Ready", FALSE);
  }

  /* Reset the shared flag that indicates progress */
  
  ready2 = COMPOSER_EXPORT_REQUESTED;
  ready = &ready2;
  XChangeProperty(TheDisplay,
		  DefaultRootWindow(TheDisplay),
		  COMPOSER_DATA_READY, XA_INTEGER, 32,
		  PropModeReplace,
		  (unsigned const char *)ready, 1);

  /* Ask for the data to be sent */
  
  ready2 = TRUE;
  XChangeProperty(TheDisplay,
		  DefaultRootWindow(TheDisplay),
		  GET_COMPOSER_DATA, XA_INTEGER, 32,
		  PropModeReplace,
		  (unsigned const char *)ready, 1);
  

  time(&time_1);
  while (*ready != COMPOSER_EXPORT_DONE) {
    if (XGetWindowProperty(TheDisplay,
			   DefaultRootWindow(TheDisplay),
			   COMPOSER_DATA_READY, 0, sizeof(int),
			   FALSE, XA_INTEGER, &type, &format,
			   &nitems, &left, (unsigned char **)(&ready))
	!= Success) {
      return NULL;
    }

    /* Use two timeouts: a short timeout until we get a response
     * (so we know that composer is running), and a longer timeout to save
     * the scene (don''t want an infinite timeout in case composer crashed).
     */
    time(&time_2);
    /* printf( "time = %d, ready = %d\n", time_2 - time_1, *ready ); */
    if (((long)time_2 - (long)time_1) > (*ready == COMPOSER_EXPORT_SENDING
				    ? TIME_OUT_DONE : TIME_OUT_SEND ))
    {
      printf ("\nUnable to find 'composer'.  Reading from file: ./%s\n",
	      COMPOSER_DEFAULT_EXPORT_NAME);
      return read_scene(COMPOSER_DEFAULT_EXPORT_NAME);
    }
  }

  /* Get the filename that the scene was saved in */
  
  XGetWindowProperty(TheDisplay,
		     DefaultRootWindow(TheDisplay),
		     NAME_OF_COMPOSER_FILE, 0, PATH_MAX,
		     FALSE, XA_STRING, &type, &format,
		     &nitems, &left, (unsigned char **)(&filename));

  return read_scene(filename);
}
Пример #4
0
static void
handle_event(XEvent * event)
{
    XWindowAttributes wa;
/*    fprintf(stderr,"event:handle_event entered\n");*/
    set_window(event->xany.window);
    if (event->type == MotionNotify) {
/*        fprintf(stderr,"event:handle_event type=MotionNotify\n");*/
        handle_motion_event((XMotionEvent *)event);
        motion = 1;
        return;
    }
    make_busy_cursors();
    switch (event->type) {
      case DestroyNotify:
/*        fprintf(stderr,"event:handle_event type=DestroyNotify\n");*/
        break;
      case Expose:
/*        fprintf(stderr,"event:handle_event type=Expose\n");*/
        XGetWindowAttributes(gXDisplay, gWindow->fMainWindow, &wa);
        if ((gWindow->width == 0 && gWindow->height == 0) ||
            (wa.width != gWindow->width || wa.height != gWindow->height)) {
            gWindow->width = wa.width;
            gWindow->height = wa.height;
            display_page(gWindow->page);
            gWindow->fWindowHashTable = gWindow->page->fLinkHashTable;
        }
        else                    /** just redraw the thing **/
            expose_page(gWindow->page);
        XFlush(gXDisplay);
        clear_exposures(gWindow->fMainWindow);
        clear_exposures(gWindow->fScrollWindow);
        break;
      case ButtonPress:
/*        fprintf(stderr,"event:handle_event type=ButtonPress\n");*/
        handle_button(event->xbutton.button, (XButtonEvent *)event);
        XFlush(gXDisplay);
        if (gWindow) {
            while (XCheckTypedWindowEvent(gXDisplay, gWindow->fMainWindow,
                                          Expose, event));
            while (XCheckTypedWindowEvent(gXDisplay, gWindow->fScrollWindow,
                                          Expose, event));
        }
        break;
      case KeyPress:
/*        fprintf(stderr,"event:handle_event type=KeyPress\n");*/
        handle_key(event);
        if (gWindow) {
            while (XCheckTypedWindowEvent(gXDisplay, gWindow->fMainWindow,
                                          Expose, event));
            while (XCheckTypedWindowEvent(gXDisplay, gWindow->fScrollWindow,
                                          Expose, event));
        }
        break;
      case MapNotify:
/*        fprintf(stderr,"event:handle_event type=MapNotify\n");*/
        create_window();
        break;

      case SelectionNotify:
/*        fprintf(stderr,"event:handle_event type=SelectionNotify\n");*/
        /* this is in response to a previous request in an input area */
        if ( gSavedInputAreaLink ) {
            XSelectionEvent *pSelEvent;
            Atom dataProperty;
            pSelEvent = (XSelectionEvent *) event;
            dataProperty = XInternAtom(gXDisplay, "PASTE_SELECTION", False);
            /* change the input focus */

        /*  change_input_focus(gSavedInputAreaLink); */

            /* try to get the selection as a window property */

            if ( pSelEvent->requestor == gWindow->fMainWindow &&
                 pSelEvent->selection == XA_PRIMARY &&
            /*   pSelEvent->time      == CurrentTime && */
                 pSelEvent->target    == XA_STRING &&
                 pSelEvent->property == dataProperty )
            {
                Atom actual_type;
                int  actual_format;
                unsigned long nitems, leftover;
                char *pSelection = NULL;

                if (Success == XGetWindowProperty(gXDisplay,
                    gWindow->fMainWindow,
                    pSelEvent->property, 0L, 100000000L, True,
                    AnyPropertyType, &actual_type, &actual_format,
                    &nitems, &leftover, (unsigned char **) &pSelection) )
                {
                    char *pBuffer;
                    InputItem *item = gSavedInputAreaLink->reference.string;

                    for (pBuffer = pSelection; *pBuffer; ++pBuffer)
                        add_buffer_to_sym(pBuffer, item);

                    XFree(pSelection);
                }
            }

            /* clear the link info */

            gSavedInputAreaLink = NULL;
        }
        break;

      default:
/*        fprintf(stderr,"event:handle_event type=default\n");*/
        break;
    }

}
Пример #5
0
PUBLIC void
get_scrap(int type, int *dstlen, char **dst)
{
  scrap_type format;

  *dstlen = -1;
  format = convert_format(type);

#if defined(X11_SCRAP)
/* * */
  {
    Window owner;
    Atom selection;
    Atom seln_type;
    int seln_format;
    unsigned long nbytes;
    unsigned long overflow;
    char *src;

    owner = XGetSelectionOwner(SDL_Display, XA_PRIMARY);
    if ( (owner == None) || (owner == SDL_Window) )
      {
        owner = DefaultRootWindow(SDL_Display);
        selection = XA_CUT_BUFFER0;
      }
    else
      {
        int selection_response = 0;
        SDL_Event event;

        owner = SDL_Window;
        selection = XInternAtom(SDL_Display, "SDL_SELECTION", False);
        XConvertSelection(SDL_Display, XA_PRIMARY, format,
                                        selection, owner, CurrentTime);
        while ( ! selection_response )
          {
            SDL_WaitEvent(&event);
            if ( event.type == SDL_SYSWMEVENT )
              {
#if SDL_MAJOR_VERSION == 0 && SDL_MINOR_VERSION < 9
                XEvent xevent = event.syswm.msg->xevent;
#else
                XEvent xevent = event.syswm.msg->event.xevent;
#endif
                if ( (xevent.type == SelectionNotify) &&
                     (xevent.xselection.requestor == owner) )
                    selection_response = 1;
              }
            else
              {
                /* FIXME: dropped event? */;
              }
          }
      }
    if ( XGetWindowProperty(SDL_Display, owner, selection, 0, INT_MAX/4,
                            False, format, &seln_type, &seln_format,
                       &nbytes, &overflow, (unsigned char **)&src) == Success )
      {
        if ( seln_type == format )
          {
            char *mem;
            *dstlen = convert_scrap(type, NULL, src, nbytes);
            mem = sdl_ReallocHandle(dst, *dstlen);
            if ( mem == NULL )
              *dstlen = -1;
            else
              convert_scrap(type, mem, src, nbytes);
          }
        XFree(src);
      }
    }

#elif defined(WIN_SCRAP)
/* * */
  if ( IsClipboardFormatAvailable(format) && OpenClipboard(SDL_Window) )
    {
      HANDLE hMem;
      char *src;

      hMem = GetClipboardData(format);
      if ( hMem != NULL )
        {
          char *mem;
          src = (char *)GlobalLock(hMem);
          *dstlen = convert_scrap(type, NULL, src, 0);
          mem = sdl_ReallocHandle(dst, *dstlen);
          if ( mem == NULL )
            *dstlen = -1;
          else
            convert_scrap(type, mem, src, 0);
          GlobalUnlock(hMem);
        }
      CloseClipboard();
    }

#endif /* scrap type */
}
Пример #6
0
void GrabWindow(Window target)
{
  char *temp;
  Window Junk,root;
  unsigned int tw,th,border_width,depth;
  int x,y;
  char *prop = NULL;
  Atom actual = None;
  int actual_format;
  unsigned long nitems, bytesafter;
     
  XUnmapWindow(dpy,target);
  XSync(dpy,0);
  XGetGeometry(dpy,target,&root,&x,&y,
	       (unsigned int *)&tw,(unsigned int *)&th,
	       (unsigned int *)&border_width,
	       (unsigned int *)&depth);
  XSync(dpy,0);

  XTranslateCoordinates(dpy, target, Root, 0, 0, &x,&y, &Junk);

  CreateWindow(x,y,tw,th);
  XSetWindowBorderWidth(dpy,target,0);
  XReparentWindow(dpy,target, holder_win,0,0);
  XMapWindow(dpy,target);
  XSelectInput(dpy,target, PropertyChangeMask|StructureNotifyMask|
	       ColormapChangeMask);
  if(XFetchName(dpy, target, &temp)==0)
    temp = NULL;
  if (XGetWindowProperty (dpy,
			  target, XA_WM_ICON_NAME, 0,
			  MAX_ICON_NAME_LEN, False, XA_STRING, 
			  &actual,&actual_format, &nitems, 
			  &bytesafter, (unsigned char **) &prop)
      == Success && (prop != NULL))
    {
      change_icon_name(prop);
      XFree(prop);
    }
  change_window_name(temp);
  {
    XWMHints *wmhints;
    
    wmhints = XGetWMHints(dpy,target);
    if(wmhints != NULL)
      {
	XSetWMHints(dpy,main_win, wmhints);
	XFree(wmhints);
      }
  }
  {
    XWindowAttributes xwa;
    if(XGetWindowAttributes(dpy,target, &xwa) != 0)
      {
	XSetWindowColormap(dpy,main_win,xwa.colormap);
      }
  }
    
  XMapWindow(dpy,main_win);
  RedrawWindow(target);
  XFree(temp);
}
Пример #7
0
DockWnd::DockWnd(QWidget *main)
        : QWidget(NULL)
{
#ifndef WIN32
    wharfIcon = NULL;
#endif
    connect(this, SIGNAL(toggleWin()), main, SLOT(toggleShow()));
    connect(this, SIGNAL(showPopup(QPoint)), main, SLOT(showPopup(QPoint)));
    connect(pClient, SIGNAL(event(ICQEvent*)), this, SLOT(processEvent(ICQEvent*)));
    connect(pClient, SIGNAL(messageRead(ICQMessage*)), this, SLOT(messageRead(ICQMessage*)));
    connect(pClient, SIGNAL(messageReceived(ICQMessage*)), this, SLOT(messageReceived(ICQMessage*)));
    connect(pMain, SIGNAL(iconChanged()), this, SLOT(reset()));
    m_state = 0;
    showIcon = State;
    QTimer *t = new QTimer(this);
    connect(t, SIGNAL(timeout()), this, SLOT(timer()));
    t->start(800);
    bool bWMDock = false;
#ifndef WIN32
    Atom r_type;
    int r_format;
    unsigned long count, bytes_remain;
    unsigned char *prop = NULL, *prop2 = NULL;
    Atom _XA_WIN_SUPPORTING_WM_CHECK = XInternAtom(qt_xdisplay(), XA_WIN_SUPPORTING_WM_CHECK, False);
    int p = XGetWindowProperty(qt_xdisplay(), qt_xrootwin(), _XA_WIN_SUPPORTING_WM_CHECK,
                               0, 1, False, XA_CARDINAL, &r_type, &r_format,
                               &count, &bytes_remain, &prop);

    if (p == Success && prop && r_type == XA_CARDINAL &&
            r_format == 32 && count == 1)
    {
        Window n = *(long *) prop;

        p = XGetWindowProperty(qt_xdisplay(), n, _XA_WIN_SUPPORTING_WM_CHECK, 0, 1,
                               False, XA_CARDINAL, &r_type, &r_format,
                               &count, &bytes_remain, &prop2);

        if (p == Success && prop2 && r_type == XA_CARDINAL &&
                r_format == 32 && count == 1)
            bWMDock = true;
    }

    if (prop)
        XFree(prop);
    if (prop2)
        XFree(prop2);

#endif
#ifdef USE_KDE
    log(L_DEBUG, "WM props? %u", bWMDock);
    if (!bWMDock)
        KWin::setSystemTrayWindowFor( winId(), main->topLevelWidget()->winId());
#endif
    needToggle = false;
#ifdef WIN32
    QWidget::hide();
    QWidget::setIcon(Pict(pClient->getStatusIcon()));
    gDock = this;
    oldDockProc = (WNDPROC)SetWindowLongW(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
    if (oldDockProc == 0)
        oldDockProc = (WNDPROC)SetWindowLongA(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
    NOTIFYICONDATAA notifyIconData;
    notifyIconData.cbSize = sizeof(notifyIconData);
    notifyIconData.hIcon = topData()->winIcon;
    notifyIconData.hWnd = winId();
    notifyIconData.szTip[0] = 0;
    notifyIconData.uCallbackMessage = WM_DOCK;
    notifyIconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
    notifyIconData.uID = 0;
    Shell_NotifyIconA(NIM_ADD, &notifyIconData);
#else
    if (!bWMDock){
        setBackgroundMode(X11ParentRelative);
        setIcon(Pict(pClient->getStatusIcon()));
#ifdef USE_KDE
        show();
#else
    hide();
#endif
    }else{
        wharfIcon = new WharfIcon(this);
        Display *dsp = x11Display();
        WId win = winId();
        XWMHints *hints;
        XClassHint classhint;
        classhint.res_name  = (char*)"sim";
        classhint.res_class = (char*)"sim";
        XSetClassHint(dsp, win, &classhint);
        hints = XGetWMHints(dsp, win);
        hints->initial_state = WithdrawnState;
        hints->icon_x = 0;
        hints->icon_y = 0;
        hints->icon_window = wharfIcon->winId();
        hints->window_group = win;
        hints->flags = WindowGroupHint | IconWindowHint | IconPositionHint | StateHint;
        XSetWMHints(dsp, win, hints);
        XFree( hints );
        XSetCommand(dsp, winId(), _argv, _argc);
        resize(64, 64);
        show();
    }
#endif
    loadUnread();
    reset();
}
Пример #8
0
static int _x11_clip_filter(const SDL_Event *ev)
{
        XSelectionRequestEvent *req;
        XEvent sevent;
        Atom seln_type;
        int seln_format;
        unsigned long nbytes;
        unsigned long overflow;
        unsigned char *seln_data;
        unsigned char *src;

        if (ev->type != SDL_SYSWMEVENT) return 1;
        if (ev->syswm.msg->event.xevent.type == SelectionNotify) {
                sevent = ev->syswm.msg->event.xevent;
                if (sevent.xselection.requestor == SDL_Window) {
                        lock_display();
                        src = NULL;
                        if (XGetWindowProperty(SDL_Display, SDL_Window, atom_sel,
                                                0, 9000, False, XA_STRING,
                                                (Atom *)&seln_type,
                                                (int *)&seln_format,
                                                (unsigned long *)&nbytes,
                                                (unsigned long *)&overflow,
                                                (unsigned char **)&src) == Success) {
                                if (seln_type == XA_STRING) {
                                        if (_current_selection != _current_clipboard) {
                                                free(_current_clipboard);
                                        }
                                        _current_clipboard = mem_alloc(nbytes+1);
                                        memcpy(_current_clipboard, (char*)src, nbytes);
                                        _current_clipboard[nbytes] = 0;
                                        _string_paste(CLIPPY_BUFFER, _current_clipboard);
                                        _widget_owner[CLIPPY_BUFFER]
                                                        = _widget_owner[CLIPPY_SELECT];
                                }
                                XFree(src);
                        }
                        unlock_display();
                }
                return 1;
        } else if (ev->syswm.msg->event.xevent.type == PropertyNotify) {
                sevent = ev->syswm.msg->event.xevent;
                return 1;

        } else if (ev->syswm.msg->event.xevent.type != SelectionRequest) {
                return 1;
        }

        req = &ev->syswm.msg->event.xevent.xselectionrequest;
        sevent.xselection.type = SelectionNotify;
        sevent.xselection.display = req->display;
        sevent.xselection.selection = req->selection;
        sevent.xselection.target = None;
        sevent.xselection.property = None;
        sevent.xselection.requestor = req->requestor;
        sevent.xselection.time = req->time;
        if (XGetWindowProperty(SDL_Display, DefaultRootWindow(SDL_Display),
                        XA_CUT_BUFFER0, 0, 9000, False, req->target,
                        &sevent.xselection.target, &seln_format,
                        &nbytes, &overflow, &seln_data) == Success) {
                if (sevent.xselection.target == req->target) {
                        if (sevent.xselection.target == XA_STRING) {
                                if (nbytes && seln_data[nbytes-1] == '\0')
                                        nbytes--;
                        }
                        XChangeProperty(SDL_Display, req->requestor, req->property,
                                sevent.xselection.target, seln_format, PropModeReplace,
                                seln_data, nbytes);
                        sevent.xselection.property = req->property;
                }
                XFree(seln_data);
        }
        XSendEvent(SDL_Display,req->requestor,False,0,&sevent);
        XSync(SDL_Display, False);
        return 1;
}
Пример #9
0
EWMHWindowType
ewmh_get_window_type(Window w) {
    Atom rt;
    Atom *type;
    int fmt;
    unsigned long n;
    unsigned long extra;
    int i;
    EWMHWindowType ret;

    i = XGetWindowProperty(dpy, w,
                           ewmh_atom[_NET_WM_WINDOW_TYPE],
                           0, 100, False, XA_ATOM, &rt, &fmt, &n, &extra,
                           (unsigned char **)&type);
    if (i != Success || type == NULL)
        return WTypeNone;
    ret = WTypeNone;
    for (; n; n--) {
        if (type[n - 1] ==
                ewmh_atom[_NET_WM_WINDOW_TYPE_DESKTOP]) {
            ret = WTypeDesktop;
            break;
        }
        if (type[n - 1] ==
                ewmh_atom[_NET_WM_WINDOW_TYPE_DOCK]) {
            ret = WTypeDock;
            break;
        }
        if (type[n - 1] ==
                ewmh_atom[_NET_WM_WINDOW_TYPE_TOOLBAR]) {
            ret = WTypeToolbar;
            break;
        }
        if (type[n - 1] ==
                ewmh_atom[_NET_WM_WINDOW_TYPE_MENU]) {
            ret = WTypeMenu;
            break;
        }
        if (type[n - 1] ==
                ewmh_atom[_NET_WM_WINDOW_TYPE_UTILITY]) {
            ret = WTypeUtility;
            break;
        }
        if (type[n - 1] ==
                ewmh_atom[_NET_WM_WINDOW_TYPE_SPLASH]) {
            ret = WTypeSplash;
            break;
        }
        if (type[n - 1] ==
                ewmh_atom[_NET_WM_WINDOW_TYPE_DIALOG]) {
            ret = WTypeDialog;
            break;
        }
        if (type[n - 1] ==
                ewmh_atom[_NET_WM_WINDOW_TYPE_NORMAL]) {
            ret = WTypeNormal;
            break;
        }
    }
    XFree(type);
    return ret;
}
Пример #10
0
void
find_window_r (guint32 pid, Window window, Display *display, Atom atom_pid, guint32 level, GSList **result)
{
	Atom actual_type_return;
	int actual_format_return;
	unsigned long nitems_return;
	unsigned long bytes_after_return;
	unsigned char *prop_return;
	guint32 pid_of_window = 0;
	XWindowAttributes window_attributes;
	WindowInfoEx *wix = NULL;
	WindowInfo *wi = NULL;
	Window dummy;
	int x, y;

	if (Success != XGetWindowProperty (display, window, atom_pid, 0, 1, False, XA_CARDINAL, &actual_type_return, &actual_format_return, &nitems_return, &bytes_after_return, &prop_return))
		return;

	if (prop_return != NULL) {
		pid_of_window = *(guint32 *) prop_return;
		XFree (prop_return);
	}

	if (pid_of_window == pid) {
		Atom _NET_WM_NAME = XInternAtom (display, "_NET_WM_NAME", False);
		Atom UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);

//		printf ("[%i shocker] %*sFound window %p for pid %i\n", getpid (), level, " ", (void *) window, pid);

		XGetWindowAttributes (display, window, &window_attributes);
		if (window_attributes.map_state != IsViewable || window_attributes.c_class != InputOutput) {
// 			printf ("[%i shocker] WindowHelper_GetWindowInfo (%i): Window %x isn't viewable and inputoutput.\n", getpid (), pid, (int) window);
			goto recurse;
		}

		XTranslateCoordinates (display, window, window_attributes.root, -window_attributes.border_width, -window_attributes.border_width, &x, &y, &dummy);

		wix = (WindowInfoEx *) g_malloc0 (sizeof (WindowInfoEx));
		wix->window = window;
		wi = &wix->wi;
		// This is not entirely correct: we're not taking into account the title bar of the window
		wi->windowLeft = x - window_attributes.border_width;
		wi->windowTop = y - window_attributes.border_width;
		wi->windowWidth = window_attributes.width;
		wi->windowHeight = window_attributes.height;
		wi->windowRight = wi->windowLeft + wi->windowWidth;
		wi->windowBottom = wi->windowTop + wi->windowBottom;
		
		wi->clientLeft = x;
		wi->clientTop = y;
		wi->clientWidth = window_attributes.width - window_attributes.border_width * 2;
		wi->clientHeight = window_attributes.height - window_attributes.border_width * 2;
		wi->clientRight = wi->clientLeft + wi->clientWidth;
		wi->clientBottom = wi->clientTop + wi->clientHeight;
		
		// Get window name
		XGetWindowProperty (display, window, _NET_WM_NAME, 0, MAX_WINDOW_TITLE / 4, False, UTF8_STRING, &actual_type_return, &actual_format_return, &nitems_return, &bytes_after_return, &prop_return);
		if (nitems_return > 0 && prop_return != NULL) {
			memcpy (wi->title, prop_return, MIN (nitems_return, MAX_WINDOW_TITLE - 1));
		}
		
		*result = g_slist_prepend (*result, wix);
		return;
	}

recurse:
// 	printf ("[%i shocker] %*sFound window %p is not in pid %i\n", getpid (), level, " ", (void *) window, pid);
	
	// Recurse into children
	Window root_return;
	Window parent_return;
	Window *children;
	unsigned int n_children;
	if (0 != (XQueryTree (display, window, &root_return, &parent_return, &children, &n_children))) {
		for (unsigned int i = 0; i < n_children; i++) {
			find_window_r (pid, children [i], display, atom_pid, level + 1, result);
		}
	}
}
Пример #11
0
static gboolean
skype_connect()
{
	Window root;
	Atom skype_inst;
	Atom type_ret;
	int format_ret;
	unsigned long nitems_ret;
	unsigned long bytes_after_ret;
	unsigned char *prop;
	int status;
	
	x11_error_code = 0;
	XSetErrorHandler(x11_error_handler);
	skype_debug_info("skype_x11", "Set the XErrorHandler\n");
#ifdef USE_XVFB_SERVER	
	if (!getenv("SKYPEDISPLAY"))
		setenv("SKYPEDISPLAY", ":25", 0);
#endif
	if (getenv("SKYPEDISPLAY"))
		disp = XOpenDisplay(getenv("SKYPEDISPLAY"));
	else
		disp = XOpenDisplay(getenv("DISPLAY"));
	if (disp == NULL)
	{
		skype_debug_info("skype_x11", "Couldn't open display\n");
		return FALSE;
	}
	skype_debug_info("skype_x11", "Opened display\n");
	message_start = XInternAtom( disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False );
	message_continue = XInternAtom( disp, "SKYPECONTROLAPI_MESSAGE", False );
	root = DefaultRootWindow( disp );
	win = XCreateSimpleWindow( disp, root, 0, 0, 1, 1,
		0, BlackPixel( disp, DefaultScreen( disp ) ),
		BlackPixel( disp, DefaultScreen( disp ) ));
	XFlush(disp);
	if (win == -1)
	{
		XCloseDisplay(disp);
		skype_debug_info("skype_x11", "Could not create X11 messaging window\n");
		return FALSE;
	}
	skype_debug_info("skype_x11", "Created X11 messaging window\n");
	skype_inst = XInternAtom(disp, "_SKYPE_INSTANCE", True);
	if (skype_inst == None)
	{
		XDestroyWindow(disp, win);
		XCloseDisplay(disp);
		win = (Window)-1;
		skype_win = (Window)-1;
		skype_debug_info("skype_x11", "Could not create skype Atom\n");
		return FALSE;
	}
	skype_debug_info("skype_x11", "Created skype Atom\n");
	status = XGetWindowProperty(disp, root, skype_inst, 0, 1, False, XA_WINDOW, &type_ret, &format_ret, &nitems_ret, &bytes_after_ret, &prop);
	if(status != Success || format_ret != 32 || nitems_ret < 1)
	{
		XDestroyWindow(disp, win);
		XCloseDisplay(disp);
		win = (Window)-1;
		XFree(prop);
		skype_win = (Window)-1;
		skype_debug_info("skype", "Skype instance not found\n");
		return FALSE;
	}
	skype_debug_info("skype_x11", "Skype instance found\n");
	skype_win = * (const unsigned long *) prop & 0xffffffff;
	XFree(prop);
	run_loop = TRUE;
	
	skype_debug_info("skype_x11", "Charging lasers...\n");
	receiving_thread = g_thread_create((GThreadFunc)receive_message_loop, NULL, FALSE, NULL);
	
	return TRUE;
}
Пример #12
0
char *x11_get_wm_name(Display *dpy)
{
   Atom XA_NET_SUPPORTING_WM_CHECK = XInternAtom(g_x11_dpy, "_NET_SUPPORTING_WM_CHECK", False);
   Atom XA_NET_WM_NAME             = XInternAtom(g_x11_dpy, "_NET_WM_NAME", False);
   Atom XA_UTF8_STRING             = XInternAtom(g_x11_dpy, "UTF8_STRING", False);
   int status;
   Atom type;
   int  format;
   unsigned long nitems;
   unsigned long bytes_after;
   unsigned char *propdata;
   char *title;
   Window window;

   if (!XA_NET_SUPPORTING_WM_CHECK || !XA_NET_WM_NAME)
      return NULL;

   status = XGetWindowProperty(dpy,
                               DefaultRootWindow(dpy),
                               XA_NET_SUPPORTING_WM_CHECK,
                               0,
                               1,
                               False,
                               XA_WINDOW,
                               &type,
                               &format,
                               &nitems,
                               &bytes_after,
                               &propdata);

   if (status == Success && propdata)
      window = ((Window *) propdata)[0];
   else
      return NULL;

   XFree(propdata);

   status = XGetWindowProperty(dpy,
                               window,
                               XA_NET_WM_NAME,
                               0,
                               8192,
                               False,
                               XA_UTF8_STRING,
                               &type,
                               &format,
                               &nitems,
                               &bytes_after,
                               &propdata);

   if (status == Success && propdata)
   {
      title = strdup((char *) propdata);
   }
   else
      return NULL;

   XFree(propdata);

   return title;
}
Пример #13
0
//
// I_GetClipboardText
//
// by Denis Lukianov - 20 Mar 2006
// Cross-platform clipboard functionality
//
std::string I_GetClipboardText (void)
{
#ifdef X11
	std::string ret;
	
	Display *dis = XOpenDisplay(NULL);
	int screen = DefaultScreen(dis);
	
	if(!dis)
	{
		Printf(PRINT_HIGH, "I_GetClipboardText: XOpenDisplay failed");
		return "";
	}
	
	XLockDisplay(dis);
	
	Window WindowEvents = XCreateSimpleWindow(dis, RootWindow(dis, screen), 0, 0, 1, 1, 0, BlackPixel(dis, screen), BlackPixel(dis, screen));

	if(XGetSelectionOwner(dis, XA_PRIMARY) != None)
	{
		if(!XConvertSelection(dis, XA_PRIMARY, XA_STRING, XA_PRIMARY, WindowEvents, CurrentTime))
		{
			XDestroyWindow(dis, WindowEvents);
			XUnlockDisplay(dis);
			XCloseDisplay(dis);
			Printf(PRINT_HIGH, "I_GetClipboardText: XConvertSelection failed");
			return "";
		}
		
		XFlush (dis);
		
		// Wait for the reply
		for(;;)
		{
			XEvent e;
			XNextEvent(dis, &e);

			if(e.type == SelectionNotify)
				break;
		}
		
		Atom type;
		int format, result;
		u_long len, bytes_left, temp;
		u_char *data;

		result = XGetWindowProperty(dis, WindowEvents, XA_PRIMARY, 0, 0, False, AnyPropertyType, &type, &format, &len, &bytes_left, &data);
		if(result != Success)
		{
			XDestroyWindow(dis, WindowEvents);
			XUnlockDisplay(dis);
			XCloseDisplay(dis);
			Printf(PRINT_HIGH, "I_GetClipboardText: XGetWindowProperty failed(1)");
			return "";
		}
		
		if(!bytes_left)
		{
			XDestroyWindow(dis, WindowEvents);
			Printf(PRINT_HIGH, "I_GetClipboardText: Len was: %d", len);
			XUnlockDisplay(dis);
			XCloseDisplay(dis);
			return "";
		}
		
		result = XGetWindowProperty(dis, WindowEvents, XA_PRIMARY, 0, bytes_left, False, AnyPropertyType, &type, &format, &len, &temp, &data);
		if(result != Success)
		{
			XDestroyWindow(dis, WindowEvents);
			XUnlockDisplay(dis);
			XCloseDisplay(dis);
			Printf(PRINT_HIGH, "I_GetClipboardText: XGetWindowProperty failed(2)");
			return "";
		}
	
		ret = std::string((const char *)data, len);
		XFree(data);
	}

	XDestroyWindow(dis, WindowEvents);
	XUnlockDisplay(dis);
	XCloseDisplay(dis);
	
	return ret;
#endif

#ifdef WIN32
	std::string ret;

	if(!IsClipboardFormatAvailable(CF_TEXT))
		return "";

	if(!OpenClipboard(NULL))
		return "";
	
	HANDLE hClipboardData = GetClipboardData(CF_TEXT);
		
	if(!hClipboardData)
	{
		CloseClipboard();
		return "";
	}
	
	const char *cData = reinterpret_cast<const char *>(GlobalLock(hClipboardData));
	u_int uiSize = static_cast<u_int>(GlobalSize(hClipboardData));
			
	if(cData && uiSize)
	{
		for(size_t i = 0; i < uiSize; i++)
		{
			if(!cData[i])
			{
				uiSize = i;
				break;
			}
		}

		ret = std::string(cData, uiSize);
	}
	
	GlobalUnlock(hClipboardData);

	CloseClipboard();
	
	return ret;
#endif
	
#ifdef OSX
	ScrapRef scrap;
	Size size;
	
	int err = GetCurrentScrap(&scrap);
	
	if(err)
	{
		Printf(PRINT_HIGH, "GetCurrentScrap error: %d", err);
		return "";
	}
	
	err = GetScrapFlavorSize(scrap, FOUR_CHAR_CODE('TEXT'), &size);
	
	if(err)
	{
		Printf(PRINT_HIGH, "GetScrapFlavorSize error: %d", err);
		return "";
	}
	
	char *data = new char[size+1];
	
	err = GetScrapFlavorData(scrap, FOUR_CHAR_CODE('TEXT'), &size, data);
	data[size] = 0;
	
	if(err)
	{
		Printf(PRINT_HIGH, "GetScrapFlavorData error: %d", err);
		delete[] data;
	}
	
	std::string ret(data);
	
	delete[] data;
	
	return ret;
#endif
	
	return "";
}
Пример #14
0
DockWnd::DockWnd(DockPlugin *plugin, const char *icon, const char *text)
        : QWidget(NULL, "dock",  WType_TopLevel | WStyle_Customize | WStyle_NoBorder | WStyle_StaysOnTop),
        EventReceiver(LowPriority)
{
#ifndef WIN32
#ifndef QT_MACOSX_VERSION
    wharfIcon = NULL;
#endif
#endif
    m_plugin = plugin;
    setMouseTracking(true);
    bNoToggle = false;
    bBlink = false;
    m_state = icon;
    blinkTimer = new QTimer(this);
    connect(blinkTimer, SIGNAL(timeout()), this, SLOT(blink()));
#ifdef WIN32
    hShell = NULL;
    setIcon(icon);
    QWidget::hide();
    gDock = this;
    if (IsWindowUnicode(winId())){
        (HMODULE&)hShell = LoadLibraryA("shell32.dll");
        if (hShell)
            (DWORD&)_Shell_NotifyIconW = (DWORD)GetProcAddress((HMODULE)hShell, "Shell_NotifyIconW");
    }
    if (IsWindowUnicode(winId()) && _Shell_NotifyIconW){
        oldDockProc = (WNDPROC)SetWindowLongW(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
        NOTIFYICONDATAW notifyIconData;
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hIcon = topData()->winIcon;
        notifyIconData.hWnd = winId();
        notifyIconData.szTip[0] = 0;
        notifyIconData.uCallbackMessage = WM_DOCK;
        notifyIconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
        notifyIconData.uID = 0;
        _Shell_NotifyIconW(NIM_ADD, &notifyIconData);
    }else{
        oldDockProc = (WNDPROC)SetWindowLongA(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
        NOTIFYICONDATAA notifyIconData;
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hIcon = topData()->winIcon;
        notifyIconData.hWnd = winId();
        notifyIconData.szTip[0] = 0;
        notifyIconData.uCallbackMessage = WM_DOCK;
        notifyIconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
        notifyIconData.uID = 0;
        Shell_NotifyIconA(NIM_ADD, &notifyIconData);
    }
#else
    setMinimumSize(22, 22);
    resize(22, 22);
#ifndef QT_MACOSX_VERSION
    bInit = false;
    inTray = false;
    inNetTray = false;

    Display *dsp = x11Display();
    WId win = winId();

    bool bEnlightenment = false;
    QWidget tmp;
    Atom enlightenment_desktop = XInternAtom(dsp, "ENLIGHTENMENT_DESKTOP", false);
    WId w = tmp.winId();
    Window p, r;
    Window *c;
    unsigned int nc;
    while (XQueryTree(dsp, w, &r, &p, &c, &nc)){
        if (c && nc > 0)
            XFree(c);
        if (! p) {
            log(L_WARN, "No parent");
            break;
        }
        unsigned char *data_ret = NULL;
        Atom type_ret;
        int i_unused;
        unsigned long l_unused;
        if ((XGetWindowProperty(dsp, p, enlightenment_desktop, 0, 1, False, XA_CARDINAL,
                                &type_ret, &i_unused, &l_unused, &l_unused,
                                &data_ret) == Success) && (type_ret == XA_CARDINAL)) {
            if (data_ret)
                XFree(data_ret);
            bEnlightenment = true;
            log(L_DEBUG, "Detect Enlightenment");
            break;
        }
        if (p == r) break;
        w = p;
    }

    if (bEnlightenment){
        bInit = true;
        resize(48, 48);
        setFocusPolicy(NoFocus);
        move(m_plugin->getDockX(), m_plugin->getDockY());
        MWMHints mwm;
        mwm.flags = MWM_HINTS_DECORATIONS;
        mwm.functions = 0;
        mwm.decorations = 0;
        mwm.inputMode = 0;
        mwm.status = 0;
        Atom a = XInternAtom(dsp, "_MOTIF_WM_HINTS", False);
        XChangeProperty(dsp, win, a, a, 32, PropModeReplace,
                        (unsigned char *)&mwm, sizeof(MWMHints) / 4);
        XStoreName(dsp, win, "SIM");
        XClassHint *xch = XAllocClassHint();
        xch->res_name  = (char*)"SIM";
        xch->res_class = (char*)"Epplet";
        XSetClassHint(dsp, win, xch);
        XFree(xch);
        XSetIconName(dsp, win, "SIM");
        unsigned long val = (1 << 0) /* | (1 << 9) */ ;
        a = XInternAtom(dsp, "_WIN_STATE", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        val = 2;
        a = XInternAtom(dsp, "_WIN_LAYER", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        val = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 5);
        a = XInternAtom(dsp, "_WIN_HINTS", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        win_name = "SIM";
        win_version = VERSION;
        win_info = "";
        while (!comms_win)
        {
            ECommsSetup(dsp);
            sleep(1);
        }
        char s[256];
        snprintf(s, sizeof(s), "set clientname %s", win_name);
        ECommsSend(s);
        snprintf(s, sizeof(s), "set version %s", win_version);
        ECommsSend(s);
        snprintf(s, sizeof(s), "set info %s", win_info);
        ECommsSend(s);
        ESYNC;

        set_background_properties(this);

        setIcon(icon);
        show();
        return;
    }

    wharfIcon = new WharfIcon(this);
#endif
    setBackgroundMode(X11ParentRelative);
    setIcon(icon);

#ifndef QT_MACOSX_VERSION
    XClassHint classhint;
    classhint.res_name  = (char*)"sim";
    classhint.res_class = (char*)"Wharf";
    XSetClassHint(dsp, win, &classhint);

    Screen *screen = XDefaultScreenOfDisplay(dsp);
    int screen_id = XScreenNumberOfScreen(screen);
    char buf[32];
    snprintf(buf, sizeof(buf), "_NET_SYSTEM_TRAY_S%d", screen_id);
    Atom selection_atom = XInternAtom(dsp, buf, false);
    XGrabServer(dsp);
    Window manager_window = XGetSelectionOwner(dsp, selection_atom);
    if (manager_window != None)
        XSelectInput(dsp, manager_window, StructureNotifyMask);
    XUngrabServer(dsp);
    XFlush(dsp);
    if (manager_window != None){
        inNetTray = true;
        if (!send_message(dsp, manager_window, SYSTEM_TRAY_REQUEST_DOCK, win, 0, 0)){
            inNetTray = false;
        }
    }

    Atom kde_net_system_tray_window_for_atom = XInternAtom(dsp, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);

    long data[1];
    data[0] = 0;
    XChangeProperty(dsp, win, kde_net_system_tray_window_for_atom, XA_WINDOW,
                    32, PropModeReplace,
                    (unsigned char*)data, 1);

    XWMHints *hints;
    hints = XGetWMHints(dsp, win);
    hints->initial_state = WithdrawnState;
    hints->icon_x = 0;
    hints->icon_y = 0;
    hints->icon_window = wharfIcon->winId();
    hints->window_group = win;
    hints->flags = WindowGroupHint | IconWindowHint | IconPositionHint | StateHint;
    XSetWMHints(dsp, win, hints);
    XFree( hints );

    Event eArgc(EventArgc);
    int argc = (int)eArgc.process();
    Event eArgv(EventArgv);
    char **argv = (char**)eArgv.process();
    XSetCommand(dsp, win, argv, argc);

    if (!inNetTray){
        move(-21, -21);
        resize(22, 22);
    }
#endif
    show();
#endif
    setTip(text);
    reset();
}
Пример #15
0
Файл: gui.c Проект: mortehu/bra
void
gui_main_loop (void)
{
  XEvent event;
  struct gui_instance *gi;

  while (0 == XNextEvent (GUI_display, &event))
    {
      if (0 == (gi = find_instance (event.xany.window)))
        continue;

      if (XFilterEvent (&event, gi->window))
        continue;

      if (gi->definition.x11_event)
        gi->definition.x11_event (gi, &event);

      switch (event.type)
        {
        case KeyPress:

          gi->last_event = event.xkey.time;

          if (gi->definition.key_pressed)
            {
              wchar_t text[32];
              Status status;
              KeySym key_sym;
              int len;

              len = XwcLookupString (gi->xic, &event.xkey, text, sizeof (text) / sizeof (text[0]) - 1, &key_sym, &status);
              text[len] = 0;

              if (status == XLookupNone)
                return;

              gi->definition.key_pressed (gi,
                                          (status == XLookupKeySym || status == XLookupBoth) ? key_sym : 0,
                                          (status == XLookupChars || status == XLookupBoth) ? text : NULL,
                                          event.xkey.state);
            }

          break;

        case KeyRelease:

          gi->last_event = event.xkey.time;

          if (gi->definition.key_released)
            {
              KeySym key_sym;

              key_sym = XLookupKeysym (&event.xkey, 0);

              gi->definition.key_released (gi, key_sym);
            }

          break;


        case MotionNotify:

          gi->last_event = event.xmotion.time;

          if (gi->definition.mouse_moved)
            gi->definition.mouse_moved (gi, event.xmotion.x,
                                        event.xmotion.y);

          break;

        case ButtonPress:

          gi->last_event = event.xbutton.time;

          if (gi->definition.button_pressed)
            gi->definition.button_pressed (gi, event.xbutton.button - 1,
                                           event.xbutton.state);

          break;

        case ButtonRelease:

          gi->last_event = event.xbutton.time;

          if (gi->definition.button_released)
            gi->definition.button_released (gi, event.xbutton.button - 1,
                                            event.xbutton.state);


          break;

        case ConfigureNotify:

          while (XCheckTypedWindowEvent (GUI_display, gi->window, ConfigureNotify, &event))
            {
              /* Do nothing */
            }

          if (gi->width == event.xconfigure.width && gi->height == event.xconfigure.height)
            break;

          gi->width = event.xconfigure.width;
          gi->height = event.xconfigure.height;

          configure_window (gi);

          XClearArea (GUI_display, gi->window, 0, 0, 0, 0, True);

          break;

        case NoExpose:

          break;

        case Expose:

            {
              int minx = event.xexpose.x;
              int miny = event.xexpose.y;
              int maxx = minx + event.xexpose.width;
              int maxy = miny + event.xexpose.height;

              while (XCheckTypedWindowEvent (GUI_display, gi->window, Expose, &event))
                {
                  if (event.xexpose.x < minx) minx = event.xexpose.x;
                  if (event.xexpose.y < miny) miny = event.xexpose.y;
                  if (event.xexpose.x + event.xexpose.width > maxx) maxx = event.xexpose.x + event.xexpose.width;
                  if (event.xexpose.y + event.xexpose.height > maxx) maxx = event.xexpose.y + event.xexpose.height;
                }

              gi->repaint_waiting = 0;

              if (!gi->back_buffer)
                configure_window (gi);

              gi->definition.paint (gi, minx, miny, maxx - minx, maxy - miny);

              XRenderComposite (GUI_display, PictOpSrc, gi->back_buffer, None,
                                gi->front_buffer, minx, miny, 0, 0, minx, miny,
                                maxx - minx, maxy - miny);
            }

          break;

        case ClientMessage:

          if (event.xclient.data.l[0] == xa_wm_delete_window)
            gi->definition.destroy (gi);

          break;

        case SelectionRequest:

            {
              XSelectionRequestEvent* request;
              XSelectionEvent response;
              enum gui_clipboard clipboard;
              int ret;

              request = &event.xselectionrequest;

              if (request->selection == XA_PRIMARY)
                clipboard = GUI_PRIMARY_SELECTION;
              else if (request->selection == XA_SECONDARY)
                clipboard = GUI_SECONDARY_SELECTION;
              else if (request->selection == xa_clipboard)
                clipboard = GUI_CLIPBOARD;
              else
                break;

              if (!gi->clipboards[clipboard].length)
                break;

              if (request->target != XA_STRING
                  && request->target != xa_utf8_string)
                break;

              if (request->property == None)
                request->property = request->target;

              response.type = SelectionNotify;
              response.send_event = True;
              response.display = GUI_display;
              response.requestor = request->requestor;
              response.selection = request->selection;
              response.target = request->target;
              response.property = None;
              response.time = request->time;

              ret = XChangeProperty (GUI_display, request->requestor,
                                     request->property, request->target,
                                     8, PropModeReplace,
                                     gi->clipboards[clipboard].data,
                                     gi->clipboards[clipboard].length);

              if (ret != BadAlloc && ret != BadAtom
                  && ret != BadValue && ret != BadWindow)
                response.property = request->property;

              XSendEvent (request->display, request->requestor, False,
                          NoEventMask, (XEvent*) &response);
            }

          break;

        case SelectionNotify:

            {
              unsigned char* prop;
              unsigned long nitems, bytes_after;
              Atom type;
              int format, result;

              result = XGetWindowProperty (GUI_display, gi->window,
                                           xa_prop_paste, 0, 0, False,
                                           AnyPropertyType, &type, &format,
                                           &nitems, &bytes_after, &prop);

              if (result != Success)
                break;

              XFree (prop);

              result = XGetWindowProperty (GUI_display, gi->window,
                                           xa_prop_paste, 0, bytes_after,
                                           False, AnyPropertyType, &type,
                                           &format, &nitems, &bytes_after,
                                           &prop);

              if (result != Success)
                break;

              if (gi->definition.paste
                  && type == xa_utf8_string && format == 8)
                {
                  gi->definition.paste (gi, (const char*) prop, nitems);
                }

              XFree (prop);
            }

          break;
        }
    }
}
Пример #16
0
/**
 * gdk_x11_screen_supports_net_wm_hint:
 * @screen: (type GdkX11Screen): the relevant #GdkScreen.
 * @property: a property atom.
 *
 * This function is specific to the X11 backend of GDK, and indicates
 * whether the window manager supports a certain hint from the
 * [Extended Window Manager Hints](http://www.freedesktop.org/Standards/wm-spec) specification.
 *
 * When using this function, keep in mind that the window manager
 * can change over time; so you shouldn’t use this function in
 * a way that impacts persistent application state. A common bug
 * is that your application can start up before the window manager
 * does when the user logs in, and before the window manager starts
 * gdk_x11_screen_supports_net_wm_hint() will return %FALSE for every property.
 * You can monitor the window_manager_changed signal on #GdkScreen to detect
 * a window manager change.
 *
 * Returns: %TRUE if the window manager supports @property
 *
 * Since: 2.2
 **/
gboolean
gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen,
				     GdkAtom    property)
{
  gulong i;
  GdkX11Screen *x11_screen;
  NetWmSupportedAtoms *supported_atoms;
  GdkDisplay *display;
  Atom atom;

  g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);

  x11_screen = GDK_X11_SCREEN (screen);
  display = x11_screen->display;

  if (!G_LIKELY (GDK_X11_DISPLAY (display)->trusted_client))
    return FALSE;

  supported_atoms = g_object_get_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms");
  if (!supported_atoms)
    {
      supported_atoms = g_new0 (NetWmSupportedAtoms, 1);
      g_object_set_data_full (G_OBJECT (screen), "gdk-net-wm-supported-atoms", supported_atoms, cleanup_atoms);
    }

  fetch_net_wm_check_window (screen);

  if (x11_screen->wmspec_check_window == None)
    return FALSE;

  if (x11_screen->need_refetch_net_supported)
    {
      /* WM has changed since we last got the supported list,
       * refetch it.
       */
      Atom type;
      gint format;
      gulong bytes_after;

      x11_screen->need_refetch_net_supported = FALSE;

      if (supported_atoms->atoms)
        XFree (supported_atoms->atoms);

      supported_atoms->atoms = NULL;
      supported_atoms->n_atoms = 0;

      XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), x11_screen->xroot_window,
                          gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTED"),
                          0, G_MAXLONG, False, XA_ATOM, &type, &format,
                          &supported_atoms->n_atoms, &bytes_after,
                          (guchar **)&supported_atoms->atoms);

      if (type != XA_ATOM)
        return FALSE;
    }

  if (supported_atoms->atoms == NULL)
    return FALSE;

  atom = gdk_x11_atom_to_xatom_for_display (display, property);

  for (i = 0; i < supported_atoms->n_atoms; i++)
    {
      if (supported_atoms->atoms[i] == atom)
        return TRUE;
    }

  return FALSE;
}
Пример #17
0
void Loop(Window target)
{
  Window root;
  int x,y,border_width,depth;
  XEvent Event;
  int tw,th;
  char *temp;
  char *prop = NULL;
  Atom actual = None;
  int actual_format;
  unsigned long nitems, bytesafter;

  while(1)
    {
      XNextEvent(dpy,&Event);
      switch(Event.type)
	{
	case Expose:
	  exposed = 1;
	  RedrawWindow(target);
	  break;
	  
	case ConfigureNotify:
	  XGetGeometry(dpy,main_win,&root,&x,&y,
		       (unsigned int *)&tw,(unsigned int *)&th,
		       (unsigned int *)&border_width,
		       (unsigned int *)&depth);
	  if((tw != Width)||(th!= Height))
	    {
	      XResizeWindow(dpy,holder_win,tw-BAR_WIDTH-PAD_WIDTH3,
			    th-BAR_WIDTH-PAD_WIDTH3);
	      Width = tw;
	      Height = th;
	      if(target_y_offset + Height - BAR_WIDTH > target_height)
		target_y_offset  = target_height - Height + BAR_WIDTH;
	      if(target_y_offset < 0)
		target_y_offset = 0;
	      if(target_x_offset < 0)
		target_x_offset = 0;
	      if(target_x_offset + Width - BAR_WIDTH > target_width)
		target_x_offset  = target_width - Width + BAR_WIDTH;

	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	      exposed = 1;
	      RedrawWindow(target);
	    }
	  break;
	  
	case ButtonPress:
	  if((Event.xbutton.y > Height-BAR_WIDTH) &&
	     (Event.xbutton.x < SCROLL_BAR_WIDTH+PAD_WIDTH3))
	    {
	      motion = LEFT;
	      exposed = 2;
	      RedrawWindow(target);
	    }
	  else if((Event.xbutton.y > Height-BAR_WIDTH) &&
	     (Event.xbutton.x > Width-BAR_WIDTH-SCROLL_BAR_WIDTH-2) &&
	     (Event.xbutton.x < Width-BAR_WIDTH))
	    {
	      motion = RIGHT;
	      exposed = 2;
	      RedrawWindow(target);
	    }
	  else if((Event.xbutton.y < SCROLL_BAR_WIDTH+PAD_WIDTH3) &&
	     (Event.xbutton.x > Width-BAR_WIDTH))
	    {
	      motion = TOP;
	      exposed = 2;
	      RedrawWindow(target);
	    }
	  else if((Event.xbutton.y > Height-BAR_WIDTH-SCROLL_BAR_WIDTH-2) &&
	     (Event.xbutton.y < Height-BAR_WIDTH)&&
	     (Event.xbutton.x > Width-BAR_WIDTH))
	    {
	      motion = BOTTOM;
	      exposed = 2;
	      RedrawWindow(target);
	    }
	  else if((Event.xbutton.x > Width - BAR_WIDTH)&&
		  (Event.xbutton.y < Height- BAR_WIDTH))
	    {

	      motion = VERTICAL;
	      target_y_offset=(Event.xbutton.y-PAD_WIDTH3-SCROLL_BAR_WIDTH)*
		target_height/
		(Height-BAR_WIDTH-PAD_WIDTH3 - 2*SCROLL_BAR_WIDTH);
	      if(target_y_offset+Height-BAR_WIDTH -PAD_WIDTH3 > target_height)
		target_y_offset  = target_height - Height+BAR_WIDTH+PAD_WIDTH3;
	      if(target_y_offset < 0)
		target_y_offset = 0;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	      RedrawWindow(target);
	    }
	  else if((Event.xbutton.y > Height- BAR_WIDTH ) &&
		  (Event.xbutton.x < Width- BAR_WIDTH))	    
	    {
	      motion=HORIZONTAL;
	      target_x_offset=(Event.xbutton.x -PAD_WIDTH3-SCROLL_BAR_WIDTH)*
		target_width/
		(Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH);
	      if(target_x_offset < 0)
		target_x_offset = 0;
	      
	      if(target_x_offset + Width - BAR_WIDTH -PAD_WIDTH3> target_width)
		target_x_offset  = target_width - Width + BAR_WIDTH+PAD_WIDTH3;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	      RedrawWindow(target);
	    }
	  else if((Event.xbutton.y > Height- BAR_WIDTH ) &&
		  (Event.xbutton.x > Width- BAR_WIDTH))	    
	    {
	      exposed = 2;
	      motion=QUIT;
	    }
	  RedrawWindow(target);
	  break;

	case ButtonRelease:
	  if((Event.xbutton.y > Height- BAR_WIDTH ) &&
	    (Event.xbutton.x > Width- BAR_WIDTH)&&
	     (motion==QUIT))
	    {
	      XUnmapWindow(dpy,main_win);
	      XReparentWindow(dpy,target,Root,x,y);
	      XSync(dpy,0);
	      exit(0);
	    }
	  if((motion == LEFT)&&(Event.xbutton.y > Height-BAR_WIDTH) &&
	     (Event.xbutton.x < SCROLL_BAR_WIDTH+PAD_WIDTH3))
	    {
	      target_x_offset -= (Width-BAR_WIDTH-PAD_WIDTH2);
	      if(target_x_offset < 0)
		target_x_offset = 0;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	      motion = NONE;
	      exposed = 2;
	    }
	  else if((motion == RIGHT)&&(Event.xbutton.y > Height-BAR_WIDTH) &&
	     (Event.xbutton.x > Width-BAR_WIDTH-SCROLL_BAR_WIDTH-2) &&
	     (Event.xbutton.x < Width-BAR_WIDTH))
	    {
	      target_x_offset += (Width-BAR_WIDTH-PAD_WIDTH2);
	      if(target_x_offset+Width-BAR_WIDTH -PAD_WIDTH3 > target_width)
		target_x_offset  = target_width - Width+BAR_WIDTH+PAD_WIDTH3;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	      motion = NONE;
	      exposed = 2;
	    }
	  else if((motion == TOP)&&
		  (Event.xbutton.y<SCROLL_BAR_WIDTH+PAD_WIDTH3)&&
		  (Event.xbutton.x > Width-BAR_WIDTH))
	    {
	      target_y_offset -= (Height-BAR_WIDTH-PAD_WIDTH2);
	      if(target_y_offset < 0)
		target_y_offset = 0;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	      motion = NONE;
	      exposed = 2;
	    }
	  else if((motion == BOTTOM)&&
		  (Event.xbutton.y > Height-BAR_WIDTH-SCROLL_BAR_WIDTH-2) &&
		  (Event.xbutton.y < Height-BAR_WIDTH)&&
		  (Event.xbutton.x > Width-BAR_WIDTH))
	    {
	      target_y_offset += (Height-BAR_WIDTH-PAD_WIDTH2);
	      if(target_y_offset+Height-BAR_WIDTH -PAD_WIDTH3 > target_height)
		target_y_offset  = target_height - Height+BAR_WIDTH+PAD_WIDTH3;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	      motion = NONE;
	      exposed = 2;
	    }
	  if(motion == VERTICAL)
	    {
	      target_y_offset=(Event.xbutton.y-PAD_WIDTH3-SCROLL_BAR_WIDTH)*target_height/
		(Height-BAR_WIDTH-PAD_WIDTH3 - 2*SCROLL_BAR_WIDTH);
	      if(target_y_offset+Height-BAR_WIDTH -PAD_WIDTH3 > target_height)
		target_y_offset  = target_height - Height+BAR_WIDTH+PAD_WIDTH3;
	      if(target_y_offset < 0)
		target_y_offset = 0;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	    }
	  if(motion == HORIZONTAL)
	    {
	      target_x_offset=(Event.xbutton.x -PAD_WIDTH3-SCROLL_BAR_WIDTH)* target_width/
		(Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH);
	      if(target_x_offset < 0)
		target_x_offset = 0;
	      
	      if(target_x_offset + Width - BAR_WIDTH -PAD_WIDTH3> target_width)
		target_x_offset  = target_width - Width + BAR_WIDTH+PAD_WIDTH3;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	    }
	  RedrawWindow(target);
	  motion = NONE;
	  break;

	case MotionNotify:
	  if((motion == LEFT)&&((Event.xmotion.y < Height-BAR_WIDTH) ||
	     (Event.xmotion.x > SCROLL_BAR_WIDTH+PAD_WIDTH3)))
	    {
	      motion = NONE;
	      exposed = 2;
	    }
	  else if((motion == RIGHT)&&((Event.xmotion.y < Height-BAR_WIDTH) ||
	     (Event.xmotion.x < Width-BAR_WIDTH-SCROLL_BAR_WIDTH-2) ||
	     (Event.xmotion.x > Width-BAR_WIDTH)))
	    {
	      motion = NONE;
	      exposed = 2;
	    }
	  else if((motion == TOP)&&
		  ((Event.xmotion.y>SCROLL_BAR_WIDTH+PAD_WIDTH3)||
		   (Event.xmotion.x < Width-BAR_WIDTH)))
	    {
	      motion = NONE;
	      exposed = 2;
	    }
	  else if((motion == BOTTOM)&&
		  ((Event.xmotion.y < Height-BAR_WIDTH-SCROLL_BAR_WIDTH-2) ||
		   (Event.xmotion.y > Height-BAR_WIDTH)||
		   (Event.xmotion.x < Width-BAR_WIDTH)))
	    {
	      motion = NONE;
	      exposed = 2;
	    }
	  if(motion == VERTICAL)
	    {
	      target_y_offset=(Event.xmotion.y-PAD_WIDTH3-SCROLL_BAR_WIDTH)*
		target_height/
		(Height-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH);
	      if(target_y_offset+Height-BAR_WIDTH -PAD_WIDTH3 > target_height)
		target_y_offset  = target_height - Height+BAR_WIDTH+PAD_WIDTH3;
	      if(target_y_offset < 0)
		target_y_offset = 0;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	    }
	  if(motion == HORIZONTAL)
	    {
	      target_x_offset=(Event.xmotion.x -PAD_WIDTH3-SCROLL_BAR_WIDTH)*
		target_width/
		(Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH);
	      if(target_x_offset < 0)
		target_x_offset = 0;
	      
	      if(target_x_offset + Width - BAR_WIDTH -PAD_WIDTH3> target_width)
		target_x_offset  = target_width - Width + BAR_WIDTH+PAD_WIDTH3;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	    }
	  if((motion == QUIT)&&
	    ((Event.xbutton.y < Height- BAR_WIDTH )||
	       (Event.xbutton.x < Width- BAR_WIDTH)))
	    {
	      motion = NONE;
	      exposed = 2;
	    }
	  RedrawWindow(target);
	  break;
	case ClientMessage:
	  if ((Event.xclient.format==32) && 
	      (Event.xclient.data.l[0]==wm_del_win))
	    {
	      DeadPipe(1);
	    }
	  break;
	case PropertyNotify:
	  if(Event.xproperty.atom == XA_WM_NAME)
	    {
	      if(XFetchName(dpy, target, &temp)==0)
		temp = NULL;
	      change_window_name(temp);
	    }
	  else if (Event.xproperty.atom == XA_WM_ICON_NAME)
	    {
	      if (XGetWindowProperty (dpy,
				      target, Event.xproperty.atom, 0,
				      MAX_ICON_NAME_LEN, False, XA_STRING, 
				      &actual,&actual_format, &nitems, 
				      &bytesafter, (unsigned char **) &prop)
		  == Success && (prop != NULL))
		change_icon_name(prop);
	    }
	  else if(Event.xproperty.atom == XA_WM_HINTS)
	    {
	      XWMHints *wmhints;

	      wmhints = XGetWMHints(dpy,target);
	      XSetWMHints(dpy,main_win, wmhints);
	      XFree(wmhints);
	    }
	  else if(Event.xproperty.atom == XA_WM_NORMAL_HINTS)	  
	    {
	      /* don't do Normal Hints. They alter the size of the window */
	    }
	  else if (Event.xproperty.atom == _XA_WM_COLORMAP_WINDOWS)
	    {
	    }
	  break;
	  
	case DestroyNotify:
	  DeadPipe(1);
	  break;

	case UnmapNotify:
	  break;

	case MapNotify:
	  XMapWindow(dpy,main_win);
	  break;
	case FocusIn:
	  XSetInputFocus(dpy,target,RevertToParent,CurrentTime);
	  break;
	case ColormapNotify:
	  {
	    XWindowAttributes xwa;
	    if(XGetWindowAttributes(dpy,target, &xwa) != 0)
	      {
		XSetWindowColormap(dpy,main_win,xwa.colormap);
	      }
	  }
	  break;
	default:
	  break;
	}
    }
  return;
}
Пример #18
0
static void
get_work_area (GdkScreen    *screen,
               GdkRectangle *area)
{
  GdkX11Screen   *x11_screen = GDK_X11_SCREEN (screen);
  Atom            workarea;
  Atom            type;
  Window          win;
  int             format;
  gulong          num;
  gulong          leftovers;
  gulong          max_len = 4 * 32;
  guchar         *ret_workarea = NULL;
  long           *workareas;
  int             result;
  int             disp_screen;
  int             desktop;
  Display        *display;

  display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen));
  disp_screen = GDK_SCREEN_XNUMBER (screen);
  workarea = XInternAtom (display, "_NET_WORKAREA", True);

  /* Defaults in case of error */
  area->x = 0;
  area->y = 0;
  area->width = gdk_screen_get_width (screen) / x11_screen->window_scale;
  area->height = gdk_screen_get_height (screen) / x11_screen->window_scale;

  if (!gdk_x11_screen_supports_net_wm_hint (screen,
                                            gdk_atom_intern_static_string ("_NET_WORKAREA")))
    return;

  if (workarea == None)
    return;

  win = XRootWindow (display, disp_screen);
  result = XGetWindowProperty (display,
                               win,
                               workarea,
                               0,
                               max_len,
                               False,
                               AnyPropertyType,
                               &type,
                               &format,
                               &num,
                               &leftovers,
                               &ret_workarea);
  if (result != Success ||
      type == None ||
      format == 0 ||
      leftovers ||
      num % 4 != 0)
    goto out;

  desktop = get_current_desktop (screen);
  if (desktop + 1 > num / 4) /* fvwm gets this wrong */
    goto out;

  workareas = (long *) ret_workarea;
  area->x = workareas[desktop * 4];
  area->y = workareas[desktop * 4 + 1];
  area->width = workareas[desktop * 4 + 2];
  area->height = workareas[desktop * 4 + 3];

  area->x /= x11_screen->window_scale;
  area->y /= x11_screen->window_scale;
  area->width /= x11_screen->window_scale;
  area->height /= x11_screen->window_scale;

out:
  if (ret_workarea)
    XFree (ret_workarea);
}
Пример #19
0
static void
event_clientmessageevent(XEvent *e)
{
     XClientMessageEvent *ev = &e->xclient;
     struct client *c;
     struct _systray *sy;
     int type = 0;

     while(type < net_last && W->net_atom[type] != ev->message_type)
          ++type;

     /*
      * Systray message
      * _NET_WM_SYSTRAY_TRAY_OPCODE
      */
     if(ev->window == W->systray.win && type == net_system_tray_opcode)
     {
          if(ev->data.l[1] == XEMBED_EMBEDDED_NOTIFY)
          {
               systray_add(ev->data.l[2]);
               systray_update();
          }
          else if(ev->data.l[1] == XEMBED_REQUEST_FOCUS)
          {
               if((sy = systray_find(ev->data.l[2])))
                    ewmh_send_message(sy->win, sy->win, "_XEMBED", XEMBED_FOCUS_IN,
                                      XEMBED_FOCUS_CURRENT, 0, 0, 0);
          }
     }
     else if(ev->window == W->root)
     {
          /* WMFS message */
          if(ev->data.l[4])
          {
               /* Manage _WMFS_FUNCTION && _WMFS_CMD */
               if(type == wmfs_function || type == wmfs_cmd)
               {
                    Atom rt;
                    int d;
                    long unsigned int len, il;
                    unsigned char *ret = NULL, *ret_cmd = NULL;
                    void (*func)(Uicb);

                    if(XGetWindowProperty(EVDPY(e), W->root, W->net_atom[wmfs_function], 0, 65536,
                                          False, W->net_atom[utf8_string], &rt, &d,
                                          &len, &il, &ret) == Success
                       && ret && ((func = uicb_name_func((char*)ret))))
                    {
                         if(XGetWindowProperty(EVDPY(e), W->root, W->net_atom[wmfs_cmd], 0, 65536,
                                               False, W->net_atom[utf8_string], &rt, &d,
                                               &len, &il, &ret_cmd) == Success
                            && len && ret_cmd)
                         {
                              func((Uicb)ret_cmd);
                              XFree(ret_cmd);
                         }
                         else
                              func(NULL);

                         XFree(ret);
                    }
               }
          }

          if(type == net_active_window)
               if((sy = systray_find(ev->data.l[0])))
                    XSetInputFocus(W->dpy, sy->win, RevertToNone, CurrentTime);
     }

     switch(type)
     {
          /* _NET_WM_STATE */
          case net_wm_state:
               if((c = client_gb_win(ev->window)))
                    ewmh_manage_state(ev->data.l, c);
               break;
          /* _NET_CLOSE_WINDOW */
          case net_close_window:
               if((c = client_gb_win(ev->window)))
                    client_close(c);
               break;
          /* _NET_WM_DESKTOP */
          case net_wm_desktop:
               break;
     }
}
Пример #20
0
char *osd_get_clipboard_text(void)
{
	SDL_SysWMinfo info;
	Display* display;
	Window our_win;
	Window selection_win;
	Atom data_type;
	int data_format;
	unsigned long nitems;
	unsigned long bytes_remaining;
	unsigned char* prop;
	char* result;
	XEvent event;
	Uint32 t0, t1;
	Atom types[2];
	int i;

	/* get & validate SDL sys-wm info */
	SDL_VERSION(&info.version);
	if ( ! SDL_GetWMInfo( &info ) )
		return NULL;
	if ( info.subsystem != SDL_SYSWM_X11 )
		return NULL;
	if ( (display = info.info.x11.display) == NULL )
		return NULL;
	if ( (our_win = info.info.x11.window) == None )
		return NULL;

	/* request data to owner */
	selection_win = XGetSelectionOwner( display, XA_PRIMARY );
	if ( selection_win == None )
		return NULL;

	/* first, try UTF-8, then latin-1 */
	types[0] = XInternAtom( display, "UTF8_STRING", False );
	types[1] = XA_STRING; /* latin-1 */

	for ( i = 0; i < ARRAY_LENGTH(types); i++ )
	{
		XConvertSelection( display, XA_PRIMARY, types[i], types[i], our_win, CurrentTime );

		/* wait for SelectionNotify, but no more than 100 ms */
		t0 = t1 = SDL_GetTicks();
		while ( 1 )
		{
			if (  XCheckTypedWindowEvent( display, our_win,  SelectionNotify, &event ) ) break;
			SDL_Delay( 1 );
			t1 = SDL_GetTicks();
			if ( t1 - t0 > 100 )
				return NULL;
		}
		if ( event.xselection.property == None )
			continue;

		/* get property & check its type */
		if ( XGetWindowProperty( display, our_win, types[i], 0, 65536, False, types[i],
						&data_type, &data_format, &nitems, &bytes_remaining, &prop )
				!= Success )
			continue;
		if ( ! prop )
			continue;
		if ( (data_format != 8) || (data_type != types[i]) )
		{
			XFree( prop );
			continue;
		}

		/* return a copy & free original */
		if (prop != NULL)
		{
			result = (char *) osd_malloc_array(strlen((char *)prop)+1);
			strcpy(result, (char *)prop);
		}
		else
			result = NULL;
		XFree( prop );
		return result;
	}

	return NULL;
}
Пример #21
0
/* Retrieves the contents of a selections. Arguments are:
 *
 * A display that has been opened.
 * A window
 * An event to process
 * The selection to return
 * The target(UTF8_STRING or XA_STRING) to return 
 * A pointer to a char array to put the selection into.
 * A pointer to a long to record the length of the char array
 * A pointer to an int to record the context in which to process the event
 * Returns ONE if retrieval of selection data is complete, or ZERO otherwise.
 */
static int xcout(Display*dpy, Window win, XEvent evt, Atom sel, Atom trg, uchar**txt, ulong*len, uint*ctx)
{
    static Atom prop; /* for other windows to put their selection into */
    static Atom inc;
    Atom prop_type;
    Atom atomUTF8String;
    int prop_fmt;
    uchar *buffer;  /* buffer for XGetWindowProperty to dump data into */
    ulong prop_size;
    ulong prop_items;
    uchar *ltxt = *txt;   /* local buffer of text to return */

    if (!prop) { prop = XInternAtom(dpy, "XCLIP_OUT", False); }
    if (!inc) { inc = XInternAtom(dpy, "INCR", False); }

    switch (*ctx) {
      case XCLIB_XCOUT_NONE: { /* there is no context, do an XConvertSelection() */
        if (*len > 0) {   /* initialise return length to 0 */
          free(*txt);
          *len = 0;
        }
        XConvertSelection(dpy, sel, trg, prop, win, CurrentTime);   /* send selection request */
        *ctx = XCLIB_XCOUT_SENTCONVSEL;
        return (0);
      }
      case XCLIB_XCOUT_SENTCONVSEL: {
        atomUTF8String = XInternAtom(dpy, "UTF8_STRING", False);
        if (evt.type != SelectionNotify)
            return (0);

        /* fallback to XA_STRING when UTF8_STRING failed */
        if (trg == atomUTF8String && evt.xselection.property == None) {
            *ctx = XCLIB_XCOUT_FALLBACK;
            return (0);
        }

        /* find the size and format of the data in property */
        XGetWindowProperty( dpy, win, prop, 0, 0, False, AnyPropertyType, 
                              &prop_type, &prop_fmt, &prop_items, &prop_size, &buffer );
        XFree(buffer);

        if (prop_type == inc) {
          XDeleteProperty(dpy, win, prop);  /* start INCR mechanism by deleting property */
          XFlush(dpy);
          *ctx = XCLIB_XCOUT_INCR;
          return (0);
        }

        /* if not incr, and not format == 8, it's nothing we understand anyway. */
        if (prop_fmt != 8) {
          *ctx = XCLIB_XCOUT_NONE;
          return (0);
        }

        /* not using INCR mechanism, just read the property */
        XGetWindowProperty( dpy, win, prop, 0, (long) prop_size, False, AnyPropertyType,
                              &prop_type, &prop_fmt, &prop_items, &prop_size, &buffer );

        /* finished with property, delete it */
        XDeleteProperty(dpy, win, prop);

        /* copy the buffer to the pointer for returned data */
        ltxt = (uchar*) malloc(prop_items);
        memcpy(ltxt, buffer, prop_items);

        /* set the length of the returned data */
        *len = prop_items;
        *txt = ltxt;

        /* free the buffer */
        XFree(buffer);

        *ctx = XCLIB_XCOUT_NONE;

        /* complete contents of selection fetched, return 1 */
        return (1);
      }
      case XCLIB_XCOUT_INCR: {
        /* To use the INCR method, we delete the property with the selection in it, 
           wait for an event indicating that the property has been created,
           then read it, delete it, etc. */

        if (evt.type != PropertyNotify) { return (0); }
        if (evt.xproperty.state != PropertyNewValue) { return (0); }

        /* check size and format of the property */
        XGetWindowProperty( dpy, win, prop, 0, 0, False, AnyPropertyType,
                              &prop_type, &prop_fmt, &prop_items, &prop_size, &buffer );

        if (prop_fmt != 8) {
          /* property is not text, deleting tells other client to send next property */
          XFree(buffer);
          XDeleteProperty(dpy, win, prop);
          return (0);
        }

        if (prop_size == 0) { /* no more data, exit from loop */
          XFree(buffer);
          XDeleteProperty(dpy, win, prop);
          *ctx = XCLIB_XCOUT_NONE;
          return (1); /* INCR transfer completed */
        }
        XFree(buffer);

        /* if we have come this far, the propery contains text, and we know the size. */
        XGetWindowProperty( dpy, win, prop, 0, (long) prop_size, False, AnyPropertyType,
                              &prop_type, &prop_fmt, &prop_items, &prop_size, &buffer );
         /* allocate memory to accommodate data in *txt */
        if (*len == 0) {
          *len = prop_items;
          ltxt = (uchar*) malloc(*len);
        } else {
          *len += prop_items;
          ltxt = (uchar*) realloc(ltxt, *len);
        }
        memcpy(&ltxt[*len - prop_items], buffer, prop_items); /* add data to ltxt */

        *txt = ltxt;
        XFree(buffer);
        XDeleteProperty(dpy, win, prop); /* delete property to get the next item */
        XFlush(dpy);
        return (0);
      }
    }
    return (0);
}
Пример #22
0
NS_IMETHODIMP
compzillaWindow::GetProperty (PRUint32 iprop, nsIPropertyBag2 **bag2)
{
    *bag2 = nsnull;

    Atom prop = (Atom)iprop;

    nsISupports *bag;
    nsCOMPtr<nsIWritablePropertyBag2> wbag;
    nsCOMPtr<nsIPropertyBag2> rbag;

    nsresult rv = CallCreateInstance("@mozilla.org/hash-property-bag;1", &bag);
    if (NS_FAILED(rv)) {
        return rv;
    }
 
    wbag = do_QueryInterface (bag);
    rbag = do_QueryInterface (bag);

#define SET_BAG() do { \
    NS_ADDREF (rbag); \
    *bag2 = rbag; \
} while (0)

#define SET_PROP(_bag, _type, _key, _val) \
    (_bag)->SetPropertyAs##_type (NS_LITERAL_STRING (_key), _val)

    switch (prop) {
        // ICCCM properties

    case XA_WM_NAME:
    case XA_WM_ICON_NAME: {
        // XXX this is missing some massaging, since the WM_NAME
        // property isn't in utf8, but in some locale character set
        // (latin1?  who knows).  Check the gtk+ source on how to
        // handle this.
        nsCAutoString str;
        if (NS_OK == GetUTF8StringProperty (prop, str)) {
            SET_BAG ();
            SET_PROP(wbag, AUTF8String, "text", str);
        }
        break;
    }

    case XA_WM_HINTS: {
        XWMHints *wmHints;

        wmHints = XGetWMHints (mDisplay, mWindow);

        if (wmHints) {
            SET_BAG ();
            SET_PROP(wbag, Int32, "wmHints.flags", wmHints->flags);
            SET_PROP(wbag, Bool, "wmHints.input", wmHints->input);
            SET_PROP(wbag, Int32, "wmHints.initialState", wmHints->initial_state);
            SET_PROP(wbag, Uint32, "wmHints.iconPixmap", wmHints->icon_pixmap);
            SET_PROP(wbag, Uint32, "wmHints.iconWindow", wmHints->icon_window);
            SET_PROP(wbag, Int32, "wmHints.iconX", wmHints->icon_x);
            SET_PROP(wbag, Int32, "wmHints.iconY", wmHints->icon_y);
            SET_PROP(wbag, Uint32, "wmHints.iconMask", wmHints->icon_mask);
            SET_PROP(wbag, Uint32, "wmHints.windowGroup", wmHints->window_group);

            XFree (wmHints);
        }
        break;
    }

    case XA_WM_NORMAL_HINTS: {
        XSizeHints sizeHints;
        long supplied;

        // XXX check return value
        XGetWMNormalHints (mDisplay, mWindow, &sizeHints, &supplied);

        SET_BAG ();

        SET_PROP(wbag, Int32, "sizeHints.flags", sizeHints.flags);

        SET_PROP(wbag, Int32, "sizeHints.x", sizeHints.x);
        SET_PROP(wbag, Int32, "sizeHints.y", sizeHints.y);
        SET_PROP(wbag, Int32, "sizeHints.width", sizeHints.width);
        SET_PROP(wbag, Int32, "sizeHints.height", sizeHints.height);

        SET_PROP(wbag, Int32, "sizeHints.minWidth", sizeHints.min_width);
        SET_PROP(wbag, Int32, "sizeHints.minHeight", sizeHints.min_height);

        SET_PROP(wbag, Int32, "sizeHints.maxWidth", sizeHints.max_width);
        SET_PROP(wbag, Int32, "sizeHints.maxHeight", sizeHints.max_height);

        SET_PROP(wbag, Int32, "sizeHints.widthInc", sizeHints.width_inc);
        SET_PROP(wbag, Int32, "sizeHints.heightInc", sizeHints.height_inc);

        SET_PROP(wbag, Int32, "sizeHints.minAspect.x", sizeHints.min_aspect.x);
        SET_PROP(wbag, Int32, "sizeHints.minAspect.y", sizeHints.min_aspect.y);

        SET_PROP(wbag, Int32, "sizeHints.maxAspect.x", sizeHints.max_aspect.x);
        SET_PROP(wbag, Int32, "sizeHints.maxAspect.y", sizeHints.max_aspect.y);

        if ((supplied & (PBaseSize|PWinGravity)) != 0) {
            SET_PROP(wbag, Int32, "sizeHints.baseWidth", sizeHints.base_width);
            SET_PROP(wbag, Int32, "sizeHints.baseHeight", sizeHints.base_height);

            SET_PROP(wbag, Int32, "sizeHints.winGravity", sizeHints.win_gravity);
        }
        break;
    }
    case XA_WM_CLASS: {
        // 2 strings, separated by a \0

        char *instance, *_class;

        Atom actual_type;
        int format;
        unsigned long nitems;
        unsigned long bytes_after_return;
        unsigned char *data;

        XGetWindowProperty (mDisplay, mWindow, (Atom)prop,
                            0, BUFSIZ, false, XA_STRING,
                            &actual_type, &format, &nitems, &bytes_after_return, 
                            &data);

        instance = (char*)data;
        _class = instance + strlen (instance) + 1;

        SET_BAG ();
        SET_PROP (wbag, ACString, "instanceName", nsCAutoString (instance));
        SET_PROP (wbag, ACString, "className", nsCAutoString (_class));

        XFree (data);

        break;
    }
    case XA_WM_TRANSIENT_FOR: {
        // the parent X window's canvas element
        break;
    }
    case XA_WM_CLIENT_MACHINE: {
        nsCAutoString str;
        if (NS_OK == GetUTF8StringProperty (prop, str)) {
            SET_BAG ();
            SET_PROP(wbag, AUTF8String, "text", str);
        }
    }
    default:
        // ICCCM properties which don't have predefined atoms

        if (prop == atoms.x.WM_COLORMAP_WINDOWS) {
            // if we ever support this, shoot me..
        }
        else if (prop == atoms.x.WM_PROTOCOLS) {
            // an array of Atoms.
        }

        // non - ICCCM properties go here

        // EWMH properties

        else if (prop == atoms.x._NET_WM_NAME
                 || prop == atoms.x._NET_WM_VISIBLE_NAME
                 || prop == atoms.x._NET_WM_ICON_NAME
                 || prop == atoms.x._NET_WM_VISIBLE_ICON_NAME) {
            // utf8 encoded string
            nsCAutoString str;
            if (NS_OK == GetUTF8StringProperty (prop, str)) {
                SET_BAG ();
                SET_PROP(wbag, AUTF8String, "text", str);
            }
        }
        else if (prop == atoms.x._NET_WM_DESKTOP) {
        }
        else if (prop == atoms.x._NET_WM_WINDOW_TYPE) {
            // XXX _NET_WM_WINDOW_TYPE is actually an array of atoms, not just 1.
            // this also needs fixing in the JS.
            PRUint32 atom;
            if (NS_OK == GetAtomProperty (prop, &atom)) {
                SET_BAG ();
                SET_PROP(wbag, Uint32, "atom", atom);
            }
        }
        else if (prop == atoms.x._NET_WM_STATE) {
        }
        else if (prop == atoms.x._NET_WM_ALLOWED_ACTIONS) {
        }
        else if (prop == atoms.x._NET_WM_STRUT) {
            PRUint32 *cards;
            PRUint32 nitems;

            if (NS_OK == GetCardinalListProperty (prop, &cards, 4)) {
                SET_BAG ();
                SET_PROP (wbag, Uint32, "left", cards[0]);
                SET_PROP (wbag, Uint32, "right", cards[1]);
                SET_PROP (wbag, Uint32, "top", cards[2]);
                SET_PROP (wbag, Uint32, "bottom", cards[3]);
            
                XFree (cards);
            }
        }
        else if (prop == atoms.x._NET_WM_STRUT_PARTIAL) {
            PRUint32 *cards;
            PRUint32 nitems;

            if (NS_OK == GetCardinalListProperty (prop, &cards, 12)) {
                SET_BAG ();
                SET_PROP (wbag, Bool, "partial", true);

                SET_PROP (wbag, Uint32, "left", cards[0]);
                SET_PROP (wbag, Uint32, "right", cards[1]);
                SET_PROP (wbag, Uint32, "top", cards[2]);
                SET_PROP (wbag, Uint32, "bottom", cards[3]);

                SET_PROP (wbag, Uint32, "leftStartY", cards[4]);
                SET_PROP (wbag, Uint32, "leftEndY", cards[5]);
                SET_PROP (wbag, Uint32, "rightStartY", cards[6]);
                SET_PROP (wbag, Uint32, "rightEndY", cards[7]);

                SET_PROP (wbag, Uint32, "topStartX", cards[8]);
                SET_PROP (wbag, Uint32, "topEndX", cards[9]);
                SET_PROP (wbag, Uint32, "bottomStartX", cards[10]);
                SET_PROP (wbag, Uint32, "bottomEndX", cards[11]);
                
                XFree (cards);
            }
        }
        else if (prop == atoms.x._NET_WM_ICON_GEOMETRY) {
            PRUint32 *cards;
            PRUint32 nitems;

            if (NS_OK == GetCardinalListProperty (prop, &cards, 4)) {
                SET_BAG ();
                SET_PROP (wbag, Bool, "partial", false);
                SET_PROP(wbag, Uint32, "x", cards[0]);
                SET_PROP(wbag, Uint32, "y", cards[1]);
                SET_PROP(wbag, Uint32, "width", cards[2]);
                SET_PROP(wbag, Uint32, "height", cards[3]);
                XFree (cards);
            }
        }
        else if (prop == atoms.x._NET_WM_ICON) {
            Atom actual_type;
            int format;
            unsigned long nitems;
            unsigned long bytes_after_return;
            unsigned char *data;
            
            if (XGetWindowProperty (mDisplay, mWindow, prop,
                                    0, BUFSIZ, false, XA_CARDINAL,
                                    &actual_type, &format, &nitems, &bytes_after_return, 
                                    &data) == Success) {
                nsCAutoString dataStr;
                dataStr.Assign ((char *) data, (format / 8) * nitems);

                SET_BAG ();
                SET_PROP(wbag, ACString, "data", dataStr);
                XFree (data);
            }
        }
        else if (prop == atoms.x._NET_WM_PID) {
        }
        else if (prop == atoms.x._NET_WM_HANDLED_ICONS) {
        }
        else if (prop == atoms.x._NET_WM_USER_TIME) {
        }
        else if (prop == atoms.x._NET_FRAME_EXTENTS) {
        }

        break;
    }

#undef SET_PROP
#undef SET_BAG

    return NS_OK;
}
Пример #23
0
const QRect XfitMan::availableGeometry(int screen) const
{
    QDesktopWidget *d = QApplication::desktop();

    if (screen < 0 || screen >= d->screenCount())
        screen = d->primaryScreen();

    QRect available = d->screenGeometry(screen);

    // Iterate over all the client windows and subtract from the available
    // area the space they reserved on the edges (struts).
    // Note: _NET_WORKAREA is not reliable as it exposes only one
    // rectangular area spanning all screens.
    Display *display = QX11Info::display();
    int x11Screen = d->isVirtualDesktop() ? DefaultScreen(display) : screen;

    Atom ret;
    int format, status;
    uchar* data = 0;
    ulong nitems, after;

    status = XGetWindowProperty(display, QX11Info::appRootWindow(x11Screen),
                                atom("_NET_CLIENT_LIST"), 0L, ~0L, False, XA_WINDOW,
                                &ret, &format, &nitems, &after, &data);

    if (status == Success && ret == XA_WINDOW && format == 32 && nitems)
    {
        const QRect desktopGeometry = d->rect();

        Window* xids = (Window*) data;
        for (quint32 i = 0; i < nitems; ++i)
        {
            ulong nitems2;
            uchar* data2 = 0;
            status = XGetWindowProperty(display, xids[i],
                                        atom("_NET_WM_STRUT_PARTIAL"), 0, 12, False, XA_CARDINAL,
                                        &ret, &format, &nitems2, &after, &data2);

            if (status == Success && ret == XA_CARDINAL && format == 32 && nitems2 == 12)
            {
                ulong* struts = (ulong*) data2;

                QRect left(desktopGeometry.x(),
                           desktopGeometry.y() + struts[4],
                           struts[0],
                           struts[5] - struts[4]);
                if (available.intersects(left))
                    available.setX(left.width());

                QRect right(desktopGeometry.x() + desktopGeometry.width() - struts[1],
                            desktopGeometry.y() + struts[6],
                            struts[1],
                            struts[7] - struts[6]);
                if (available.intersects(right))
                    available.setWidth(right.x() - available.x());

                QRect top(desktopGeometry.x() + struts[8],
                          desktopGeometry.y(),
                          struts[9] - struts[8],
                          struts[2]);
                if (available.intersects(top))
                    available.setY(top.height());

                QRect bottom(desktopGeometry.x() + struts[10],
                             desktopGeometry.y() + desktopGeometry.height() - struts[3],
                             struts[11] - struts[10],
                             struts[3]);
                if (available.intersects(bottom))
                    available.setHeight(bottom.y() - available.y());
            }
            if (data2)
                XFree(data2);
        }
    }
    if (data)
        XFree(data);

    return available;
}
Пример #24
0
static int SetXi18nSelectionOwner(Xi18n i18n_core)
{
    Display *dpy = i18n_core->address.dpy;
    Window ims_win = i18n_core->address.im_window;
    Window root = RootWindow (dpy, DefaultScreen (dpy));
    Atom realtype;
    int realformat;
    unsigned long bytesafter;
    long *data=NULL;
    unsigned long length;
    Atom atom;
    int i;
    int found;
    int forse = False;
    char buf[256];

    (void)sprintf(buf, "@server=%s", i18n_core->address.im_name);
    if ((atom = XInternAtom(dpy, buf, False)) == 0)
        return False;
    i18n_core->address.selection = atom;

    if (XIM_Servers == None)
        XIM_Servers = XInternAtom (dpy, XIM_SERVERS, False);
    /*endif*/
    XGetWindowProperty (dpy,
                        root,
                        XIM_Servers,
                        0L,
                        1000000L,
                        False,
                        XA_ATOM,
                        &realtype,
                        &realformat,
                        &length,
                        &bytesafter,
                        (unsigned char **) (&data));
    if (realtype != None && (realtype != XA_ATOM || realformat != 32)) {
        if (data != NULL)
            XFree ((char *) data);
        return False;
    }

    found = False;
    for (i = 0; i < length; i++) {
        if (data[i] == atom) {
            Window owner;
            found = True;
            if ((owner = XGetSelectionOwner (dpy, atom)) != ims_win) {
                if (owner == None  ||  forse == True)
                    XSetSelectionOwner (dpy, atom, ims_win, CurrentTime);
                else
                    return False;
            }
            break;
        }
    }

    if (found == False) {
        XSetSelectionOwner (dpy, atom, ims_win, CurrentTime);
        XChangeProperty (dpy,
                         root,
                         XIM_Servers,
                         XA_ATOM,
                         32,
                         PropModePrepend,
                         (unsigned char *) &atom,
                         1);
    }
    else {
	/* 
	 * We always need to generate the PropertyNotify to the Root Window 
	 */
        XChangeProperty (dpy,
                         root,
                         XIM_Servers,
                         XA_ATOM,
                         32,
                         PropModePrepend,
                         (unsigned char *) data,
                         0);
    }
    if (data != NULL)
        XFree ((char *) data);
    
    /* Intern "LOCALES" and "TRANSOPORT" Target Atoms */
    i18n_core->address.Localename = XInternAtom (dpy, LOCALES, False);
    i18n_core->address.Transportname = XInternAtom (dpy, TRANSPORT, False);
    return (XGetSelectionOwner (dpy, atom) == ims_win);
}
Пример #25
0
bool CWinSystemX11::HasWindowManager()
{
  Window wm_check;
  unsigned char *data;
  int status, real_format;
  Atom real_type, prop;
  unsigned long items_read, items_left;

  prop = XInternAtom(m_dpy, "_NET_SUPPORTING_WM_CHECK", True);
  if (prop == None)
    return false;
  status = XGetWindowProperty(m_dpy, DefaultRootWindow(m_dpy), prop,
                      0L, 1L, False, XA_WINDOW, &real_type, &real_format,
                      &items_read, &items_left, &data);
  if(status != Success || ! items_read)
  {
    if(status == Success)
      XFree(data);
    return false;
  }

  wm_check = ((Window*)data)[0];
  XFree(data);

  status = XGetWindowProperty(m_dpy, wm_check, prop,
                      0L, 1L, False, XA_WINDOW, &real_type, &real_format,
                      &items_read, &items_left, &data);

  if(status != Success || !items_read)
  {
    if(status == Success)
      XFree(data);
    return false;
  }

  if(wm_check != ((Window*)data)[0])
  {
    XFree(data);
    return false;
  }

  XFree(data);

  prop = XInternAtom(m_dpy, "_NET_WM_NAME", True);
  if (prop == None)
  {
    CLog::Log(LOGDEBUG,"Window Manager Name: ");
    return true;
  }

  status = XGetWindowProperty(m_dpy, wm_check, prop,
                        0L, (~0L), False, AnyPropertyType, &real_type, &real_format,
                        &items_read, &items_left, &data);

  if(status == Success && items_read)
  {
    CLog::Log(LOGDEBUG,"Window Manager Name: %s", data);
  }
  else
    CLog::Log(LOGDEBUG,"Window Manager Name: ");

  if(status == Success)
    XFree(data);

  return true;
}
Пример #26
0
static int DeleteXi18nAtom(Xi18n i18n_core)
{
    Display *dpy = i18n_core->address.dpy;
    Window root = RootWindow (dpy, DefaultScreen (dpy));
    Atom realtype;
    int realformat;
    unsigned long bytesafter;
    long *data=NULL;
    unsigned long length;
    Atom atom;
    int i, ret;
    int found;
    char buf[256];

    (void)sprintf(buf, "@server=%s", i18n_core->address.im_name);
    if ((atom = XInternAtom(dpy, buf, False)) == 0)
        return False;
    i18n_core->address.selection = atom;

    if (XIM_Servers == None)
        XIM_Servers = XInternAtom (dpy, XIM_SERVERS, False);
    XGetWindowProperty (dpy,
                        root,
                        XIM_Servers,
                        0L,
                        1000000L,
                        False,
                        XA_ATOM,
                        &realtype,
                        &realformat,
                        &length,
                        &bytesafter,
                        (unsigned char **) (&data));
    if (realtype != XA_ATOM || realformat != 32) {
        if (data != NULL)
            XFree ((char *) data);
        return False;
    }

    found = False;
    for (i = 0; i < length; i++) {
        if (data[i] == atom) {
            found = True;
            break;
        }
    }

    if (found == True) {
        for (i=i+1; i<length; i++)
            data[i-1] = data[i];
        XChangeProperty (dpy,
                         root,
                         XIM_Servers,
                         XA_ATOM,
                         32,
                         PropModeReplace,
                         (unsigned char *)data,
                         length-1);
        ret = True;
    }
    else {
        XChangeProperty (dpy,
                         root,
                         XIM_Servers,
                         XA_ATOM,
                         32,
                         PropModePrepend,
                         (unsigned char *)data,
                         0);
        ret = False;
    }
    if (data != NULL)
        XFree ((char *) data);
    return ret;
}
Пример #27
0
int GetMWMHints(Window w, MotifWmHints *mwmHints)
{
	int success;
	Atom actual_type;
	int actual_format;
	unsigned long nitems;
	unsigned long bytes_after;
	unsigned long *prop = NULL;

	/* Defaults for when not found */
	mwmHints->flags = 0;
	mwmHints->functions = 0;
	mwmHints->decorations = 0;
#ifdef FULL_MWM_DATA
	mwmHints->input_mode = 0;
	mwmHints->status = 0;
#endif

	if(MOTIF_WM_HINTS == (Atom)None) {
		MOTIF_WM_HINTS = XInternAtom(dpy, "_MOTIF_WM_HINTS", True);
	}

	success = XGetWindowProperty(
	                  dpy, w, MOTIF_WM_HINTS,
	                  0, 5,           /* long_offset, long long_length, */
	                  False,          /* Bool delete, */
	                  AnyPropertyType,/* Atom req_type */
	                  &actual_type,   /* Atom *actual_type_return, */
	                  &actual_format, /* int *actual_format_return, */
	                  &nitems,        /* unsigned long *nitems_return,  */
	                  &bytes_after,   /* unsigned long * */
	                  (unsigned char **)&prop);       /* unsigned char ** */

	if(success == Success &&
	                actual_type == MOTIF_WM_HINTS &&
	                actual_format == 32 &&
	                nitems >= 3) {
		mwmHints->flags = (int)prop[0];
		mwmHints->functions = (int)prop[1];
		mwmHints->decorations = (int)prop[2];
#ifdef FULL_MWM_DATA
		mwmHints->input_mode = (int)prop[3];
		mwmHints->status = (int)prop[4];
#endif

		if(mwmHints->flags & MWM_HINTS_FUNCTIONS) {
			if(mwmHints->functions & MWM_FUNC_ALL) {
				mwmHints->functions ^= ~0;
			}
		}
		if(mwmHints->flags & MWM_HINTS_DECORATIONS) {
			if(mwmHints->decorations & MWM_DECOR_ALL) {
				mwmHints->decorations ^= ~0;
			}
		}

		success = True;
	}
	else {
		success = False;
	}

	if(prop != NULL) {
		XFree(prop);
	}

	return success;
}
Пример #28
0
QString AutoTypePlatformX11::windowTitle(Window window, bool useBlacklist)
{
    QString title;

    Atom type;
    int format;
    unsigned long nitems;
    unsigned long after;
    unsigned char* data = Q_NULLPTR;

    // the window manager spec says we should read _NET_WM_NAME first, then fall back to WM_NAME

    int retVal = XGetWindowProperty(m_dpy, window, m_atomNetWmName, 0, 1000, false, m_atomUtf8String,
                                    &type, &format, &nitems, &after, &data);

    if ((retVal == 0) && data) {
        title = QString::fromUtf8(reinterpret_cast<char*>(data));
    }
    else {
        XTextProperty textProp;
        retVal = XGetTextProperty(m_dpy, window, &textProp, m_atomWmName);
        if ((retVal != 0) && textProp.value) {
            char** textList = Q_NULLPTR;
            int count;

            if (textProp.encoding == m_atomUtf8String) {
                title = QString::fromUtf8(reinterpret_cast<char*>(textProp.value));
            }
            else if ((XmbTextPropertyToTextList(m_dpy, &textProp, &textList, &count) == 0)
                     && textList && (count > 0)) {
                title = QString::fromLocal8Bit(textList[0]);
            }
            else if (textProp.encoding == m_atomString) {
                title = QString::fromLocal8Bit(reinterpret_cast<char*>(textProp.value));
            }

            if (textList) {
                XFreeStringList(textList);
            }
        }

        if (textProp.value) {
            XFree(textProp.value);
        }
    }

    if (data) {
        XFree(data);
    }

    if (useBlacklist && !title.isEmpty()) {
        if (window == m_rootWindow) {
            return QString();
        }

        QString className = windowClassName(window);
        if (m_classBlacklist.contains(className)) {
            return QString();
        }

        QList<Window> keepassxWindows = widgetsToX11Windows(QApplication::topLevelWidgets());
        if (keepassxWindows.contains(window)) {
            return QString();
        }
    }

    return title;
}
Пример #29
0
/*
 * Backend for f.identify and f.version: Fills in the Info array with the
 * appropriate bits for ctwm and the window specified (if any), and
 * sizes/pops up the InfoWindow.
 *
 * Notably, the bits of Info aren't written into the window during this
 * process; that happens later as a result of the expose event.
 */
static void
Identify(TwmWindow *t)
{
	int i, n, twidth, width, height;
	int x, y;
	unsigned int wwidth, wheight, bw, depth;
	Window junk;
	int px, py, dummy;
	unsigned udummy;
	unsigned char *prop;
	unsigned long nitems, bytesafter;
	Atom actual_type;
	int actual_format;
	XRectangle inc_rect;
	XRectangle logical_rect;
	char *ctopts;

	/*
	 * Include some checking we don't blow out _LINES.  We use snprintf()
	 * exclusively to avoid blowing out _SIZE.
	 *
	 * In an ideal world, we'd probably fix this to be more dynamically
	 * allocated, but this will do for now.
	 */
	n = 0;
#define CHKN do { \
                if(n > (INFO_LINES - 3)) { \
                        fprintf(stderr, "Overflowing Info[] on line %d\n", n); \
                        sprintf(Info[n++], "(overflow)"); \
                        goto info_dismiss; \
                } \
        } while(0)

	snprintf(Info[n++], INFO_SIZE, "Twm version:  %s", TwmVersion);
	CHKN;
	if(VCSRevision) {
		snprintf(Info[n++], INFO_SIZE, "VCS Revision:  %s", VCSRevision);
		CHKN;
	}

	ctopts = ctopts_string(", ");
	snprintf(Info[n++], INFO_SIZE, "Compile time options : %s", ctopts);
	free(ctopts);
	CHKN;

	Info[n++][0] = '\0';
	CHKN;

	if(t) {
		XGetGeometry(dpy, t->w, &JunkRoot, &JunkX, &JunkY,
		             &wwidth, &wheight, &bw, &depth);
		XTranslateCoordinates(dpy, t->w, Scr->Root, 0, 0,
		                      &x, &y, &junk);
		snprintf(Info[n++], INFO_SIZE, "Name               = \"%s\"",
		         t->name);
		CHKN;
		snprintf(Info[n++], INFO_SIZE, "Class.res_name     = \"%s\"",
		         t->class.res_name);
		CHKN;
		snprintf(Info[n++], INFO_SIZE, "Class.res_class    = \"%s\"",
		         t->class.res_class);
		CHKN;
		Info[n++][0] = '\0';
		CHKN;
		snprintf(Info[n++], INFO_SIZE,
		         "Geometry/root (UL) = %dx%d+%d+%d (Inner: %dx%d+%d+%d)",
		         wwidth + 2 * (bw + t->frame_bw3D),
		         wheight + 2 * (bw + t->frame_bw3D) + t->title_height,
		         x - (bw + t->frame_bw3D),
		         y - (bw + t->frame_bw3D + t->title_height),
		         wwidth, wheight, x, y);
		CHKN;
		snprintf(Info[n++], INFO_SIZE,
		         "Geometry/root (LR) = %dx%d-%d-%d (Inner: %dx%d-%d-%d)",
		         wwidth + 2 * (bw + t->frame_bw3D),
		         wheight + 2 * (bw + t->frame_bw3D) + t->title_height,
		         Scr->rootw - (x + wwidth + bw + t->frame_bw3D),
		         Scr->rooth - (y + wheight + bw + t->frame_bw3D),
		         wwidth, wheight,
		         Scr->rootw - (x + wwidth), Scr->rooth - (y + wheight));
		CHKN;
		snprintf(Info[n++], INFO_SIZE, "Border width       = %d", bw);
		CHKN;
		snprintf(Info[n++], INFO_SIZE, "3D border width    = %d", t->frame_bw3D);
		CHKN;
		snprintf(Info[n++], INFO_SIZE, "Depth              = %d", depth);
		CHKN;
		if(t->vs &&
		                t->vs->wsw &&
		                t->vs->wsw->currentwspc) {
			snprintf(Info[n++], INFO_SIZE, "Virtual Workspace  = %s",
			         t->vs->wsw->currentwspc->name);
			CHKN;
		}
		snprintf(Info[n++], INFO_SIZE, "OnTopPriority      = %d",
		         OtpEffectiveDisplayPriority(t));
		CHKN;

		if(t->icon != NULL) {
			int iwx, iwy;

			XGetGeometry(dpy, t->icon->w, &JunkRoot, &iwx, &iwy,
			             &wwidth, &wheight, &bw, &depth);
			Info[n++][0] = '\0';
			CHKN;
			snprintf(Info[n++], INFO_SIZE, "IconGeom/root     = %dx%d+%d+%d",
			         wwidth, wheight, iwx, iwy);
			CHKN;
			snprintf(Info[n++], INFO_SIZE, "IconGeom/intern   = %dx%d+%d+%d",
			         t->icon->w_width, t->icon->w_height,
			         t->icon->w_x, t->icon->w_y);
			CHKN;
			snprintf(Info[n++], INFO_SIZE, "IconBorder width  = %d", bw);
			CHKN;
			snprintf(Info[n++], INFO_SIZE, "IconDepth         = %d", depth);
			CHKN;
		}

		if(XGetWindowProperty(dpy, t->w, XA_WM_CLIENT_MACHINE, 0L, 64, False,
		                      XA_STRING, &actual_type, &actual_format, &nitems,
		                      &bytesafter, &prop) == Success) {
			if(nitems && prop) {
				snprintf(Info[n++], INFO_SIZE, "Client machine     = %s",
				         (char *)prop);
				XFree(prop);
				CHKN;
			}
		}
		Info[n++][0] = '\0';
		CHKN;
	}

#undef CHKN
info_dismiss:
	snprintf(Info[n++], INFO_SIZE, "Click to dismiss....");


	/*
	 * OK, it's all built now.
	 */

	/* figure out the width and height of the info window */
	height = n * (Scr->DefaultFont.height + 2);
	width = 1;
	for(i = 0; i < n; i++) {
		XmbTextExtents(Scr->DefaultFont.font_set, Info[i],
		               strlen(Info[i]), &inc_rect, &logical_rect);

		twidth = logical_rect.width;
		if(twidth > width) {
			width = twidth;
		}
	}

	/* Unmap if it's currently up, while we muck with it */
	if(Scr->InfoWindow.mapped) {
		XUnmapWindow(dpy, Scr->InfoWindow.win);
		/* Don't really need to bother since we're about to reset, but...  */
		Scr->InfoWindow.mapped = false;
	}

	/* Stash the new number of lines */
	Scr->InfoWindow.lines = n;

	width += 10;                /* some padding */
	height += 10;               /* some padding */
	if(XQueryPointer(dpy, Scr->Root, &JunkRoot, &JunkChild,
	                 &dummy, &dummy, &px, &py, &udummy)) {
		px -= width / 2;
		py -= height / 3;
	}
	else {
		px = py = 0;
	}

	{
		RArea area = RAreaNew(px, py, width, height);
		int min_x, min_y, max_bottom, max_right;

		RLayoutFindLeftRightEdges(Scr->Layout, &area, &min_x, &max_right);
		if(px < min_x) {
			px = min_x;
		}
		else if(px + width - 1 > max_right) {
			px = max_right - width + 1;
		}

		RLayoutFindTopBottomEdges(Scr->Layout, &area, &min_y, &max_bottom);
		if(py < min_y) {
			py = min_y;
		}
		else if(py + height - 1 > max_bottom) {
			py = max_bottom - height + 1;
		}
	}
	XMoveResizeWindow(dpy, Scr->InfoWindow.win, px, py, width, height);
	XMapRaised(dpy, Scr->InfoWindow.win);
	Scr->InfoWindow.mapped = true;
	Scr->InfoWindow.width  = width;
	Scr->InfoWindow.height = height;
}
Пример #30
0
void getwindowproperties(Display *display, Window window, char **process, char **title)
{
   Atom pid_atom, name1_atom, name2_atom, class_atom;
   Atom type;
   int format;
   unsigned long nitems, after;
   unsigned char *data = NULL;
   pid_t pid = 0;
   char *name1 = NULL, *name2 = NULL, *class = NULL;
   Window parent = 0, root = 0;
   Window *children = NULL;
   unsigned int nchildren;

   do {
      pid_atom = XInternAtom(display, SO"_NET_WM_PID", True);
      if((pid_atom == BadAlloc) || (pid_atom == BadValue)) break;
      name1_atom = XInternAtom(display, SO"_NET_WM_NAME", True);
      if((name1_atom == BadAlloc) || (name1_atom == BadValue)) break;
      name2_atom = XInternAtom(display, SO"WM_NAME", True);
      if((name2_atom == BadAlloc) || (name2_atom == BadValue)) break;
      class_atom = XInternAtom(display, SO"WM_CLASS", True);
      if((class_atom == BadAlloc) || (class_atom == BadValue)) break;

      while(window && (window != root)) {
         if(!pid) {
            XGetWindowProperty(display, window, pid_atom, 0, 1, False, AnyPropertyType, &type, &format, &nitems, &after, &data);
            if(data) {
               pid = *(pid_t *)data;
               XFree(data);
            }
         }

         if(!name1) {
            XGetWindowProperty(display, window, name1_atom, 0, 256, False, AnyPropertyType, &type, &format, &nitems, &after, &data);
            if(data) {
               name1 = strdup((char *)data);
               XFree(data);
            }
         }

         if(!name2 && !name1) {
            XGetWindowProperty(display, window, name2_atom, 0, 256, False, AnyPropertyType, &type, &format, &nitems, &after, &data);
            if(data) {
               name2 = strdup((char *)data);
               XFree(data);
            }
         }

         if(!class) {
            XGetWindowProperty(display, window, class_atom, 0, 16, False, AnyPropertyType, &type, &format, &nitems, &after, &data);
            if(data) {
               class = strdup((char *)((unsigned long)strchr((char *)data, '\0') + 1));
               XFree(data);
            }
         }

         if(pid && name1 && class) break;

         if(!XQueryTree(display, window, &root, &parent, &children, &nchildren)) break;
         if(children) {
            XFree(children);
            children = NULL;
         }

         window = parent;
      }

      asprintf(process, "%s (%u)", class ? class : SO"Unknown", pid ? pid : 0);
      *title = strdup(name1 ? name1 : (name2 ? name2 : ""));
   } while(0); 

   if(name1) free(name1);
   if(name2) free(name2);
   if(class) free(class);

   return;
}