void EffectHunter::collectFPS()
{
    long    fpsSum = 0;
    bool    firstDamageFlag = true;

    XDamageCreate(mXWindowDisplay, mWinId, XDamageReportRawRectangles);

    int damageEvt, damageErr;
    if (!XDamageQueryExtension (mXWindowDisplay, &damageEvt, &damageErr)){
        std::cerr << "not support damage\n";
        exit(-1);
    }
    
    XEvent e;

    if (mMode == SAMPLE_FPS) {
        struct itimerval itVal;
        itVal.it_interval.tv_sec = 1;
        itVal.it_interval.tv_usec = 0;
        itVal.it_value.tv_sec = 1;
        itVal.it_value.tv_usec = 0;
        setitimer(ITIMER_REAL, &itVal, NULL);

        XSync(mXWindowDisplay, true);

        while (!mTermFlag) {
            XNextEvent(mXWindowDisplay, &e);
            if (e.type == (damageEvt + XDamageNotify)) {
                //printEvent(&e);
                mFPS++;
            }
        }

        itVal.it_interval.tv_sec = 0;
        itVal.it_interval.tv_usec = 0;
        itVal.it_value.tv_sec = 0;
        itVal.it_value.tv_usec = 0;
        setitimer(ITIMER_REAL, &itVal, NULL);;   
 
        std::cout << " [Info]: Sampling finished." << std::endl; 
        for(int i=0; i<mSampleCount; i++) {
            fpsSum += mFPSs[i];
        }
        std::cout << " [Info]: Average FPS - " << (double)fpsSum/mSampleCount << std::endl;
    } else if (mMode == SAMPLE_TIMESTAMP) {
        XSync(mXWindowDisplay, true);
        while (!mTermFlag) {
            XNextEvent(mXWindowDisplay, &e);
            if (e.type == (damageEvt + XDamageNotify)) {
                //printEvent(&e);
                gettimeofday(mLastXDamageEventTimeStamp, NULL);
                if (firstDamageFlag) {
                    mFirstXDamageEventTimeStamp->tv_sec = mLastXDamageEventTimeStamp->tv_sec;
                    mFirstXDamageEventTimeStamp->tv_usec = mLastXDamageEventTimeStamp->tv_usec;
                    firstDamageFlag = false;
                }
            }
        }
    }
}
Ejemplo n.º 2
0
CompositeWindow::CompositeWindow (CompWindow *w) :
    PluginClassHandler<CompositeWindow, CompWindow, COMPIZ_COMPOSITE_ABI> (w),
    priv (new PrivateCompositeWindow (w, this))
{
    CompScreen *s = screen;

    if (w->windowClass () != InputOnly)
    {
	priv->damage = XDamageCreate (s->dpy (), w->id (),
				      XDamageReportBoundingBox);
    }
    else
    {
	priv->damage = None;
    }

    priv->opacity = OPAQUE;
    if (!(w->type () & CompWindowTypeDesktopMask))
	priv->opacity = s->getWindowProp32 (w->id (),
					    Atoms::winOpacity, OPAQUE);

    priv->brightness = s->getWindowProp32 (w->id (),
					   Atoms::winBrightness, BRIGHT);

    priv->saturation = s->getWindowProp32 (w->id (),
					   Atoms::winSaturation, COLOR);

    if (w->isViewable ())
	priv->damaged = true;
}
Ejemplo n.º 3
0
void X11Support::registerForTrayIconUpdates(unsigned long window)
{
	XSelectInput(QX11Info::display(), window, StructureNotifyMask);

	// Apparently, there is no need to destroy damage object, as it's gone automatically when window is destroyed.
	XDamageCreate(QX11Info::display(), window, XDamageReportNonEmpty);
}
Ejemplo n.º 4
0
/* Registers XDamage events for a given Window. */
static void register_damage(Display *dpy, Window win) {
    XWindowAttributes attrib;
    if (XGetWindowAttributes(dpy, win, &attrib) &&
            !attrib.override_redirect) {
        XDamageCreate(dpy, win, XDamageReportRawRectangles);
    }
}
Ejemplo n.º 5
0
void window_set_mapped(Window id, bool mapped)
{
	window_t *window = window_get(id);
	
	if (window == NULL)
		return;
	
	window->mapped = mapped;
	
	if (mapped == TRUE) {
		XRenderPictFormat *format;
		XRenderPictureAttributes pa;
		
		format = XRenderFindVisualFormat(conn, visual);
		pa.subwindow_mode = IncludeInferiors;
		
		if (window->picture != None)
			XRenderFreePicture(conn, window->picture);
		
		if (window->pixmap != None)
			XFreePixmap(conn, window->pixmap);
		
		window->pixmap = XCompositeNameWindowPixmap(conn, id);
		window->picture = XRenderCreatePicture(conn, window->pixmap,
				format, CPSubwindowMode, &pa);
		XDamageCreate(conn, window->pixmap, XDamageReportNonEmpty);
		
		window_list_remove(id);
		window_list_append(id);
	}
}
void FdoSelectionManager::addDamageWatch(QWidget *container, WId client)
{
#if defined(HAVE_XFIXES) && defined(HAVE_XDAMAGE) && defined(HAVE_XCOMPOSITE)
    DamageWatch *damage = new DamageWatch;
    damage->container = container;
    damage->damage = XDamageCreate(QX11Info::display(), client, XDamageReportNonEmpty);
    damageWatches.insert(client, damage);
#endif
}
static void
create_damage (MetaSurfaceActorX11 *self)
{
  MetaSurfaceActorX11Private *priv = meta_surface_actor_x11_get_instance_private (self);
  Display *xdisplay = meta_display_get_xdisplay (priv->display);
  Window xwindow = meta_window_x11_get_toplevel_xwindow (priv->window);

  priv->damage = XDamageCreate (xdisplay, xwindow, XDamageReportBoundingBox);
}
RedirectedXCompositeWindow::RedirectedXCompositeWindow(const IntSize& size, GLContextNeeded needsContext)
    : m_size(size)
    , m_window(0)
    , m_parentWindow(0)
    , m_pixmap(0)
    , m_needsContext(needsContext)
    , m_surface(0)
    , m_needsNewPixmapAfterResize(false)
    , m_damage(0)
    , m_damageNotifyCallback(0)
    , m_damageNotifyData(0)
{
    Display* display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
    Screen* screen = DefaultScreenOfDisplay(display);

    // This is based on code from Chromium: src/content/common/gpu/image_transport_surface_linux.cc
    XSetWindowAttributes windowAttributes;
    windowAttributes.override_redirect = True;
    m_parentWindow = XCreateWindow(display,
        RootWindowOfScreen(screen),
        WidthOfScreen(screen) + 1, 0, 1, 1,
        0,
        CopyFromParent,
        InputOutput,
        CopyFromParent,
        CWOverrideRedirect,
        &windowAttributes);
    XMapWindow(display, m_parentWindow);

    windowAttributes.event_mask = StructureNotifyMask;
    windowAttributes.override_redirect = False;
    m_window = XCreateWindow(display,
                             m_parentWindow,
                             0, 0, size.width(), size.height(),
                             0,
                             CopyFromParent,
                             InputOutput,
                             CopyFromParent,
                             CWEventMask,
                             &windowAttributes);
    XMapWindow(display, m_window);

    if (getWindowHashMap().isEmpty())
        gdk_window_add_filter(0, reinterpret_cast<GdkFilterFunc>(filterXDamageEvent), 0);
    getWindowHashMap().add(m_window, this);

    while (1) {
        XEvent event;
        XWindowEvent(display, m_window, StructureNotifyMask, &event);
        if (event.type == MapNotify && event.xmap.window == m_window)
            break;
    }
    XSelectInput(display, m_window, NoEventMask);
    XCompositeRedirectWindow(display, m_window, CompositeRedirectManual);
    m_damage = XDamageCreate(display, m_window, XDamageReportNonEmpty);
}
Ejemplo n.º 9
0
static DecorTexture *
decorGetTexture (CompScreen *screen,
		 Pixmap	    pixmap)
{
    DecorTexture *texture;
    unsigned int width, height, depth, ui;
    Window	 root;
    int		 i;

    DECOR_DISPLAY (screen->display);

    for (texture = dd->textures; texture; texture = texture->next)
    {
	if (texture->pixmap == pixmap)
	{
	    texture->refCount++;
	    return texture;
	}
    }

    texture = malloc (sizeof (DecorTexture));
    if (!texture)
	return NULL;

    initTexture (screen, &texture->texture);

    if (!XGetGeometry (screen->display->display, pixmap, &root,
		       &i, &i, &width, &height, &ui, &depth))
    {
	finiTexture (screen, &texture->texture);
	free (texture);
	return NULL;
    }

    if (!bindPixmapToTexture (screen, &texture->texture, pixmap,
			      width, height, depth))
    {
	finiTexture (screen, &texture->texture);
	free (texture);
	return NULL;
    }

    if (!dd->opt[DECOR_DISPLAY_OPTION_MIPMAP].value.b)
	texture->texture.mipmap = FALSE;

    texture->damage = XDamageCreate (screen->display->display, pixmap,
				     XDamageReportRawRectangles);

    texture->refCount = 1;
    texture->pixmap   = pixmap;
    texture->next     = dd->textures;

    dd->textures = texture;

    return texture;
}
Ejemplo n.º 10
0
Archivo: video.c Proyecto: zmike/compiz
static VideoTexture *
videoGetTexture(CompScreen *screen,
                Pixmap pixmap)
{
   VideoTexture *texture;
   unsigned int width, height, depth, ui;
   Window root;
   int i;

   VIDEO_DISPLAY(screen->display);

   for (texture = vd->textures; texture; texture = texture->next)
     {
        if (texture->pixmap == pixmap)
          {
             texture->refCount++;
             return texture;
          }
     }

   texture = malloc(sizeof (VideoTexture));
   if (!texture)
     return NULL;

   initTexture(screen, &texture->texture);

   if (!XGetGeometry(screen->display->display, pixmap, &root,
                     &i, &i, &width, &height, &ui, &depth))
     {
        finiTexture(screen, &texture->texture);
        free(texture);
        return NULL;
     }

   if (!bindPixmapToTexture(screen, &texture->texture, pixmap,
                            width, height, depth))
     {
        finiTexture(screen, &texture->texture);
        free(texture);
        return NULL;
     }

   texture->damage = XDamageCreate(screen->display->display, pixmap,
                                   XDamageReportRawRectangles);

   texture->refCount = 1;
   texture->pixmap = pixmap;
   texture->width = width;
   texture->height = height;
   texture->next = vd->textures;

   vd->textures = texture;

   return texture;
}
Ejemplo n.º 11
0
void
clientwin_map(ClientWin *cw) {
	session_t *ps = cw->mainwin->ps;
	free_damage(ps, &cw->damage);
	
	cw->damage = XDamageCreate(ps->dpy, cw->src.window, XDamageReportDeltaRectangles);
	XRenderSetPictureTransform(ps->dpy, cw->origin, &cw->mainwin->transform);
	
	clientwin_render(cw);
	
	XMapWindow(ps->dpy, cw->mini.window);
	XRaiseWindow(ps->dpy, cw->mini.window);
}
Ejemplo n.º 12
0
void
clientwin_map(ClientWin *cw)
{
	if(cw->damage)
		XDamageDestroy(cw->mainwin->dpy, cw->damage);
	
	cw->damage = XDamageCreate(cw->mainwin->dpy, cw->client.window, XDamageReportDeltaRectangles);
	XRenderSetPictureTransform(cw->mainwin->dpy, cw->origin, &cw->mainwin->transform);
	
	clientwin_render(cw);
	
	XMapWindow(cw->mainwin->dpy, cw->mini.window);
}
Ejemplo n.º 13
0
void xf_xdamage_init(xfInfo* xfi)
{
	int damage_event;
	int damage_error;
	int major, minor;
	XGCValues values;

	if (XDamageQueryExtension(xfi->display, &damage_event, &damage_error) == 0)
	{
		fprintf(stderr, "XDamageQueryExtension failed\n");
		return;
	}

	XDamageQueryVersion(xfi->display, &major, &minor);

	if (XDamageQueryVersion(xfi->display, &major, &minor) == 0)
	{
		fprintf(stderr, "XDamageQueryVersion failed\n");
		return;
	}
	else if (major < 1)
	{
		fprintf(stderr, "XDamageQueryVersion failed: major:%d minor:%d\n", major, minor);
		return;
	}

	xfi->xdamage_notify_event = damage_event + XDamageNotify;
	xfi->xdamage = XDamageCreate(xfi->display, xfi->root_window, XDamageReportDeltaRectangles);

	if (xfi->xdamage == None)
	{
		fprintf(stderr, "XDamageCreate failed\n");
		return;
	}

#ifdef WITH_XFIXES
	xfi->xdamage_region = XFixesCreateRegion(xfi->display, NULL, 0);

	if (xfi->xdamage_region == None)
	{
		fprintf(stderr, "XFixesCreateRegion failed\n");
		XDamageDestroy(xfi->display, xfi->xdamage);
		xfi->xdamage = None;
		return;
	}
#endif

	values.subwindow_mode = IncludeInferiors;
	xfi->xdamage_gc = XCreateGC(xfi->display, xfi->root_window, GCSubwindowMode, &values);
	XSetFunction(xfi->display, xfi->xdamage_gc, GXcopy);
}
Ejemplo n.º 14
0
EAPI Ecore_X_Damage
ecore_x_damage_new(Ecore_X_Drawable d,
                   Ecore_X_Damage_Report_Level level)
{
#ifdef ECORE_XDAMAGE
   Ecore_X_Damage damage;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   damage = XDamageCreate(_ecore_x_disp, d, level);
   return damage;
#else /* ifdef ECORE_XDAMAGE */
   return 0;
#endif /* ifdef ECORE_XDAMAGE */
}
Ejemplo n.º 15
0
void TrayIcon::attachApp(WId id){
  if(id==0){ return; } //nothing to attach
  else if(AID!=0){ qWarning() << "Tray Icon is already attached to a window!"; return; }
  AID = id;
  IID = this->winId(); //embed directly into this widget
  //IID = LX11::CreateWindow( this->winId(), this->rect() ); //Create an intermediate window to be the parent
  if( LSession::handle()->XCB->EmbedWindow(AID, IID) ){
    LX11::RestoreWindow(AID); //make it visible
    //XSelectInput(QX11Info::display(), AID, StructureNotifyMask);
    //xcb_damage_create(QX11Info::connection(), dmgID, AID, XCB_DAMAGE_REPORT_LEVEL_RAW_RECTANGLES);
    dmgID = XDamageCreate( QX11Info::display(), AID, XDamageReportRawRectangles );
    qDebug() << "New System Tray App:" << AID;
    QTimer::singleShot(1000, this, SLOT(updateIcon()) );
  }else{
    qWarning() << "Could not Embed Tray Application:" << AID;
    //LX11::DestroyWindow(IID);
    IID = 0;
    AID = 0;
  }
}
void
clutter_x11_texture_pixmap_set_automatic (ClutterX11TexturePixmap *texture,
                                          gboolean                 setting)
{
  ClutterX11TexturePixmapPrivate *priv;
  Display                        *dpy;

  g_return_if_fail (CLUTTER_X11_IS_TEXTURE_PIXMAP (texture));

  priv = texture->priv;

  if (setting == priv->automatic_updates)
    return;

  dpy = clutter_x11_get_default_display();

  if (setting == TRUE)
    {
      clutter_x11_add_filter (on_x_event_filter, (gpointer)texture);

      clutter_x11_trap_x_errors ();

      if (priv->window)
        priv->damage_drawable = priv->window;
      else
        priv->damage_drawable = priv->pixmap;

      priv->damage = XDamageCreate (dpy,
                                    priv->damage_drawable,
                                    XDamageReportNonEmpty);

      XSync (dpy, FALSE);
      clutter_x11_untrap_x_errors ();
    }
  else
    free_damage_resources (texture);

  priv->automatic_updates = setting;

}
Ejemplo n.º 17
0
compzillaWindow::compzillaWindow(Display *display, Window win, XWindowAttributes *attrs)
    : mAttr(*attrs),
      mDisplay(display),
      mWindow(win),
      mPixmap(None),
      mDamage(None),
      mLastEntered(None),
      mIsDestroyed(false),
      mIsRedirected(false),
      mIsResizePending(false)
{
    XSelectInput (display, win, (PropertyChangeMask | EnterWindowMask | FocusChangeMask));

#if HAVE_XSHAPE
    XShapeSelectInput (display, win, ShapeNotifyMask);
#endif

    // Get notified of global cursor changes.  
    // FIXME: This is not very useful, as X has no way of fetching the Cursor
    // for a given window.
    //XFixesSelectCursorInput (display, win, XFixesDisplayCursorNotifyMask);

    XGrabButton (display, AnyButton, AnyModifier, win, true, 
                 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),
                 GrabModeSync, GrabModeSync, None, None);

    /* 
     * Set up damage notification.  RawRectangles gives us smaller grain
     * changes, versus NonEmpty which seems to always include the entire
     * contents.
     */
    mDamage = XDamageCreate (mDisplay, mWindow, XDamageReportRawRectangles);

    if (mAttr.map_state == IsViewable) {
        mAttr.map_state = IsUnmapped;
        Mapped (mAttr.override_redirect);
    }
}
Ejemplo n.º 18
0
guint32
ccm_display_register_damage (CCMDisplay* self, CCMDrawable* drawable, CCMDamageCallbackFunc func)
{
    Damage damage = XDamageCreate (CCM_DISPLAY_XDISPLAY (self),
                                   ccm_drawable_get_xid (drawable),
                                   XDamageReportDeltaRectangles);
    if (damage)
    {
        GSList* item;
        gboolean found = FALSE;
        CCMDamageCallback* callback;

        callback = (CCMDamageCallback*)ccm_set_search (self->priv->registered_damage,
                                                       G_TYPE_UINT, NULL, NULL,
                                                       (gpointer)damage,
                                                       (CCMSetValueCompareFunc)ccm_damage_callback_compare_with_damage);
        if (callback == NULL)
        {
            callback = ccm_damage_callback_new ();
            XDamageSubtract (CCM_DISPLAY_XDISPLAY (self), damage, None, None);
            callback->damage = damage;
            callback->func = func;
            callback->drawable = drawable;

            ccm_set_insert (self->priv->registered_damage, callback);
        }
        else
        {
            callback->func = func;
            callback->drawable = drawable;
        }
    }
    else
        damage = None;

    return (guint32)damage;
}
Ejemplo n.º 19
0
static int x11_shadow_xdamage_init(x11ShadowSubsystem* subsystem)
{
#ifdef WITH_XDAMAGE
	int major, minor;
	int damage_event;
	int damage_error;

	if (!subsystem->use_xfixes)
		return -1;

	if (!XDamageQueryExtension(subsystem->display, &damage_event, &damage_error))
		return -1;

	if (!XDamageQueryVersion(subsystem->display, &major, &minor))
		return -1;

	if (major < 1)
		return -1;

	subsystem->xdamage_notify_event = damage_event + XDamageNotify;
	subsystem->xdamage = XDamageCreate(subsystem->display, subsystem->root_window, XDamageReportDeltaRectangles);

	if (!subsystem->xdamage)
		return -1;

#ifdef WITH_XFIXES
	subsystem->xdamage_region = XFixesCreateRegion(subsystem->display, NULL, 0);

	if (!subsystem->xdamage_region)
		return -1;
#endif

	return 1;
#else
	return -1;
#endif
}
Ejemplo n.º 20
0
RedirectedXCompositeWindow::RedirectedXCompositeWindow(GdkWindow* parentWindow, std::function<void()> damageNotify)
    : m_display(GDK_DISPLAY_XDISPLAY(gdk_window_get_display(parentWindow)))
    , m_window(0)
    , m_parentWindow(0)
    , m_pixmap(0)
    , m_damage(0)
    , m_needsNewPixmapAfterResize(false)
{
    Screen* screen = DefaultScreenOfDisplay(m_display);

    GdkVisual* visual = gdk_window_get_visual(parentWindow);
    Colormap colormap = XCreateColormap(m_display, RootWindowOfScreen(screen), GDK_VISUAL_XVISUAL(visual), AllocNone);

    // This is based on code from Chromium: src/content/common/gpu/image_transport_surface_linux.cc
    XSetWindowAttributes windowAttributes;
    windowAttributes.override_redirect = True;
    windowAttributes.colormap = colormap;

    // CWBorderPixel must be present when the depth doesn't match the parent's one.
    // See http://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c?id=xorg-server-1.16.0#n703.
    windowAttributes.border_pixel = 0;

    m_parentWindow = XCreateWindow(m_display,
        RootWindowOfScreen(screen),
        WidthOfScreen(screen) + 1, 0, 1, 1,
        0,
        gdk_visual_get_depth(visual),
        InputOutput,
        GDK_VISUAL_XVISUAL(visual),
        CWOverrideRedirect | CWColormap | CWBorderPixel,
        &windowAttributes);
    XMapWindow(m_display, m_parentWindow);

    windowAttributes.event_mask = StructureNotifyMask;
    windowAttributes.override_redirect = False;
    // Create the window of at last 1x1 since X doesn't allow to create empty windows.
    m_window = XCreateWindow(m_display,
        m_parentWindow,
        0, 0,
        std::max(1, m_size.width()),
        std::max(1, m_size.height()),
        0,
        CopyFromParent,
        InputOutput,
        CopyFromParent,
        CWEventMask,
        &windowAttributes);
    XMapWindow(m_display, m_window);

    XFreeColormap(m_display, colormap);

    xDamageNotifier().add(m_window, WTF::move(damageNotify));

    while (1) {
        XEvent event;
        XWindowEvent(m_display, m_window, StructureNotifyMask, &event);
        if (event.type == MapNotify && event.xmap.window == m_window)
            break;
    }
    XSelectInput(m_display, m_window, NoEventMask);
    XCompositeRedirectWindow(m_display, m_window, CompositeRedirectManual);
    m_damage = XDamageCreate(m_display, m_window, XDamageReportNonEmpty);
}
Ejemplo n.º 21
0
				sraRgnMakeEmpty(*ptr);
			}
		}
		/* set so will be 0 in first collect_xdamage call */
		xdamage_ticker = -1;
	}
}

void create_xdamage_if_needed(void) {

	RAWFB_RET_VOID

#if LIBVNCSERVER_HAVE_LIBXDAMAGE
	if (! xdamage) {
		X_LOCK;
		xdamage = XDamageCreate(dpy, window, XDamageReportRawRectangles); 
		XDamageSubtract(dpy, xdamage, None, None);
		X_UNLOCK;
		rfbLog("created xdamage object: 0x%lx\n", xdamage);
	}
#endif
}

void destroy_xdamage_if_needed(void) {

	RAWFB_RET_VOID

#if LIBVNCSERVER_HAVE_LIBXDAMAGE
	if (xdamage) {
		XEvent ev;
		X_LOCK;
Ejemplo n.º 22
0
bool BackendInitialize(const char * display_name)
{
	Display * dpy = XOpenDisplay(display_name);
	if (!dpy)
	{
		fprintf (stderr, "%s:  unable to open display '%s'\n",
					g_program_name, XDisplayName (display_name));
		usage();
		return false;
	}

	Window root = DefaultRootWindow(dpy);

	int damage_error, damage;
	if (!XDamageQueryExtension (dpy, &damage, &damage_error))
	{
		fprintf (stderr, "%s: Backend does not have damage extension\n", g_program_name);
		return false;
	}
#ifndef USE_PANELS
	XDamageCreate (dpy, root, XDamageReportRawRectangles);
#endif

	XWindowAttributes attrib;
	XGetWindowAttributes(dpy, root, &attrib);
	if (attrib.width ==0 || attrib.height == 0)
	{
		fprintf(stderr, "%s: Bad root with %d x %d\n", 
			g_program_name, attrib.width, attrib.height);
		return false;
	}

#ifndef USE_PANELS
	GLuint texture;
	glGenTextures(1, &texture);
	glBindTexture(GL_TEXTURE_2D, texture);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, attrib.width, attrib.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
#endif

	int buffer_size = attrib.width * attrib.height * 4;
	unsigned char * buffer = (unsigned char *)malloc(buffer_size);
	if (!buffer)
	{
		fprintf(stderr, "%s: Failed to allocate buffer %d x %d\n",
			g_program_name, attrib.width, attrib.height);
		return false;
	}

	uint32_t mask = ~dpy->resource_mask;
	uint32_t shift = 0;
	while (!(mask & 1))
	{
		shift++;
		mask >>= 1;
	}

	g_backend._dpy = dpy;
	g_backend._root = root;
	g_backend._damage = damage;
	g_backend._width = attrib.width;
	g_backend._height = attrib.height;
#ifndef USE_PANELS
	g_backend._texture = texture;
#endif
	g_backend._mouse_x = attrib.width/2;
	g_backend._mouse_y = attrib.height/2;
	g_backend._buffer_size = buffer_size;
	g_backend._buffer = buffer;
	g_backend._mask = ~dpy->resource_mask;
	g_backend._shift = shift;

#ifndef USE_PANELS
	BackendUpdateTexture(root, texture, 0, 0, attrib.width, attrib.height);
#endif
	return true;
}
Ejemplo n.º 23
0
/* The main function */
int main(int argc, char const *argv[])
{
	Display *dpy;
	GString *line;
	unsigned xeventmask;
	int error_base, shape_event, damage_event;
	struct
	{
		Bool children, creation, mapping, configure, shape;
		Bool properties, clientmsg;
		Bool visibility, exposure, damages;
		Bool pointer, keyboard;
	} track;

	dpy = XOpenDisplay(NULL);
	XSetErrorHandler(xerror_handler);
	XA_utf8_string = XInternAtom(dpy, "UTF8_STRING", False);
	XA_wm_state    = XInternAtom(dpy, "WM_STATE", False);

	if (argv[1] && !strcmp(argv[1], "-t"))
	{
		Opt_timestamp = 1;
		optind++;
	}

	/* Choose which events we're interested in. */
	memset(&track, 0, sizeof(track));
	track.children		= True;
	track.creation		= True;
	track.mapping		= True;
	track.configure		= True;
	track.shape		= True;
	track.properties	= True;
	track.clientmsg		= True;
	track.visibility	= True;
	track.keyboard		= True;
	for (; argv[optind]; optind++)
	{
		char const *opt;
		Bool add, del, *which;

		opt = argv[optind];
		add = opt[0] == '+';
		del = opt[0] == '-';
		if (add || del)
			opt++;

		if (!strcmp(opt, "children"))
			which = &track.children;
		else if (!strcmp(opt, "create"))
			which = &track.creation;
		else if (!strcmp(opt, "map"))
			which = &track.mapping;
		else if (!strcmp(opt, "config"))
			which = &track.configure;
		else if (!strcmp(opt, "shape"))
			which = &track.shape;
		else if (!strcmp(opt, "prop"))
			which = &track.properties;
		else if (!strcmp(opt, "ipc"))
			which = &track.clientmsg;
		else if (!strcmp(opt, "visibility"))
			which = &track.visibility;
		else if (!strcmp(opt, "expose"))
			which = &track.exposure;
		else if (!strcmp(opt, "damage"))
			which = &track.damages;
		else if (!strcmp(opt, "ptr"))
			which = &track.pointer;
		else if (!strcmp(opt, "kbd"))
			which = &track.keyboard;
		else
			break;

		if (!add && !del)
			memset(&track, 0, sizeof(track));
		*which = !del;
	} /* for */

	xeventmask = 0;
	if (track.creation || track.mapping || track.configure
			|| track.clientmsg)
		xeventmask |= track.children
			? SubstructureNotifyMask
			: StructureNotifyMask;
	if (track.shape)
		XShapeQueryExtension(dpy, &shape_event, &error_base);
	if (track.properties)
		xeventmask |= PropertyChangeMask;
	if (track.visibility)
		xeventmask |= VisibilityChangeMask;
	if (track.exposure)
		xeventmask |= ExposureMask;
	if (track.damages)
		XDamageQueryExtension(dpy, &damage_event, &error_base);
	if (track.pointer);
		xeventmask |= EnterWindowMask|LeaveWindowMask;
	if (track.keyboard)
		xeventmask |= KeyPressMask|KeyReleaseMask;

	/* XSelectInput() the windows we're interested in
	 * or the root window. */
	if (argv[optind])
		do
		{
			Window win;
			char const *errp;

			win = strtoul(argv[optind], (char **)&errp, 0);
			if (errp == argv[optind] || *errp)
			{
				fprintf(stderr, "%s: what is `%s'?\n",
					argv[0], argv[optind]);
				exit(1);
			}

			XSelectInput(dpy, win, xeventmask);
			if (track.shape)
				XShapeSelectInput(dpy, win, ShapeNotifyMask);
			if (track.damages)
				XDamageCreate(dpy, win,
					XDamageReportRawRectangles);
		} while (argv[++optind]);
	else
		XSelectInput(dpy, DefaultRootWindow(dpy), xeventmask);

	/* The main loop */
	line = g_string_new("");
	for (;;)
	{
		XEvent ev;

		/* Wait for, get and process the next event. */
		XNextEvent(dpy, &ev);
		if (ev.type == CreateNotify)
		{
			XCreateWindowEvent const *create = &ev.xcreatewindow;

			if (!track.creation)
				continue;
			fmtxid(line, create->parent);
			g_string_append_printf(line,
				"Create(0x%lx)", create->window);
			output(line, ev.xany.send_event);
		} else if (ev.type == DestroyNotify)
		{
			XDestroyWindowEvent const *destroy = &ev.xdestroywindow;

			if (!track.creation)
				continue;
			fmtxid(line, destroy->event);
			g_string_append_printf(line,
				"Destroy(0x%lx)", destroy->window);
			output(line, ev.xany.send_event);
		} else if (ev.type == MapNotify)
		{
			XMapEvent const *map = &ev.xmap;

			if (!track.mapping)
				continue;
			fmtxid(line, map->event);
			g_string_append_printf(line, "Map(0x%lx%s)",
				map->window, map->override_redirect
					? ", override_redirected" : "");
			output(line, ev.xany.send_event);
		} else if (ev.type == UnmapNotify)
		{
			XUnmapEvent const *unmap = &ev.xunmap;

			if (!track.mapping)
				continue;
			fmtxid(line, unmap->event);
			g_string_append_printf(line, "Unmap(0x%lx%s)",
				unmap->window, unmap->from_configure
					? ", from_configure" : "");
			output(line, ev.xany.send_event);
		} else if (ev.type == ReparentNotify)
		{
			XReparentEvent const *reparent  = &ev.xreparent;

			if (!track.configure)
				continue;
			fmtxid(line, reparent->event);
			g_string_append_printf(line,
				"Reparent(0x%lx => 0x%lx)",
				reparent->window, reparent->parent);
			output(line, ev.xany.send_event);
		} else if (ev.type == ConfigureNotify)
		{
			XConfigureEvent const *cfg = &ev.xconfigure;

			if (!track.configure)
				continue;
			fmtxid(line, cfg->event);
			g_string_append_printf(line,
				"Configure(0x%lx => %dx%d%+d%+d, "
				"above=0x%lx%s)", cfg->window,
				cfg->width, cfg->height, cfg->x, cfg->y,
				cfg->above, cfg->override_redirect
					? ", override_redirected" : "");
			output(line, ev.xany.send_event);
		} else if (track.shape && ev.type == shape_event + ShapeNotify)
		{
			static char const *shapes[] =
				{ "Bounding", "Clip", "Input" };
			XShapeEvent sev;

			memcpy(&sev, &ev, sizeof(sev));
			fmtxid(line, sev.window);
			g_string_append_printf(line,
				"Shape(%s => %dx%d%+d%+d)",
				shapes[sev.kind],
				sev.width, sev.height, sev.x, sev.y);
			output(line, ev.xany.send_event);
		} else if (ev.type == PropertyNotify)
		{
			assert(track.properties);
			property_event(dpy, &ev.xproperty, line);
		} else if (ev.type == ClientMessage)
		{
			if (!track.clientmsg)
				continue;
			client_message(dpy, &ev.xclient, line);
		} else if (ev.type == VisibilityNotify)
		{
			static char const *visibilities[] =
			{
				"unobscured",
				"partially obscured",
				"fully obscured",
			};
			XVisibilityEvent const *vis = &ev.xvisibility;

			assert(track.visibility);
			fmtxid(line, vis->window);
			g_string_append_printf(line, "Visibility=%s",
				visibilities[vis->state]);
			output(line, ev.xany.send_event);
		} else if (ev.type == Expose)
		{
			XExposeEvent const *ex = &ev.xexpose;

			assert(track.exposure);
			fmtxid(line, ex->window);
			g_string_append_printf(line,
				"Expose(%dx%d%+d%+d)",
				ex->width, ex->height,
				ex->x, ex->y);
			output(line, ev.xany.send_event);
		} else if (track.damages && ev.type == damage_event)
		{
			XDamageNotifyEvent dev;

			memcpy(&dev, &ev, sizeof(dev));
			fmtxid(line, dev.drawable);
			g_string_append_printf(line,
				"Damage(%dx%d%+d%+d)",
				dev.area.width, dev.area.height,
				dev.area.x, dev.area.y);
			output(line, ev.xany.send_event);
			XDamageSubtract(dpy, dev.damage, None, None);
		} else if (ev.type == EnterNotify || ev.type == LeaveNotify)
		{
			XCrossingEvent const *cross = &ev.xcrossing;

			if (!track.pointer)
				continue;
			fmtxid(line, cross->window);
			g_string_append_printf(line,
				"%s(%dx%d",
				cross->type == EnterNotify
					? "Enter" : "Leave",
				cross->x, cross->y);
			if (cross->mode == NotifyGrab)
				g_string_append(line, ", grab");
			else if (cross->mode == NotifyUngrab)
				g_string_append(line, ", ungrab");
			g_string_append_c(line, ')');
			output(line, ev.xany.send_event);
		} else if (ev.type == KeyPress || ev.type == KeyRelease)
		{
			static struct { int mask; char const *name; } states[] =
			{
				{ ShiftMask,	"Shift"	},
				{ LockMask,	"Lock"	},
				{ ControlMask,	"Ctrl"	},
				{ Mod1Mask,	"Mod1"	},
				{ Mod2Mask,	"Mod2"	},
				{ Mod3Mask,	"Mod3"	},
				{ Mod4Mask,	"Mod4"	},
				{ Mod5Mask,	"Mod5"	},
			};
			unsigned i;
			int has_modifiers;
			XKeyEvent const *key;

			assert(track.keyboard);
			key = &ev.xkey;
			fmtxid(line, key->window);

			/* Prepend with the list of modifiers. */
			has_modifiers = 0;
			for (i = 0; i < G_N_ELEMENTS(states); i++)
				if (key->state & states[i].mask)
				{
					if (!has_modifiers)
					{
						g_string_append_c(line, ' ');
						has_modifiers = 1;
					} else
						g_string_append_c(line, '-');
					g_string_append(line, states[i].name);
				}
                        if (has_modifiers)
				g_string_append_c(line, '-');
			g_string_append_printf(line, "%s %s",
				XKeysymToString(XKeycodeToKeysym(dpy,
						      key->keycode, 0)),
				ev.type == KeyPress
					? "pressed" : "released");
			output(line, ev.xany.send_event);
		} /* if */
	} /* for ever */

	return 0;
} /* main */
Ejemplo n.º 24
0
CoglHandle
cogl_texture_pixmap_x11_new (guint32 pixmap,
                             gboolean automatic_updates)
{
  CoglTexturePixmapX11 *tex_pixmap = g_new (CoglTexturePixmapX11, 1);
  Display *display = cogl_xlib_get_display ();
  Window pixmap_root_window;
  int pixmap_x, pixmap_y;
  unsigned int pixmap_border_width;
  CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
  XWindowAttributes window_attributes;
  int damage_base;
  const CoglWinsysVtable *winsys;

  _COGL_GET_CONTEXT (ctxt, COGL_INVALID_HANDLE);

  _cogl_texture_init (tex, &cogl_texture_pixmap_x11_vtable);

  tex_pixmap->pixmap = pixmap;
  tex_pixmap->image = NULL;
  tex_pixmap->shm_info.shmid = -1;
  tex_pixmap->tex = COGL_INVALID_HANDLE;
  tex_pixmap->damage_owned = FALSE;
  tex_pixmap->damage = 0;

  if (!XGetGeometry (display, pixmap, &pixmap_root_window,
                     &pixmap_x, &pixmap_y,
                     &tex_pixmap->width, &tex_pixmap->height,
                     &pixmap_border_width, &tex_pixmap->depth))
    {
      g_free (tex_pixmap);
      g_warning ("Unable to query pixmap size");
      return COGL_INVALID_HANDLE;
    }

  /* We need a visual to use for shared memory images so we'll query
     it from the pixmap's root window */
  if (!XGetWindowAttributes (display, pixmap_root_window, &window_attributes))
    {
      g_free (tex_pixmap);
      g_warning ("Unable to query root window attributes");
      return COGL_INVALID_HANDLE;
    }
  tex_pixmap->visual = window_attributes.visual;

  /* If automatic updates are requested and the Xlib connection
     supports damage events then we'll register a damage object on the
     pixmap */
  damage_base = _cogl_xlib_get_damage_base ();
  if (automatic_updates && damage_base >= 0)
    {
      Damage damage = XDamageCreate (display,
                                     pixmap,
                                     XDamageReportBoundingBox);
      set_damage_object_internal (ctxt,
                                  tex_pixmap,
                                  damage,
                                  COGL_TEXTURE_PIXMAP_X11_DAMAGE_BOUNDING_BOX);
      tex_pixmap->damage_owned = TRUE;
    }

  /* Assume the entire pixmap is damaged to begin with */
  tex_pixmap->damage_rect.x1 = 0;
  tex_pixmap->damage_rect.x2 = tex_pixmap->width;
  tex_pixmap->damage_rect.y1 = 0;
  tex_pixmap->damage_rect.y2 = tex_pixmap->height;

  winsys = _cogl_texture_pixmap_x11_get_winsys (tex_pixmap);
  if (winsys->texture_pixmap_x11_create)
    {
      tex_pixmap->use_winsys_texture =
        winsys->texture_pixmap_x11_create (tex_pixmap);
    }
  else
    tex_pixmap->use_winsys_texture = FALSE;

  if (!tex_pixmap->use_winsys_texture)
    tex_pixmap->winsys = NULL;

  return _cogl_texture_pixmap_x11_handle_new (tex_pixmap);
}
Ejemplo n.º 25
0
static CoglTexturePixmapX11 *
_cogl_texture_pixmap_x11_new (CoglContext *ctxt,
                              uint32_t pixmap,
                              gboolean automatic_updates,
                              CoglTexturePixmapStereoMode stereo_mode,
                              CoglError **error)
{
  CoglTexturePixmapX11 *tex_pixmap = g_new (CoglTexturePixmapX11, 1);
  Display *display = cogl_xlib_renderer_get_display (ctxt->display->renderer);
  Window pixmap_root_window;
  int pixmap_x, pixmap_y;
  unsigned int pixmap_width, pixmap_height;
  unsigned int pixmap_border_width;
  CoglPixelFormat internal_format;
  CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
  XWindowAttributes window_attributes;
  int damage_base;
  const CoglWinsysVtable *winsys;

  if (!XGetGeometry (display, pixmap, &pixmap_root_window,
                     &pixmap_x, &pixmap_y,
                     &pixmap_width, &pixmap_height,
                     &pixmap_border_width, &tex_pixmap->depth))
    {
      g_free (tex_pixmap);
      _cogl_set_error (error,
                   COGL_TEXTURE_PIXMAP_X11_ERROR,
                   COGL_TEXTURE_PIXMAP_X11_ERROR_X11,
                   "Unable to query pixmap size");
      return NULL;
    }

  /* Note: the detailed pixel layout doesn't matter here, we are just
   * interested in RGB vs RGBA... */
  internal_format = (tex_pixmap->depth >= 32
                     ? COGL_PIXEL_FORMAT_RGBA_8888_PRE
                     : COGL_PIXEL_FORMAT_RGB_888);

  _cogl_texture_init (tex, ctxt, pixmap_width, pixmap_height,
                      internal_format,
                      NULL, /* no loader */
                      &cogl_texture_pixmap_x11_vtable);

  tex_pixmap->pixmap = pixmap;
  tex_pixmap->stereo_mode = stereo_mode;
  tex_pixmap->left = NULL;
  tex_pixmap->image = NULL;
  tex_pixmap->shm_info.shmid = -1;
  tex_pixmap->tex = NULL;
  tex_pixmap->damage_owned = FALSE;
  tex_pixmap->damage = 0;

  /* We need a visual to use for shared memory images so we'll query
     it from the pixmap's root window */
  if (!XGetWindowAttributes (display, pixmap_root_window, &window_attributes))
    {
      g_free (tex_pixmap);
      _cogl_set_error (error,
                   COGL_TEXTURE_PIXMAP_X11_ERROR,
                   COGL_TEXTURE_PIXMAP_X11_ERROR_X11,
                   "Unable to query root window attributes");
      return NULL;
    }

  tex_pixmap->visual = window_attributes.visual;

  /* If automatic updates are requested and the Xlib connection
     supports damage events then we'll register a damage object on the
     pixmap */
  damage_base = _cogl_xlib_get_damage_base ();
  if (automatic_updates && damage_base >= 0)
    {
      Damage damage = XDamageCreate (display,
                                     pixmap,
                                     XDamageReportBoundingBox);
      set_damage_object_internal (ctxt,
                                  tex_pixmap,
                                  damage,
                                  COGL_TEXTURE_PIXMAP_X11_DAMAGE_BOUNDING_BOX);
      tex_pixmap->damage_owned = TRUE;
    }

  /* Assume the entire pixmap is damaged to begin with */
  tex_pixmap->damage_rect.x1 = 0;
  tex_pixmap->damage_rect.x2 = pixmap_width;
  tex_pixmap->damage_rect.y1 = 0;
  tex_pixmap->damage_rect.y2 = pixmap_height;

  winsys = _cogl_texture_pixmap_x11_get_winsys (tex_pixmap);
  if (winsys->texture_pixmap_x11_create)
    {
      tex_pixmap->use_winsys_texture =
        winsys->texture_pixmap_x11_create (tex_pixmap);
    }
  else
    tex_pixmap->use_winsys_texture = FALSE;

  if (!tex_pixmap->use_winsys_texture)
    tex_pixmap->winsys = NULL;

  _cogl_texture_set_allocated (tex, internal_format,
                               pixmap_width, pixmap_height);

  return _cogl_texture_pixmap_x11_object_new (tex_pixmap);
}
Ejemplo n.º 26
0
RedirectedXCompositeWindow::RedirectedXCompositeWindow(WebPageProxy& webPage, const IntSize& initialSize, std::function<void()>&& damageNotify)
    : m_webPage(webPage)
    , m_display(GDK_DISPLAY_XDISPLAY(gdk_window_get_display(gtk_widget_get_parent_window(webPage.viewWidget()))))
    , m_size(initialSize)
{
    m_size.scale(m_webPage.deviceScaleFactor());

    ASSERT(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native() == m_display);
    Screen* screen = DefaultScreenOfDisplay(m_display);

    GdkVisual* visual = gdk_window_get_visual(gtk_widget_get_parent_window(webPage.viewWidget()));
    XUniqueColormap colormap(XCreateColormap(m_display, RootWindowOfScreen(screen), GDK_VISUAL_XVISUAL(visual), AllocNone));

    // This is based on code from Chromium: src/content/common/gpu/image_transport_surface_linux.cc
    XSetWindowAttributes windowAttributes;
    windowAttributes.override_redirect = True;
    windowAttributes.colormap = colormap.get();

    // CWBorderPixel must be present when the depth doesn't match the parent's one.
    // See http://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c?id=xorg-server-1.16.0#n703.
    windowAttributes.border_pixel = 0;

    m_parentWindow = XCreateWindow(m_display,
        RootWindowOfScreen(screen),
        WidthOfScreen(screen) + 1, 0, 1, 1,
        0,
        gdk_visual_get_depth(visual),
        InputOutput,
        GDK_VISUAL_XVISUAL(visual),
        CWOverrideRedirect | CWColormap | CWBorderPixel,
        &windowAttributes);
    XMapWindow(m_display, m_parentWindow.get());

    windowAttributes.event_mask = StructureNotifyMask;
    windowAttributes.override_redirect = False;
    // Create the window of at last 1x1 since X doesn't allow to create empty windows.
    m_window = XCreateWindow(m_display,
        m_parentWindow.get(),
        0, 0,
        std::max(1, m_size.width()),
        std::max(1, m_size.height()),
        0,
        CopyFromParent,
        InputOutput,
        CopyFromParent,
        CWEventMask,
        &windowAttributes);
    XMapWindow(m_display, m_window.get());

    xDamageNotifier().add(m_window.get(), WTFMove(damageNotify));

    while (1) {
        XEvent event;
        XWindowEvent(m_display, m_window.get(), StructureNotifyMask, &event);
        if (event.type == MapNotify && event.xmap.window == m_window.get())
            break;
    }
    XSelectInput(m_display, m_window.get(), NoEventMask);
    XCompositeRedirectWindow(m_display, m_window.get(), CompositeRedirectManual);
    if (!m_size.isEmpty())
        createNewPixampAndPixampSurface();
    m_damage = XDamageCreate(m_display, m_window.get(), XDamageReportNonEmpty);
}
Ejemplo n.º 27
0
bool TrayIcon::init()
{
    Display* dsp = QX11Info::display();

    XWindowAttributes attr;
    if (! XGetWindowAttributes(dsp, mIconId, &attr)) return false;

//    qDebug() << "New tray icon ***********************************";
//    qDebug() << "  * window id:  " << hex << mIconId;
//    qDebug() << "  * window name:" << xfitMan().getName(mIconId);
//    qDebug() << "  * size (WxH): " << attr.width << "x" << attr.height;
//    qDebug() << "  * color depth:" << attr.depth;

    unsigned long mask = 0;
    XSetWindowAttributes set_attr;

    Visual* visual = attr.visual;
    set_attr.colormap = attr.colormap;
    set_attr.background_pixel = 0;
    set_attr.border_pixel = 0;
    mask = CWColormap|CWBackPixel|CWBorderPixel;

    mWindowId = XCreateWindow(dsp, this->winId(), 0, 0, mIconSize.width(), mIconSize.height(),
                              0, attr.depth, InputOutput, visual, mask, &set_attr);


    xError = false;
    XErrorHandler old;
    old = XSetErrorHandler(windowErrorHandler);
    XReparentWindow(dsp, mIconId, mWindowId, 0, 0);
    XSync(dsp, false);
    XSetErrorHandler(old);

    if (xError) {
        qWarning() << "****************************************";
        qWarning() << "* Not icon_swallow                     *";
        qWarning() << "****************************************";
        XDestroyWindow(dsp, mWindowId);
        return false;
    }


    {
        Atom acttype;
        int actfmt;
        unsigned long nbitem, bytes;
        unsigned char *data = 0;
        int ret;

        ret = XGetWindowProperty(dsp, mIconId, xfitMan().atom("_XEMBED_INFO"),
                                 0, 2, false, xfitMan().atom("_XEMBED_INFO"),
                                 &acttype, &actfmt, &nbitem, &bytes, &data);
        if (ret == Success) {
            if (data)
                XFree(data);
        }
        else {
            qWarning() << "TrayIcon: xembed error";
            XDestroyWindow(dsp, mWindowId);
            return false;
        }
    }

    {
        XEvent e;
        e.xclient.type = ClientMessage;
        e.xclient.serial = 0;
        e.xclient.send_event = True;
        e.xclient.message_type = xfitMan().atom("_XEMBED");
        e.xclient.window = mIconId;
        e.xclient.format = 32;
        e.xclient.data.l[0] = CurrentTime;
        e.xclient.data.l[1] = XEMBED_EMBEDDED_NOTIFY;
        e.xclient.data.l[2] = 0;
        e.xclient.data.l[3] = mWindowId;
        e.xclient.data.l[4] = 0;
        XSendEvent(dsp, mIconId, false, 0xFFFFFF, &e);
    }

    XSelectInput(dsp, mIconId, StructureNotifyMask);
    mDamage = XDamageCreate(dsp, mIconId, XDamageReportRawRectangles);
    XCompositeRedirectWindow(dsp, mWindowId, CompositeRedirectManual);

    XMapWindow(dsp, mIconId);
    XMapRaised(dsp, mWindowId);

    xfitMan().resizeWindow(mWindowId, mIconSize.width(), mIconSize.height());
    xfitMan().resizeWindow(mIconId,   mIconSize.width(), mIconSize.height());

    return true;
}
Ejemplo n.º 28
0
nsresult nsPluginNativeWindowGtk2::CreateXCompositedWindow() {
  NS_ASSERTION(!mSocketWidget,"Already created a socket widget!");

  mParentWindow = gtk_window_new(GTK_WINDOW_POPUP);
  mSocketWidget = gtk_socket_new();
  GdkWindow *parent_win = mParentWindow->window;

  //attach the socket to the container widget
  gtk_widget_set_parent_window(mSocketWidget, parent_win);

  // Make sure to handle the plug_removed signal.  If we don't the
  // socket will automatically be destroyed when the plug is
  // removed, which means we're destroying it more than once.
  // SYNTAX ERROR.
  g_signal_connect(mSocketWidget, "plug_removed",
                   G_CALLBACK(plug_removed_cb), NULL);

  g_signal_connect(mSocketWidget, "destroy",
                   G_CALLBACK(gtk_widget_destroyed), &mSocketWidget);

  /*gpointer user_data = NULL;
  gdk_window_get_user_data(parent_win, &user_data);
  */
  GtkContainer *container = GTK_CONTAINER(mParentWindow);
  gtk_container_add(container, mSocketWidget);
  gtk_widget_realize(mSocketWidget);

  // Resize before we show
  SetAllocation();
  gtk_widget_set_size_request (mSocketWidget, width, height);
  /* move offscreen */
  gtk_window_move (GTK_WINDOW(mParentWindow), width+1000, height+1000);


  gtk_widget_show(mSocketWidget);
  gtk_widget_show_all(mParentWindow);

  /* store away a reference to the socketwidget */
  mPlugWindow = (mSocketWidget);

  gdk_flush();
  window = (nsPluginPort *)gtk_socket_get_id(GTK_SOCKET(mSocketWidget));

  /* This is useful if we still have the plugin window inline
   * i.e. firefox vs. fennec */
  // gdk_window_set_composited(mSocketWidget->window, TRUE);

  if (!mDamage) {
    /* we install a general handler instead of one specific to a particular window
     * because we don't have a GdkWindow for the plugin window */
    gdk_window_add_filter (parent_win, plugin_composite_filter_func, this);

    int junk;
    if (!XDamageQueryExtension (GDK_DISPLAY (), &xdamage_event_base, &junk))
      printf ("This requires the XDamage extension");

    mDamage = XDamageCreate(GDK_DISPLAY(), (Drawable)window, XDamageReportNonEmpty);
    XCompositeRedirectWindow (GDK_DISPLAY(),
        (Drawable)window,
        CompositeRedirectManual);

    /* this is a hack to avoid having flash causing a crash when it is unloaded.
     * libplayback sets up dbus_connection_filters. When flash is unloaded it takes
     * libplayback with it, however the connection filters are not removed
     * which causes a crash when dbus tries to execute them. dlopening libplayback
     * ensures that those functions stay around even after flash is gone. */
    static void *libplayback_handle;
    if (!libplayback_handle) {
      libplayback_handle = dlopen("libplayback-1.so.0", RTLD_NOW);
    }

  }

  // Fill out the ws_info structure.
  // (The windowless case is done in nsObjectFrame.cpp.)
  GdkWindow *gdkWindow = gdk_window_lookup((XID)window);
  mWsInfo.display = GDK_WINDOW_XDISPLAY(gdkWindow);
  mWsInfo.colormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(gdkWindow));
  GdkVisual* gdkVisual = gdk_drawable_get_visual(gdkWindow);
  mWsInfo.visual = GDK_VISUAL_XVISUAL(gdkVisual);
  mWsInfo.depth = gdkVisual->depth;

  return NS_OK;
}
Ejemplo n.º 29
0
Thumbnail::Thumbnail(TeleWindow *teleWindow, Window clientWindow)
{
    _teleWindow = teleWindow;
    _dpy = teleWindow->display();
    _clientWindow = clientWindow;

    _depth = DefaultDepth(_dpy, DefaultScreen(_dpy));

    _title = XTools::windowTitle_alloc(_clientWindow);
    _clientClass = XTools::windowClass_alloc(_clientWindow);

#ifdef MAEMO4
    _isOssoMediaPlayer = strcmp(_clientClass, "mediaplayer-ui") == 0;
    _isLiqBase = strncmp(_clientClass, "liq", 3) == 0;
#endif

    _image = 0;
    _gc = 0;
    _xftDraw = 0;


    _clientDestroyed = false;

    XSelectInput(_dpy, _clientWindow, StructureNotifyMask | PropertyChangeMask);


    _damage = XDamageCreate(_dpy, _clientWindow, XDamageReportNonEmpty);


    XWindowAttributes attrs;
    XGetWindowAttributes(_dpy, _clientWindow, &attrs);

#ifdef DESKTOP
    Window root;
    Window parent;
    Window *children;
    unsigned int nchildren;
    XQueryTree(_dpy, _clientWindow, &root, &parent, &children, &nchildren);
    XFree(children);

    XWindowAttributes decoAttrs;
    XGetWindowAttributes(_dpy, parent, &decoAttrs);

    _clientDecoX = decoAttrs.x;
    _clientDecoY = decoAttrs.y;
#else
#ifdef MAEMO4
    _clientDecoX = attrs.x;
    _clientDecoY = attrs.y;
#else
#error Unknown window manager
#endif
#endif


    _previewValid = false;
    _previewOnceDrawn = false;


    // First setGeometry call will compare this with new dimensions
    _width = -1;
    _height = -1;


    _minimized = XTools::checkIfWindowMinimized(_clientWindow);


    XRenderPictureAttributes pa;
    pa.subwindow_mode = IncludeInferiors;

    _clientPict = XRenderCreatePicture(_dpy, _clientWindow, XTools::xrenderFormat(), CPSubwindowMode, &pa);
}
Ejemplo n.º 30
0
gboolean embed_icon(TrayWindow *traywin)
{
	if (systray_profile)
		fprintf(stderr,
		        "[%f] %s:%d win = %lu (%s)\n",
		        profiling_get_time(),
		        __FUNCTION__,
		        __LINE__,
		        traywin->win,
		        traywin->name);
	if (traywin->embedded)
		return TRUE;

	Panel *panel = systray.area.panel;

	XSync(server.display, False);
	error = FALSE;
	XErrorHandler old = XSetErrorHandler(window_error_handler);

	if (0) {
		Atom acttype;
		int actfmt;
		unsigned long nbitem, bytes;
		unsigned long *data = 0;
		int ret;

		if (systray_profile)
			fprintf(stderr,
					"XGetWindowProperty(server.display, traywin->win, server.atom._XEMBED_INFO, 0, 2, False, "
			        "server.atom._XEMBED_INFO, &acttype, &actfmt, &nbitem, &bytes, &data)\n");
		ret = XGetWindowProperty(server.display,
		                         traywin->win,
		                         server.atom._XEMBED_INFO,
		                         0,
		                         2,
		                         False,
		                         server.atom._XEMBED_INFO,
		                         &acttype,
		                         &actfmt,
		                         &nbitem,
		                         &bytes,
		                         (unsigned char **)&data);
		if (ret == Success) {
			if (data) {
				if (nbitem >= 2) {
					int hide = ((data[1] & XEMBED_MAPPED) == 0);
					if (hide) {
						// In theory we have to check the embedding with this and remove icons that refuse embedding.
						// In practice we have no idea when the other application processes the event and accepts the
						// embed so we cannot check now without a race.
						// Race can be triggered with PyGtk(2) apps.
						// We could defer this for later (if we set PropertyChangeMask in XSelectInput we get notified)
						// but for some reason it breaks transparency for Qt icons. So we don't.
						// fprintf(stderr, RED "tint2: window refused embedding" RESET "\n");
						// remove_icon(traywin);
						// XFree(data);
						// return FALSE;
					}
				}
				XFree(data);
			}
		} else {
			fprintf(stderr, RED "tint2 : xembed error" RESET "\n");
			remove_icon(traywin);
			return FALSE;
		}
	}

	// Redirect rendering when using compositing
	if (systray_composited) {
		if (systray_profile)
			fprintf(stderr, "XDamageCreate(server.display, traywin->parent, XDamageReportRawRectangles)\n");
		traywin->damage = XDamageCreate(server.display, traywin->parent, XDamageReportRawRectangles);
		if (systray_profile)
			fprintf(stderr, "XCompositeRedirectWindow(server.display, traywin->parent, CompositeRedirectManual)\n");
		XCompositeRedirectWindow(server.display, traywin->parent, CompositeRedirectManual);
	}

	XRaiseWindow(server.display, traywin->win);

	// Make the icon visible
	if (systray_profile)
		fprintf(stderr, "XMapWindow(server.display, traywin->win)\n");
	XMapWindow(server.display, traywin->win);
	if (!panel->is_hidden) {
		if (systray_profile)
			fprintf(stderr, "XMapRaised(server.display, traywin->parent)\n");
		XMapRaised(server.display, traywin->parent);
	}

	if (systray_profile)
		fprintf(stderr, "XSync(server.display, False)\n");
	XSync(server.display, False);
	XSetErrorHandler(old);
	if (error != FALSE) {
		fprintf(stderr,
		        RED "systray %d: cannot embed icon for window %lu (%s) parent %lu pid %d" RESET "\n",
		        __LINE__,
		        traywin->win,
		        traywin->name,
		        traywin->parent,
		        traywin->pid);
		remove_icon(traywin);
		return FALSE;
	}

	traywin->embedded = TRUE;

	if (systray_profile)
		fprintf(stderr,
		        "[%f] %s:%d win = %lu (%s)\n",
		        profiling_get_time(),
		        __FUNCTION__,
		        __LINE__,
		        traywin->win,
		        traywin->name);

	return TRUE;
}