コード例 #1
0
ファイル: ws.c プロジェクト: Gamer125/wiibrowser
/**
 * @brief Set differently sized icons to a window.
 *
 *        This function sets the X icon hint as well as
 *        the properties KWM_WIN_ICON and _NET_WM_ICON.
 *
 * @param dpy display
 * @param win window
 * @param icon pointer to the icons
 */
void wsSetIcon(Display *dpy, Window win, guiIcon_t *icon)
{
    XWMHints *wm;
    Atom iconatom;
    long data[2];

    if (icon->normal) {
        wm = XGetWMHints(dpy, win);

        if (!wm)
            wm = XAllocWMHints();

        wm->icon_pixmap = icon->normal;
        wm->icon_mask   = icon->normal_mask;
        wm->flags      |= IconPixmapHint | IconMaskHint;

        XSetWMHints(dpy, win, wm);
        XFree(wm);
    }

    if (icon->small || icon->normal) {
        iconatom = XInternAtom(dpy, "KWM_WIN_ICON", False);
        data[0]  = (icon->small ? icon->small : icon->normal);
        data[1]  = (icon->small ? icon->small_mask : icon->normal_mask);

        XChangeProperty(dpy, win, iconatom, iconatom, 32, PropModeReplace, (unsigned char *)data, 2);
    }

    if (icon->collection) {
        iconatom = XInternAtom(dpy, "_NET_WM_ICON", False);
        XChangeProperty(dpy, win, iconatom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)icon->collection, icon->collection_size);
    }
}
コード例 #2
0
static void wxgtk_window_set_urgency_hint (GtkWindow *win,
                                           gboolean setting)
{
#if GTK_CHECK_VERSION(2,7,0)
    if (gtk_check_version(2,7,0) == NULL)
        gtk_window_set_urgency_hint(win, setting);
    else
#endif
    {
#ifdef GDK_WINDOWING_X11
        GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(win));
        wxCHECK_RET(window, "wxgtk_window_set_urgency_hint: GdkWindow not realized");

        Display* dpy = GDK_WINDOW_XDISPLAY(window);
        Window xid = GDK_WINDOW_XID(window);
        XWMHints* wm_hints = XGetWMHints(dpy, xid);

        if (!wm_hints)
            wm_hints = XAllocWMHints();

        if (setting)
            wm_hints->flags |= XUrgencyHint;
        else
            wm_hints->flags &= ~XUrgencyHint;

        XSetWMHints(dpy, xid, wm_hints);
        XFree(wm_hints);
#endif // GDK_WINDOWING_X11
    }
}
コード例 #3
0
ファイル: WindowImplX11.cpp プロジェクト: AwkwardDev/MangosFX
////////////////////////////////////////////////////////////
/// /see WindowImpl::SetIcon
////////////////////////////////////////////////////////////
void WindowImplX11::SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels)
{
    // X11 wants BGRA pixels : swap red and blue channels
    // Note : this memory will never be freed, but it seems to cause a bug on exit if I do so
    Uint8* IconPixels = new Uint8[Width * Height * 4];
    for (std::size_t i = 0; i < Width * Height; ++i)
    {
        IconPixels[i * 4 + 0] = Pixels[i * 4 + 2];
        IconPixels[i * 4 + 1] = Pixels[i * 4 + 1];
        IconPixels[i * 4 + 2] = Pixels[i * 4 + 0];
        IconPixels[i * 4 + 3] = Pixels[i * 4 + 3];
    }

    // Create the icon pixmap
    Visual*      DefVisual = DefaultVisual(ourDisplay, ourScreen);
    unsigned int DefDepth  = DefaultDepth(ourDisplay, ourScreen);
    XImage* IconImage = XCreateImage(ourDisplay, DefVisual, DefDepth, ZPixmap, 0, (char*)IconPixels, Width, Height, 32, 0);
    if (!IconImage)
    {
        std::cerr << "Failed to set the window's icon" << std::endl;
        return;
    }
    Pixmap IconPixmap = XCreatePixmap(ourDisplay, RootWindow(ourDisplay, ourScreen), Width, Height, DefDepth);
    XGCValues Values;
    GC IconGC = XCreateGC(ourDisplay, IconPixmap, 0, &Values);
    XPutImage(ourDisplay, IconPixmap, IconGC, IconImage, 0, 0, 0, 0, Width, Height);
    XFreeGC(ourDisplay, IconGC);
    XDestroyImage(IconImage);

    // Create the mask pixmap (must have 1 bit depth)
    std::size_t Pitch = (Width + 7) / 8;
    static std::vector<Uint8> MaskPixels(Pitch * Height, 0);
    for (std::size_t j = 0; j < Height; ++j)
    {
        for (std::size_t i = 0; i < Pitch; ++i)
        {
            for (std::size_t k = 0; k < 8; ++k)
            {
                if (i * 8 + k < Width)
                {
                    Uint8 Opacity = (Pixels[(i * 8 + k + j * Width) * 4 + 3] > 0) ? 1 : 0;
                    MaskPixels[i + j * Pitch] |= (Opacity << k);                    
                }
            }
        }
    }
    Pixmap MaskPixmap = XCreatePixmapFromBitmapData(ourDisplay, myWindow, (char*)&MaskPixels[0], Width, Height, 1, 0, 1);

    // Send our new icon to the window through the WMHints
    XWMHints* Hints = XAllocWMHints();
    Hints->flags       = IconPixmapHint | IconMaskHint;
    Hints->icon_pixmap = IconPixmap;
    Hints->icon_mask   = MaskPixmap;
    XSetWMHints(ourDisplay, myWindow, Hints);
    XFree(Hints);

    XFlush(ourDisplay);
}
コード例 #4
0
ファイル: ecore_x_icccm.c プロジェクト: jigpu/efl
EAPI void
ecore_x_icccm_hints_set(Ecore_X_Window win,
                        Eina_Bool accepts_focus,
                        Ecore_X_Window_State_Hint initial_state,
                        Ecore_X_Pixmap icon_pixmap,
                        Ecore_X_Pixmap icon_mask,
                        Ecore_X_Window icon_window,
                        Ecore_X_Window window_group,
                        Eina_Bool is_urgent)
{
   XWMHints *hints;

   hints = XAllocWMHints();
   if (!hints)
     return;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   hints->flags = InputHint | StateHint;
   hints->input = accepts_focus;
   if (initial_state == ECORE_X_WINDOW_STATE_HINT_WITHDRAWN)
     hints->initial_state = WithdrawnState;
   else if (initial_state == ECORE_X_WINDOW_STATE_HINT_NORMAL)
     hints->initial_state = NormalState;
   else if (initial_state == ECORE_X_WINDOW_STATE_HINT_ICONIC)
     hints->initial_state = IconicState;

   if (icon_pixmap != 0)
     {
        hints->icon_pixmap = icon_pixmap;
        hints->flags |= IconPixmapHint;
     }

   if (icon_mask != 0)
     {
        hints->icon_mask = icon_mask;
        hints->flags |= IconMaskHint;
     }

   if (icon_window != 0)
     {
        hints->icon_window = icon_window;
        hints->flags |= IconWindowHint;
     }

   if (window_group != 0)
     {
        hints->window_group = window_group;
        hints->flags |= WindowGroupHint;
     }

   if (is_urgent)
     hints->flags |= XUrgencyHint;

   XSetWMHints(_ecore_x_disp, win, hints);
   if (_ecore_xlib_sync) ecore_x_sync();
   XFree(hints);
}
コード例 #5
0
int main () {
  Display   *display;
  Window     main, grouptran, child, group;
  XEvent     report;
  XWMHints  *wmhints;

  display = XOpenDisplay(NULL);

  if (display == NULL) {
    fprintf(stderr, "couldn't connect to X server :0\n");
    return 0;
  }

  group = XCreateWindow(display, RootWindow(display, 0),
                        0,0,1,1, 10, CopyFromParent, CopyFromParent,
			 CopyFromParent, 0, 0);

  main = XCreateWindow(display, RootWindow(display, 0),
                      0,0,100,100, 10, CopyFromParent, CopyFromParent,
			 CopyFromParent, 0, 0);
  grouptran = XCreateWindow(display, RootWindow(display, 0),
                            10,10,80,180, 10, CopyFromParent, CopyFromParent,
                            CopyFromParent, 0, 0);
  child = XCreateWindow(display, RootWindow(display, 0),
                        20,20,60,60, 10, CopyFromParent, CopyFromParent,
                        CopyFromParent, 0, 0);

  XSetWindowBackground(display,main,WhitePixel(display,0));
  XSetWindowBackground(display,grouptran,BlackPixel(display,0));
  XSetWindowBackground(display,child,WhitePixel(display,0));

  XSetTransientForHint(display, grouptran, RootWindow(display,0));
  XSetTransientForHint(display, child, grouptran);

  wmhints = XAllocWMHints();

  wmhints->flags = WindowGroupHint;
  wmhints->window_group = group;

  XSetWMHints(display, main, wmhints);
  XSetWMHints(display, grouptran, wmhints);
  XSetWMHints(display, child, wmhints);

  XFree(wmhints);

  XMapWindow(display, main);
  XMapWindow(display, grouptran);
  XMapWindow(display, child);
  XFlush(display);

  while (1) {
    XNextEvent(display, &report);
  }

  return 1;
}
コード例 #6
0
KPagerMainWindow::KPagerMainWindow(QWidget *parent, const char *name)
	: DCOPObject("KPagerIface"), KMainWindow(parent, name)
{
    m_reallyClose=false;

    m_pPager = new KPager(this, 0);
    setCentralWidget(m_pPager);

    KConfig *cfg = kapp->config();
    cfg->setGroup("KPager");

    // Update the last used geometry
    int w = cfg->readNumEntry(m_pPager->lWidth(),-1);
    int h = cfg->readNumEntry(m_pPager->lHeight(),-1);
    if (w > 0 && h > 0)
        resize(w,h);
    else
        resize(m_pPager->sizeHint());
    //  resize(cfg->readNumEntry(lWidth(),200),cfg->readNumEntry(lHeight(),90));

    int xpos=cfg->readNumEntry("xPos",-1);
    int ypos=cfg->readNumEntry("yPos",-1);
    if (xpos > 0 && ypos > 0)
      move(xpos,ypos);
    else
    {
//      NETRootInfo ri( qt_xdisplay(), NET::WorkArea );
//      NETRect rect=ri.workArea(1);
//      move(rect.pos.x+rect.size.width-m_pPager->width(),
//	  rect.pos.y+rect.size.height-m_pPager->height());
// antonio:The above lines don't work. I should look at them when I have
// more time
        move(kapp->desktop()->width()-m_pPager->sizeHint().width()-5,kapp->desktop()->height()-m_pPager->sizeHint().height()-25);
    }

    // Set the wm flags to this window
    KWin::setState( winId(), NET::StaysOnTop | NET::SkipTaskbar | NET::Sticky | NET::SkipPager );
    KWin::setOnAllDesktops( winId(), true);
    if ( KWin::windowInfo( winId(), NET::WMWindowType, 0 ).windowType(NET::Normal) == NET::Normal )
    {
       KWin::setType( winId(), NET::Utility );
    }

    XWMHints *hints = XGetWMHints(x11Display(), winId());
    if( hints == NULL )
        hints = XAllocWMHints();
    hints->input = false;
    hints->flags |= InputHint;
    XSetWMHints(x11Display(), winId(), hints);
    XFree(reinterpret_cast<char *>(hints));

    timeout=new QTimer(this,"timeoutToQuit");
    connect(timeout,SIGNAL(timeout()),this, SLOT(reallyClose()));
}
コード例 #7
0
ファイル: piglit-glx-util.c プロジェクト: blaztinn/piglit
void
piglit_glx_window_set_no_input(Display *dpy, GLXDrawable win)
{
	XWMHints *hints;
	hints = XAllocWMHints();
	hints->flags |= InputHint;
	hints->input = False;

	XSetWMHints(dpy, win, hints);

	XFree(hints);
}
コード例 #8
0
ファイル: wm.C プロジェクト: KrisChaplin/octeon_toolchain-4.1
void wm_set_icon(Display *display, Window shell, Pixmap icon, Pixmap mask)
{
    XWMHints *wm_hints = XAllocWMHints();

    wm_hints->flags       = IconPixmapHint | IconMaskHint;
    wm_hints->icon_pixmap = icon;
    wm_hints->icon_mask   = mask;

    XSetWMHints(display, shell, wm_hints);

    XFree((void *)wm_hints);
}
コード例 #9
0
ファイル: x_window.cpp プロジェクト: KarlHegbloom/texmacs
void
x_window_rep::set_hints (int min_w, int min_h, int max_w, int max_h) {
  XSizeHints* size_hints;
  XWMHints*   wm_hints;
  XClassHint* class_hints;
  ASSERT (size_hints= XAllocSizeHints (), "out of memory (X server)");
  ASSERT (wm_hints= XAllocWMHints (), "out of memory (X server)");
  ASSERT (class_hints= XAllocClassHint (), "out of memory (X server)");

  XTextProperty Window_Name;
  XTextProperty Icon_Name;
  ASSERT (XStringListToTextProperty (&name, 1, &Window_Name) != 0,
	  "out of memory (X server)");
  ASSERT (XStringListToTextProperty (&name, 1, &Icon_Name) != 0,
	  "out of memory (X server)");

  // time_t start_1= texmacs_time ();
  Pixmap pm= retrieve_pixmap (load_xpm ("TeXmacs.xpm"));
  // cout << "Getting pixmap required " << (texmacs_time ()-start_1) << " ms\n";

  // time_t start_2= texmacs_time ();
  size_hints->flags       = PPosition | PSize | PMinSize | PMaxSize;
  size_hints->min_width   = min_w;
  size_hints->min_height  = min_h;
  size_hints->max_width   = max_w;
  size_hints->max_height  = max_h;
  wm_hints->initial_state = NormalState;
  wm_hints->input         = true;
  wm_hints->icon_pixmap   = pm;
  wm_hints->flags         = StateHint | IconPixmapHint | InputHint;
  class_hints->res_name   = name;
  class_hints->res_class  = name;

  XSetWMProperties (
    dpy,
    win,
    &Window_Name,
    &Icon_Name,
    gui->argv,
    gui->argc,
    size_hints,
    wm_hints,
    class_hints
  );

  XFree(size_hints);
  XFree(wm_hints);
  XFree(class_hints);
  XFree(Window_Name.value);
  XFree(Icon_Name.value);
  // cout << "Setting hints required " << (texmacs_time ()-start_2) << " ms\n";
}
コード例 #10
0
static void updateWindowHints(JNIEnv *env, Display *disp, Window window) {
	XWMHints* win_hints = XAllocWMHints();
	if (win_hints == NULL) {
		throwException(env, "XAllocWMHints failed");
		return;
	}

	win_hints->flags = InputHint;
	win_hints->input = True;

	XSetWMHints(disp, window, win_hints);
	XFree(win_hints);
	XFlush(disp);
}
コード例 #11
0
ファイル: glut_win.cpp プロジェクト: astrofimov/vgallium
/* CENTRY */
int GLUTAPIENTRY
glutCreateWindow(const char *title)
{
  static int firstWindow = 1;
  GLUTwindow *window;
#if !defined(_WIN32) && !defined(__OS2__)
  XWMHints *wmHints;
#endif
  Window win;
  XTextProperty textprop;

  if (__glutGameModeWindow) {
    __glutFatalError("cannot create windows in game mode.");
  }
  window = __glutCreateWindow(NULL,
    __glutSizeHints.x, __glutSizeHints.y,
    __glutInitWidth, __glutInitHeight,
    /* not game mode */ 0);
  win = window->win;
  /* Setup ICCCM properties. */
  textprop.value = (unsigned char *) title;
  textprop.encoding = XA_STRING;
  textprop.format = 8;
  textprop.nitems = strlen(title);
#if defined(__OS2__)
  WinSetWindowText(window->frame, (PCSZ)title);
  if (__glutIconic) {
    window->desiredMapState = IconicState;
  }
#elif defined(_WIN32)
  SetWindowText(win, title);
  if (__glutIconic) {
    window->desiredMapState = IconicState;
  }
#else
  wmHints = XAllocWMHints();
  wmHints->initial_state =
    __glutIconic ? IconicState : NormalState;
  wmHints->flags = StateHint;
  XSetWMProperties(__glutDisplay, win, &textprop, &textprop,
  /* Only put WM_COMMAND property on first window. */
    firstWindow ? __glutArgv : NULL,
    firstWindow ? __glutArgc : 0,
    &__glutSizeHints, wmHints, NULL);
  XFree(wmHints);
  XSetWMProtocols(__glutDisplay, win, &__glutWMDeleteWindow, 1);
#endif
  firstWindow = 0;
  return window->num + 1;
}
コード例 #12
0
ファイル: glut_win.c プロジェクト: linghushaoxia/glut
/* CENTRY */
int GLUTAPIENTRY
glutCreateWindow(const char *title)
{
    static int firstWindow = 1;
    GLUTwindow *window;
#if !defined(_WIN32)
    XWMHints *wmHints;
#endif
    Window win;
    XTextProperty textprop;
    const char **pvalue = (const char**) &textprop.value;  // See below for why...

    if (__glutGameModeWindow) {
        __glutFatalError("cannot create windows in game mode.");
    }
    window = __glutCreateWindow(NULL,
                                __glutSizeHints.x, __glutSizeHints.y,
                                __glutInitWidth, __glutInitHeight,
                                /* not game mode */ 0);
    win = window->win;
    /* Setup ICCCM properties. */
    *pvalue = title; /* We want to write "textprop.value = (unsigned char *) title;"
                      but gcc complains about discarding const-ness of pointer */
    assert(!strcmp((const char*)textprop.value, title));
    textprop.encoding = XA_STRING;
    textprop.format = 8;
    textprop.nitems = (unsigned long)strlen(title);
#if defined(_WIN32)
    SetWindowText(win, title);
    if (__glutIconic) {
        window->desiredMapState = IconicState;
    }
#else
    wmHints = XAllocWMHints();
    wmHints->initial_state =
        __glutIconic ? IconicState : NormalState;
    wmHints->flags = StateHint;
    XSetWMProperties(__glutDisplay, win, &textprop, &textprop,
                     /* Only put WM_COMMAND property on first window. */
                     firstWindow ? __glutArgv : NULL,
                     firstWindow ? __glutArgc : 0,
                     &__glutSizeHints, wmHints, NULL);
    XFree(wmHints);
    XSetWMProtocols(__glutDisplay, win, &__glutWMDeleteWindow, 1);
#endif
    firstWindow = 0;
    return window->num + 1;
}
コード例 #13
0
static int __X_syspopup_disable_focus(Display *dpy, Window win)
{
	XWMHints *hints;

	hints = XAllocWMHints();
	if (!hints) return -1;

	hints->flags = InputHint | StateHint;
	hints->input = 0;
	hints->initial_state = NormalState;

	XSetWMHints(dpy, win, hints);
	XFree(hints);

	return 0;
}
コード例 #14
0
ファイル: kwm.cpp プロジェクト: kthxbyte/KDE1-Linaro
void KWM::setIcon(Window w, const QPixmap &pm){
  XWMHints *hints = XGetWMHints(qt_xdisplay(), w);
  if (!hints)
    hints = XAllocWMHints();
  QPixmap *p = new QPixmap;
  *p = pm;
  hints->icon_pixmap=p->handle();
  hints->flags |= IconPixmapHint;
  if(p->mask()){
    hints->icon_mask = p->mask()->handle();
    hints->flags |= IconMaskHint;
  }
  else
    hints->flags &= ~IconMaskHint;
  XSetWMHints( qt_xdisplay(), w, hints );
  XFree((char*)hints);
  delete p;
}
コード例 #15
0
ファイル: toplevel.cpp プロジェクト: CobaltBlues/wxWidgets
static void wxgtk_window_set_urgency_hint (GtkWindow *win,
                                           gboolean setting)
{
    wxASSERT_MSG( GTK_WIDGET_REALIZED(win), wxT("wxgtk_window_set_urgency_hint: GdkWindow not realized") );
    GdkWindow *window = GTK_WIDGET(win)->window;
    XWMHints *wm_hints;

    wm_hints = XGetWMHints(GDK_WINDOW_XDISPLAY(window), GDK_WINDOW_XWINDOW(window));

    if (!wm_hints)
        wm_hints = XAllocWMHints();

    if (setting)
        wm_hints->flags |= XUrgencyHint;
    else
        wm_hints->flags &= ~XUrgencyHint;

    XSetWMHints(GDK_WINDOW_XDISPLAY(window), GDK_WINDOW_XWINDOW(window), wm_hints);
    XFree(wm_hints);
}
コード例 #16
0
ファイル: piglit_x11_framework.c プロジェクト: RAOF/piglit
static void
show_window(struct piglit_winsys_framework *winsys_fw)
{
	struct piglit_x11_framework *x11_fw = piglit_x11_framework(&winsys_fw->wfl_fw.gl_fw);
	struct piglit_wfl_framework *wfl_fw = &winsys_fw->wfl_fw;
	XWMHints *wm_hints;

	get_native(x11_fw);

	if (piglit_automatic) {
		/* Prevent the window from grabbing input. */
		wm_hints = XAllocWMHints();
		wm_hints->flags |= InputHint;
		wm_hints->input = False;
		XSetWMHints(x11_fw->display, x11_fw->window, wm_hints);
		XFree(wm_hints);
	}

	waffle_window_show(wfl_fw->window);
}
コード例 #17
0
ファイル: qt4.cpp プロジェクト: TheSLinux-forks/uim
KUimCharDict::KUimCharDict( QWidget *parent )
        : QWidget( parent )
{
#ifdef Q_WS_X11
    // Don't give input focus to this window.
    XWMHints *wmhints = XGetWMHints( QX11Info::display(), winId() );
    if ( !wmhints )
        wmhints = XAllocWMHints();
    wmhints->flags = InputHint;
    wmhints->input = False;
    XSetWMHints( QX11Info::display(), winId(), wmhints );
    XFree( wmhints );
#endif

    setupWidgets();

    readConfig();

    uim_fd = uim_helper_init_client_fd( 0 );
}
コード例 #18
0
ファイル: toplevel.cpp プロジェクト: chromylei/third_party
void wxTopLevelWindowX11::DoSetIcon(const wxIcon& icon)
{
    if (icon.IsOk() && X11GetMainWindow())
    {
#if !wxUSE_NANOX
        XWMHints *wmHints = XAllocWMHints();
        wmHints->icon_pixmap = (Pixmap) icon.GetPixmap();

        wmHints->flags = IconPixmapHint;

        if (icon.GetMask())
        {
            wmHints->flags |= IconMaskHint;
            wmHints->icon_mask = (Pixmap) icon.GetMask()->GetBitmap();
        }

        XSetWMHints(wxGlobalDisplay(), (Window) X11GetMainWindow(), wmHints);
        XFree(wmHints);
#endif
    }
}
コード例 #19
0
ファイル: xdisplay.c プロジェクト: billyquith/allegro5
static void set_initial_icon(Display *x11display, Window window)
{
#ifdef ALLEGRO_XWINDOWS_WITH_XPM
   XWMHints *wm_hints;

   if (x11_xpm == NULL)
      return;

   wm_hints = XAllocWMHints();

   wm_hints->flags |= IconPixmapHint | IconMaskHint;
   XpmCreatePixmapFromData(x11display, window, x11_xpm,
      &wm_hints->icon_pixmap, &wm_hints->icon_mask, NULL);

   XSetWMHints(x11display, window, wm_hints);
   XFree(wm_hints);
#else
   (void)x11display;
   (void)window;
#endif
}
コード例 #20
0
void VID_SetWindowTitle( Window win, char *pszName )
{
	XTextProperty	textprop;
	XWMHints		*wmHints;

    // Setup ICCCM properties
    textprop.value = (unsigned char *)pszName;
    textprop.encoding = XA_STRING;
    textprop.format = 8;
    textprop.nitems = strlen(pszName);
    wmHints = XAllocWMHints();
    wmHints->initial_state = NormalState;
    wmHints->flags = StateHint;
    XSetWMProperties( x_disp, win, &textprop, &textprop,
					  // Only put WM_COMMAND property on first window.
					  com_argv, com_argc, NULL, NULL, NULL );
    XFree( wmHints );

    aWMDelete = XInternAtom( x_disp, "WM_DELETE_WINDOW", False );
    XSetWMProtocols( x_disp, win, &aWMDelete, 1 );
}
コード例 #21
0
ファイル: wtest.c プロジェクト: crmafra/wmaker
static void newwin(void *foo, int item, Time time)
{
	Window win;
	XClassHint classhint;
	char title[100];

	wincount++;
	win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10 * wincount, 10 * wincount, 200, 100, 0, 0, 0);
	prots[0] = delete_win;
	prots[1] = miniaturize_win;
	XSetWMProtocols(dpy, win, prots, 2);
	sprintf(title, "Test Window %i", wincount);
	XStoreName(dpy, win, title);

	/* set class hint */
	classhint.res_name = "test";
	classhint.res_class = "Test";
	XSetClassHint(dpy, win, &classhint);

	/* set WindowMaker hints */
	attr.flags = GSMiniaturizePixmapAttr | GSMiniaturizeMaskAttr;
	attr.miniaturize_pixmap = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), bits, 10, 10);

	attr.miniaturize_mask = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), mbits, 10, 10);
	/*
	   attr.flags |= GSWindowStyleAttr;
	   attr.window_style = NSTitledWindowMask|NSClosableWindowMask;
	 */

	WMSetWindowAttributes(dpy, win, &attr);

	hints = XAllocWMHints();
	/* set window group leader */
	hints->window_group = leader;
	hints->flags = WindowGroupHint;
	XSetWMHints(dpy, win, hints);

	WMAppAddWindow(app, win);
	XMapWindow(dpy, win);
}
コード例 #22
0
/* CENTRY */
int APIENTRY
glutCreateWindow(const char *title)
{
  static int firstWindow = 1;
  GLUTwindow *window;
#if !defined(WIN32)
  XWMHints *wmHints;
#endif
  Window win;
  XTextProperty textprop;

  window = __glutCreateWindow(NULL,
    __glutSizeHints.x, __glutSizeHints.y,
    __glutInitWidth, __glutInitHeight);
  win = window->win;
  /* Setup ICCCM properties. */
  textprop.value = (unsigned char *) title;
  textprop.encoding = XA_STRING;
  textprop.format = 8;
  textprop.nitems = strlen(title);
#if defined(WIN32)
  SetWindowText(win, title);
  if (__glutIconic)
    ShowWindow(win, SW_MINIMIZE);
#else
  wmHints = XAllocWMHints();
  wmHints->initial_state =
    __glutIconic ? IconicState : NormalState;
  wmHints->flags = StateHint;
  XSetWMProperties(__glutDisplay, win, &textprop, &textprop,
  /* Only put WM_COMMAND property on first window. */
    firstWindow ? __glutArgv : NULL,
    firstWindow ? __glutArgc : 0,
    &__glutSizeHints, wmHints, NULL);
  XFree(wmHints);
  XSetWMProtocols(__glutDisplay, win, &__glutWMDeleteWindow, 1);
#endif
  firstWindow = 0;
  return window->num + 1;
}
コード例 #23
0
static void updateWindowHints(JNIEnv *env, Display *disp, Window window) {
	XWMHints* win_hints = XAllocWMHints();
	if (win_hints == NULL) {
		throwException(env, "XAllocWMHints failed");
		return;
	}

	win_hints->flags = InputHint;
	win_hints->input = True;
	if (current_icon_pixmap != 0) {
		win_hints->flags |= IconPixmapHint;
		win_hints->icon_pixmap = current_icon_pixmap;
	}
	if (current_icon_mask_pixmap != 0) {
		win_hints->flags |= IconMaskHint;
		win_hints->icon_mask = current_icon_mask_pixmap;
	}

	XSetWMHints(disp, window, win_hints);
	XFree(win_hints);
	XFlush(disp);
}
コード例 #24
0
ファイル: ws.c プロジェクト: NeeMeese/mplayer-ce
void wsSetIcon( Display * dsp,Window win,Pixmap icon,Pixmap mask )
{
 XWMHints * wm;
 long	    data[2];
 Atom	    iconatom;

 wm=XGetWMHints( dsp,win );
 if ( !wm ) wm=XAllocWMHints();

 wm->icon_pixmap=icon;
 wm->icon_mask=mask;
 wm->flags|=IconPixmapHint | IconMaskHint;

 XSetWMHints( dsp,win,wm );

 data[0]=icon;
 data[1]=mask;
 iconatom=XInternAtom( dsp,"KWM_WIN_ICON",0 );
 XChangeProperty( dsp,win,iconatom,iconatom,32,PropModeReplace,(unsigned char *)data,2 );

 XFree( wm );
}
コード例 #25
0
ファイル: x11_window.c プロジェクト: Ape/DCPUToolchain
static GLboolean createWindow(_GLFWwindow* window,
			      const _GLFWwndconfig* wndconfig)
{
    unsigned long wamask;
    XSetWindowAttributes wa;
    XVisualInfo* visual = _glfwGetContextVisual(window);

    // Every window needs a colormap
    // Create one based on the visual used by the current context
    // TODO: Decouple this from context creation

    window->X11.colormap = XCreateColormap(_glfwLibrary.X11.display,
					   _glfwLibrary.X11.root,
					   visual->visual,
					   AllocNone);

    // Create the actual window
    {
	wamask = CWBorderPixel | CWColormap | CWEventMask;

	wa.colormap = window->X11.colormap;
	wa.border_pixel = 0;
	wa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask |
	    PointerMotionMask | ButtonPressMask | ButtonReleaseMask |
	    ExposureMask | FocusChangeMask | VisibilityChangeMask |
	    EnterWindowMask | LeaveWindowMask;

	if (wndconfig->mode == GLFW_WINDOWED)
	{
	    // The /only/ reason for setting the background pixel here is that
	    // otherwise our window won't get any decorations on systems using
	    // certain versions of Compiz on Intel hardware
	    wa.background_pixel = BlackPixel(_glfwLibrary.X11.display,
					     _glfwLibrary.X11.screen);
	    wamask |= CWBackPixel;
	}

	window->X11.handle = XCreateWindow(_glfwLibrary.X11.display,
					   _glfwLibrary.X11.root,
					   0, 0,	   // Position
					   window->width, window->height,
					   0,		   // Border width
					   visual->depth,  // Color depth
					   InputOutput,
					   visual->visual,
					   wamask,
					   &wa);

	if (!window->X11.handle)
	{
	    // TODO: Handle all the various error codes here and translate them
	    // to GLFW errors

	    _glfwSetError(GLFW_PLATFORM_ERROR, "X11: Failed to create window");
	    return GL_FALSE;
	}
    }

    if (window->mode == GLFW_FULLSCREEN && !_glfwLibrary.X11.hasEWMH)
    {
	// This is the butcher's way of removing window decorations
	// Setting the override-redirect attribute on a window makes the window
	// manager ignore the window completely (ICCCM, section 4)
	// The good thing is that this makes undecorated fullscreen windows
	// easy to do; the bad thing is that we have to do everything manually
	// and some things (like iconify/restore) won't work at all, as those
	// are tasks usually performed by the window manager

	XSetWindowAttributes attributes;
	attributes.override_redirect = True;
	XChangeWindowAttributes(_glfwLibrary.X11.display,
				window->X11.handle,
				CWOverrideRedirect,
				&attributes);

	window->X11.overrideRedirect = GL_TRUE;
    }

    // Find or create the protocol atom for window close notifications
    _glfwLibrary.X11.wmDeleteWindow = XInternAtom(_glfwLibrary.X11.display,
						  "WM_DELETE_WINDOW",
						  False);

    // Declare the WM protocols supported by GLFW
    {
	int count = 0;
	Atom protocols[2];

	// The WM_DELETE_WINDOW ICCCM protocol
	// Basic window close notification protocol
	if (_glfwLibrary.X11.wmDeleteWindow != None)
	    protocols[count++] = _glfwLibrary.X11.wmDeleteWindow;

	// The _NET_WM_PING EWMH protocol
	// Tells the WM to ping the GLFW window and flag the application as
	// unresponsive if the WM doesn't get a reply within a few seconds
	if (_glfwLibrary.X11.wmPing != None)
	    protocols[count++] = _glfwLibrary.X11.wmPing;

	if (count > 0)
	{
	    XSetWMProtocols(_glfwLibrary.X11.display, window->X11.handle,
			    protocols, count);
	}
    }

    // Set ICCCM WM_HINTS property
    {
	XWMHints* hints = XAllocWMHints();
	if (!hints)
	{
	    _glfwSetError(GLFW_OUT_OF_MEMORY,
			  "X11: Failed to allocate WM hints");
	    return GL_FALSE;
	}

	hints->flags = StateHint;
	hints->initial_state = NormalState;

	XSetWMHints(_glfwLibrary.X11.display, window->X11.handle, hints);
	XFree(hints);
    }

    // Set ICCCM WM_NORMAL_HINTS property (even if no parts are set)
    {
	XSizeHints* hints = XAllocSizeHints();
	if (!hints)
	{
	    _glfwSetError(GLFW_OUT_OF_MEMORY,
			  "X11: Failed to allocate size hints");
	    return GL_FALSE;
	}

	hints->flags = 0;

	if (!wndconfig->resizable)
	{
	    hints->flags |= (PMinSize | PMaxSize);
	    hints->min_width  = hints->max_width  = window->width;
	    hints->min_height = hints->max_height = window->height;
	}

	XSetWMNormalHints(_glfwLibrary.X11.display, window->X11.handle, hints);
	XFree(hints);
    }

    _glfwPlatformSetWindowTitle(window, wndconfig->title);

    return GL_TRUE;
}
コード例 #26
0
ファイル: x11_window.c プロジェクト: NathanSweet/glfw
// Create the X11 window (and its colormap)
//
static GLboolean createWindow(_GLFWwindow* window,
                              const _GLFWwndconfig* wndconfig)
{
    unsigned long wamask;
    XSetWindowAttributes wa;
    XVisualInfo* visual = _GLFW_X11_CONTEXT_VISUAL;

    // Every window needs a colormap
    // Create one based on the visual used by the current context
    // TODO: Decouple this from context creation

    window->x11.colormap = XCreateColormap(_glfw.x11.display,
                                           _glfw.x11.root,
                                           visual->visual,
                                           AllocNone);

    // Create the actual window
    {
        wamask = CWBorderPixel | CWColormap | CWEventMask;

        wa.colormap = window->x11.colormap;
        wa.border_pixel = 0;
        wa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask |
                        PointerMotionMask | ButtonPressMask | ButtonReleaseMask |
                        ExposureMask | FocusChangeMask | VisibilityChangeMask |
                        EnterWindowMask | LeaveWindowMask | PropertyChangeMask;

        if (wndconfig->monitor == NULL)
        {
            // HACK: This is a workaround for windows without a background pixel
            // not getting any decorations on certain older versions of Compiz
            // running on Intel hardware
            wa.background_pixel = BlackPixel(_glfw.x11.display,
                                             _glfw.x11.screen);
            wamask |= CWBackPixel;
        }

        window->x11.handle = XCreateWindow(_glfw.x11.display,
                                           _glfw.x11.root,
                                           0, 0,
                                           wndconfig->width, wndconfig->height,
                                           0,              // Border width
                                           visual->depth,  // Color depth
                                           InputOutput,
                                           visual->visual,
                                           wamask,
                                           &wa);

        if (!window->x11.handle)
        {
            // TODO: Handle all the various error codes here and translate them
            // to GLFW errors

            _glfwInputError(GLFW_PLATFORM_ERROR, "X11: Failed to create window");
            return GL_FALSE;
        }

        if (wndconfig->undecorated) {
            Atom motif_hints_atom = XInternAtom(_glfw.x11.display, "_MOTIF_WM_HINTS", False);
            MotifWmHints motif_hints;
            motif_hints.flags = MWM_HINTS_DECORATIONS;
            motif_hints.decorations = 0;
            XChangeProperty(_glfw.x11.display, window->x11.handle,
                motif_hints_atom, motif_hints_atom, 32,
                PropModeReplace,
                (unsigned char *)&motif_hints, sizeof(MotifWmHints) / sizeof(long));
        }
    }

    if (window->monitor && !_glfw.x11.hasEWMH)
    {
        // This is the butcher's way of removing window decorations
        // Setting the override-redirect attribute on a window makes the window
        // manager ignore the window completely (ICCCM, section 4)
        // The good thing is that this makes undecorated fullscreen windows
        // easy to do; the bad thing is that we have to do everything manually
        // and some things (like iconify/restore) won't work at all, as those
        // are tasks usually performed by the window manager

        XSetWindowAttributes attributes;
        attributes.override_redirect = True;
        XChangeWindowAttributes(_glfw.x11.display,
                                window->x11.handle,
                                CWOverrideRedirect,
                                &attributes);

        window->x11.overrideRedirect = GL_TRUE;
    }

    // Declare the WM protocols supported by GLFW
    {
        int count = 0;
        Atom protocols[2];

        // The WM_DELETE_WINDOW ICCCM protocol
        // Basic window close notification protocol
        if (_glfw.x11.WM_DELETE_WINDOW != None)
            protocols[count++] = _glfw.x11.WM_DELETE_WINDOW;

        // The _NET_WM_PING EWMH protocol
        // Tells the WM to ping the GLFW window and flag the application as
        // unresponsive if the WM doesn't get a reply within a few seconds
        if (_glfw.x11.NET_WM_PING != None)
            protocols[count++] = _glfw.x11.NET_WM_PING;

        if (count > 0)
        {
            XSetWMProtocols(_glfw.x11.display, window->x11.handle,
                            protocols, count);
        }
    }

    // Set ICCCM WM_HINTS property
    {
        XWMHints* hints = XAllocWMHints();
        if (!hints)
        {
            _glfwInputError(GLFW_OUT_OF_MEMORY,
                            "X11: Failed to allocate WM hints");
            return GL_FALSE;
        }

        hints->flags = StateHint;
        hints->initial_state = NormalState;

        XSetWMHints(_glfw.x11.display, window->x11.handle, hints);
        XFree(hints);
    }

    // Set ICCCM WM_NORMAL_HINTS property (even if no parts are set)
    {
        XSizeHints* hints = XAllocSizeHints();
        hints->flags = 0;

        if (wndconfig->monitor)
        {
            hints->flags |= PPosition;
            _glfwPlatformGetMonitorPos(wndconfig->monitor, &hints->x, &hints->y);
        }

        if (!wndconfig->resizable)
        {
            hints->flags |= (PMinSize | PMaxSize);
            hints->min_width  = hints->max_width  = wndconfig->width;
            hints->min_height = hints->max_height = wndconfig->height;
        }

        XSetWMNormalHints(_glfw.x11.display, window->x11.handle, hints);
        XFree(hints);
    }

    if (_glfw.x11.xi2.available)
    {
        // Select for XInput2 events

        XIEventMask eventmask;
        unsigned char mask[] = { 0 };

        eventmask.deviceid = 2;
        eventmask.mask_len = sizeof(mask);
        eventmask.mask = mask;
        XISetMask(mask, XI_Motion);

        XISelectEvents(_glfw.x11.display, window->x11.handle, &eventmask, 1);
    }

    _glfwPlatformSetWindowTitle(window, wndconfig->title);

    XRRSelectInput(_glfw.x11.display, window->x11.handle,
                   RRScreenChangeNotifyMask);

    return GL_TRUE;
}
コード例 #27
0
void setWindowHints(Window win, char **argv, int argc, char *window_name,
                    char *icon_name, char *res_name, char *res_class)
{
  XSizeHints *size_hints;
  XWMHints *wm_hints;
  XClassHint *class_hints;
  XTextProperty windowName, iconName;

  XSelectInput(Spw_Dpy, win,
               ButtonPressMask | ButtonReleaseMask
               | KeyPressMask | KeyReleaseMask
               | ExposureMask 
               );

  /*
   * Allocate and set the the Size hints in a friendly way
   */

  if ( !(size_hints = XAllocSizeHints()) )
     {
     fprintf(stderr,"Not enough memory\n");
     exit(-1);
     }
  /*
   *  What things we will be setting.  Position and size refer to
   *  if the user set the values (via a resource file for example)
   *  or if the program set the values.
   */
  size_hints->flags = 
                      PPosition   | /* Program specified position      */
                      PSize       | /* Program specified size          */
                      PBaseSize   | /* Program specified base size     */
                      0;

  /*
   *  Now set the values.
   */
  size_hints->base_width = Spw_WindowWidth;
  size_hints->base_height = Spw_WindowHeight;
   
  /*
   * Allocate and set the the Window Manager hints in a friendly way.
   * This is probably the most critical to set correctly as some
   * WMs (olwm) are REALLY picky about setting them correctly and
   * hose you if you don't.  Like, for example, not sending you any
   * keypresses.
   */
  if ( !(wm_hints = XAllocWMHints()) )
     {
     fprintf(stderr,"Not enough memory\n");
     exit(-1);
     }

  /*
   *  What hints we will be setting
   */
  wm_hints->flags = InputHint        | /* Setting if we expect input  */
                    StateHint        | /* What initial state to be in */
                    IconPixmapHint   | /* Set the Icon pixmap         */
                    IconMaskHint     | /* Set the Icon Shape Mask     */
                    0;

  wm_hints->input = TRUE;                /* InputHint */
  wm_hints->initial_state = NormalState  /* or IconicState */; /* StateHint */

  wm_hints->icon_pixmap = XCreateBitmapFromData(Spw_Dpy,
                                                Spw_mainWindow,
                                                (char *)sbXcityfly_icon_bits,
                                                sbXcityfly_icon_width,
                                                sbXcityfly_icon_height);
  wm_hints->icon_mask = XCreateBitmapFromData(Spw_Dpy,
                                              Spw_mainWindow,
                                              (char *)sbXcityfly_iconMask_bits,
                                              sbXcityfly_iconMask_width,
                                              sbXcityfly_iconMask_height);
  /*
   * Allocate and set the the Class hints in a friendly way
   */
  if ( !(class_hints = XAllocClassHint()) )
     {
     fprintf(stderr,"Not enough memory\n");
     exit(-1);
     }
   /*
    *  Not much to say this is about it for class hints....
    */
  class_hints->res_name = res_name;
  class_hints->res_class = res_class;
  
  /*
   * Convert names into X strings
   */

  if ( XStringListToTextProperty( &window_name, 1, &windowName) == 0 )
     {
     fprintf(stderr,"Couldn't create string\n");
     exit(-1);
     }
  if ( XStringListToTextProperty( &icon_name, 1, &iconName) == 0 )
     {
     fprintf(stderr,"Couldn't create string\n");
     exit(-1);
     }

  /*
   * Finally we can set the properities.
   * This is supposedly the "correct" call.  Most of the
   * others like SetWMHints are obsolete.
   */

  XSetWMProperties(Spw_Dpy, win, &windowName, &iconName,
                   argv, argc, size_hints, wm_hints, class_hints);

}
コード例 #28
0
ファイル: SDL_x11video.c プロジェクト: 00wendi00/MyProject
/* Create auxiliary (toplevel) windows with the current visual */
static void create_aux_windows(_THIS)
{
    int x = 0, y = 0;
    char classname[1024];
    XSetWindowAttributes xattr;
    XWMHints *hints;
    unsigned long app_event_mask;
    int def_vis = (SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen));

    /* Look up some useful Atoms */
    WM_DELETE_WINDOW = XInternAtom(SDL_Display, "WM_DELETE_WINDOW", False);

    /* Don't create any extra windows if we are being managed */
    if ( SDL_windowid ) {
	FSwindow = 0;
	WMwindow = SDL_strtol(SDL_windowid, NULL, 0);
        return;
    }

    if(FSwindow)
	XDestroyWindow(SDL_Display, FSwindow);

#if SDL_VIDEO_DRIVER_X11_XINERAMA
    if ( use_xinerama ) {
        x = xinerama_info.x_org;
        y = xinerama_info.y_org;
    }
#endif
    xattr.override_redirect = True;
    xattr.background_pixel = def_vis ? BlackPixel(SDL_Display, SDL_Screen) : 0;
    xattr.border_pixel = 0;
    xattr.colormap = SDL_XColorMap;

    FSwindow = XCreateWindow(SDL_Display, SDL_Root,
                             x, y, 32, 32, 0,
			     this->hidden->depth, InputOutput, SDL_Visual,
			     CWOverrideRedirect | CWBackPixel | CWBorderPixel
			     | CWColormap,
			     &xattr);

    XSelectInput(SDL_Display, FSwindow, StructureNotifyMask);

    /* Tell KDE to keep the fullscreen window on top */
    {
	XEvent ev;
	long mask;

	SDL_memset(&ev, 0, sizeof(ev));
	ev.xclient.type = ClientMessage;
	ev.xclient.window = SDL_Root;
	ev.xclient.message_type = XInternAtom(SDL_Display,
					      "KWM_KEEP_ON_TOP", False);
	ev.xclient.format = 32;
	ev.xclient.data.l[0] = FSwindow;
	ev.xclient.data.l[1] = CurrentTime;
	mask = SubstructureRedirectMask;
	XSendEvent(SDL_Display, SDL_Root, False, mask, &ev);
    }

    hints = NULL;
    if(WMwindow) {
	/* All window attributes must survive the recreation */
	hints = XGetWMHints(SDL_Display, WMwindow);
	XDestroyWindow(SDL_Display, WMwindow);
    }

    /* Create the window for windowed management */
    /* (reusing the xattr structure above) */
    WMwindow = XCreateWindow(SDL_Display, SDL_Root,
                             x, y, 32, 32, 0,
			     this->hidden->depth, InputOutput, SDL_Visual,
			     CWBackPixel | CWBorderPixel | CWColormap,
			     &xattr);

    /* Set the input hints so we get keyboard input */
    if(!hints) {
	hints = XAllocWMHints();
	hints->input = True;
	hints->flags = InputHint;
    }
    XSetWMHints(SDL_Display, WMwindow, hints);
    XFree(hints);
    X11_SetCaptionNoLock(this, this->wm_title, this->wm_icon);

    app_event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask
	| PropertyChangeMask | StructureNotifyMask | KeymapStateMask;
    XSelectInput(SDL_Display, WMwindow, app_event_mask);

    /* Set the class hints so we can get an icon (AfterStep) */
    get_classname(classname, sizeof(classname));
    {
	XClassHint *classhints;
	classhints = XAllocClassHint();
	if(classhints != NULL) {
	    classhints->res_name = classname;
	    classhints->res_class = classname;
	    XSetClassHint(SDL_Display, WMwindow, classhints);
	    XFree(classhints);
	}
    }

	/* Setup the communication with the IM server */
	/* create_aux_windows may be called several times against the same
	   Display.  We should reuse the SDL_IM if one has been opened for
	   the Display, so we should not simply reset SDL_IM here.  */

	#ifdef X_HAVE_UTF8_STRING
	if (SDL_X11_HAVE_UTF8) {
		/* Discard obsolete resources if any.  */
		if (SDL_IM != NULL && SDL_Display != XDisplayOfIM(SDL_IM)) {
			/* Just a double check. I don't think this
		           code is ever executed. */
			SDL_SetError("display has changed while an IM is kept");
			if (SDL_IC) {
				XUnsetICFocus(SDL_IC);
				XDestroyIC(SDL_IC);
				SDL_IC = NULL;
			}
			XCloseIM(SDL_IM);
			SDL_IM = NULL;
		}

		/* Open an input method.  */
		if (SDL_IM == NULL) {
			char *old_locale = NULL, *old_modifiers = NULL;
			const char *p;
			size_t n;
			/* I'm not comfortable to do locale setup
			   here.  However, we need C library locale
			   (and xlib modifiers) to be set based on the
			   user's preference to use XIM, and many
			   existing game programs doesn't take care of
			   users' locale preferences, so someone other
			   than the game program should do it.
			   Moreover, ones say that some game programs
			   heavily rely on the C locale behaviour,
			   e.g., strcol()'s, and we can't change the C
			   library locale.  Given the situation, I
			   couldn't find better place to do the
			   job... */

			/* Save the current (application program's)
			   locale settings.  */
			p = setlocale(LC_ALL, NULL);
			if ( p ) {
				n = SDL_strlen(p)+1;
				old_locale = SDL_stack_alloc(char, n);
				if ( old_locale ) {
					SDL_strlcpy(old_locale, p, n);
				}
			}
			p = XSetLocaleModifiers(NULL);
			if ( p ) {
				n = SDL_strlen(p)+1;
				old_modifiers = SDL_stack_alloc(char, n);
				if ( old_modifiers ) {
					SDL_strlcpy(old_modifiers, p, n);
				}
			}

			/* Fetch the user's preferences and open the
			   input method with them.  */
			setlocale(LC_ALL, "");
			XSetLocaleModifiers("");
			SDL_IM = XOpenIM(SDL_Display, NULL, classname, classname);

			/* Restore the application's locale settings
			   so that we don't break the application's
			   expected behaviour.  */
			if ( old_locale ) {
				/* We need to restore the C library
				   locale first, since the
				   interpretation of the X modifier
				   may depend on it.  */
				setlocale(LC_ALL, old_locale);
				SDL_stack_free(old_locale);
			}
			if ( old_modifiers ) {
				XSetLocaleModifiers(old_modifiers);
				SDL_stack_free(old_modifiers);
			}
		}

		/* Create a new input context for the new window just created.  */
		if (SDL_IM == NULL) {
			SDL_SetError("no input method could be opened");
		} else {
			if (SDL_IC != NULL) {
				/* Discard the old IC before creating new one.  */
			    XUnsetICFocus(SDL_IC);
			    XDestroyIC(SDL_IC);
			}
			/* Theoretically we should check the current IM supports
			   PreeditNothing+StatusNothing style (i.e., root window method)
			   before creating the IC.  However, it is the bottom line method,
			   and we supports any other options.  If the IM didn't support
			   root window method, the following call fails, and SDL falls
			   back to pre-XIM keyboard handling.  */
			SDL_IC = pXCreateIC(SDL_IM,
					XNClientWindow, WMwindow,
					XNFocusWindow, WMwindow,
					XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
					XNResourceName, classname,
					XNResourceClass, classname,
					NULL);

			if (SDL_IC == NULL) {
				SDL_SetError("no input context could be created");
				XCloseIM(SDL_IM);
				SDL_IM = NULL;
			} else {
				/* We need to receive X events that an IM wants and to pass
				   them to the IM through XFilterEvent. The set of events may
				   vary depending on the IM implementation and the options
				   specified through various routes. Although unlikely, the
				   xlib specification allows IM to change the event requirement
				   with its own circumstances, it is safe to call SelectInput
				   whenever we re-create an IC.  */
				unsigned long mask = 0;
				char *ret = pXGetICValues(SDL_IC, XNFilterEvents, &mask, NULL);
				if (ret != NULL) {
					XUnsetICFocus(SDL_IC);
					XDestroyIC(SDL_IC);
					SDL_IC = NULL;
					SDL_SetError("no input context could be created");
					XCloseIM(SDL_IM);
					SDL_IM = NULL;
				} else {
					XSelectInput(SDL_Display, WMwindow, app_event_mask | mask);
					XSetICFocus(SDL_IC);
				}
			}
		}
	}
コード例 #29
0
ファイル: x11_window.c プロジェクト: jjiezheng/lfant
// Create the X11 window (and its colormap)
//
static GLboolean createWindow(_GLFWwindow* window,
                              const _GLFWwndconfig* wndconfig)
{
    unsigned long wamask;
    XSetWindowAttributes wa;
    XVisualInfo* visual = _GLFW_X11_CONTEXT_VISUAL;

    // Every window needs a colormap
    // Create one based on the visual used by the current context
    // TODO: Decouple this from context creation

    window->x11.colormap = XCreateColormap(_glfw.x11.display,
                                           _glfw.x11.root,
                                           visual->visual,
                                           AllocNone);

    // Create the actual window
    {
        wamask = CWBorderPixel | CWColormap | CWEventMask;

        wa.colormap = window->x11.colormap;
        wa.border_pixel = 0;
        wa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask |
                        PointerMotionMask | ButtonPressMask | ButtonReleaseMask |
                        ExposureMask | FocusChangeMask | VisibilityChangeMask |
                        EnterWindowMask | LeaveWindowMask | PropertyChangeMask;

        if (wndconfig->monitor == NULL)
        {
            // HACK: This is a workaround for windows without a background pixel
            //       not getting any decorations on certain older versions of
            //       Compiz running on Intel hardware
            wa.background_pixel = BlackPixel(_glfw.x11.display,
                                             _glfw.x11.screen);
            wamask |= CWBackPixel;
        }

        _glfwGrabXErrorHandler();

        window->x11.handle = XCreateWindow(_glfw.x11.display,
                                           _glfw.x11.root,
                                           0, 0,
                                           wndconfig->width, wndconfig->height,
                                           0,              // Border width
                                           visual->depth,  // Color depth
                                           InputOutput,
                                           visual->visual,
                                           wamask,
                                           &wa);

        _glfwReleaseXErrorHandler();

        if (!window->x11.handle)
        {
            _glfwInputXError(GLFW_PLATFORM_ERROR,
                             "X11: Failed to create window");
            return GL_FALSE;
        }

        if (!wndconfig->decorated)
        {
            MotifWmHints hints;
            hints.flags = MWM_HINTS_DECORATIONS;
            hints.decorations = 0;

            XChangeProperty(_glfw.x11.display, window->x11.handle,
                            _glfw.x11.MOTIF_WM_HINTS,
                            _glfw.x11.MOTIF_WM_HINTS, 32,
                            PropModeReplace,
                            (unsigned char*) &hints,
                            sizeof(MotifWmHints) / sizeof(long));
        }

        XSaveContext(_glfw.x11.display,
                     window->x11.handle,
                     _glfw.x11.context,
                     (XPointer) window);
    }

    if (window->monitor && !_glfw.x11.hasEWMH)
    {
        // This is the butcher's way of removing window decorations
        // Setting the override-redirect attribute on a window makes the window
        // manager ignore the window completely (ICCCM, section 4)
        // The good thing is that this makes undecorated fullscreen windows
        // easy to do; the bad thing is that we have to do everything manually
        // and some things (like iconify/restore) won't work at all, as those
        // are tasks usually performed by the window manager

        XSetWindowAttributes attributes;
        attributes.override_redirect = True;
        XChangeWindowAttributes(_glfw.x11.display,
                                window->x11.handle,
                                CWOverrideRedirect,
                                &attributes);

        window->x11.overrideRedirect = GL_TRUE;
    }

    // Declare the WM protocols supported by GLFW
    {
        int count = 0;
        Atom protocols[2];

        // The WM_DELETE_WINDOW ICCCM protocol
        // Basic window close notification protocol
        if (_glfw.x11.WM_DELETE_WINDOW)
            protocols[count++] = _glfw.x11.WM_DELETE_WINDOW;

        // The _NET_WM_PING EWMH protocol
        // Tells the WM to ping the GLFW window and flag the application as
        // unresponsive if the WM doesn't get a reply within a few seconds
        if (_glfw.x11.NET_WM_PING)
            protocols[count++] = _glfw.x11.NET_WM_PING;

        if (count > 0)
        {
            XSetWMProtocols(_glfw.x11.display, window->x11.handle,
                            protocols, count);
        }
    }

    if (_glfw.x11.NET_WM_PID)
    {
        const pid_t pid = getpid();

        XChangeProperty(_glfw.x11.display,  window->x11.handle,
                        _glfw.x11.NET_WM_PID, XA_CARDINAL, 32,
                        PropModeReplace,
                        (unsigned char*) &pid, 1);
    }

    // Set ICCCM WM_HINTS property
    {
        XWMHints* hints = XAllocWMHints();
        if (!hints)
        {
            _glfwInputError(GLFW_OUT_OF_MEMORY,
                            "X11: Failed to allocate WM hints");
            return GL_FALSE;
        }

        hints->flags = StateHint;
        hints->initial_state = NormalState;

        XSetWMHints(_glfw.x11.display, window->x11.handle, hints);
        XFree(hints);
    }

    // Set ICCCM WM_NORMAL_HINTS property (even if no parts are set)
    {
        XSizeHints* hints = XAllocSizeHints();
        hints->flags = 0;

        if (wndconfig->monitor)
        {
            hints->flags |= PPosition;
            _glfwPlatformGetMonitorPos(wndconfig->monitor, &hints->x, &hints->y);
        }
        else
        {
            // HACK: Explicitly setting PPosition to any value causes some WMs,
            //       notably Compiz and Metacity, to honor the position of
            //       unmapped windows set by XMoveWindow
            hints->flags |= PPosition;
            hints->x = hints->y = 0;
        }

        if (!wndconfig->resizable)
        {
            hints->flags |= (PMinSize | PMaxSize);
            hints->min_width  = hints->max_width  = wndconfig->width;
            hints->min_height = hints->max_height = wndconfig->height;
        }

        XSetWMNormalHints(_glfw.x11.display, window->x11.handle, hints);
        XFree(hints);
    }

    // Set ICCCM WM_CLASS property
    // HACK: Until a mechanism for specifying the application name is added, the
    //       initial window title is used as the window class name
    if (strlen(wndconfig->title))
    {
        XClassHint* hint = XAllocClassHint();
        hint->res_name = (char*) wndconfig->title;
        hint->res_class = (char*) wndconfig->title;

        XSetClassHint(_glfw.x11.display, window->x11.handle, hint);
        XFree(hint);
    }

    if (_glfw.x11.xi.available)
    {
        // Select for XInput2 events

        XIEventMask eventmask;
        unsigned char mask[] = { 0 };

        eventmask.deviceid = 2;
        eventmask.mask_len = sizeof(mask);
        eventmask.mask = mask;
        XISetMask(mask, XI_Motion);

        XISelectEvents(_glfw.x11.display, window->x11.handle, &eventmask, 1);
    }

    if (_glfw.x11.XdndAware)
    {
        // Announce support for Xdnd (drag and drop)
        const Atom version = 5;
        XChangeProperty(_glfw.x11.display, window->x11.handle,
                        _glfw.x11.XdndAware, XA_ATOM, 32,
                        PropModeReplace, (unsigned char*) &version, 1);
    }

    _glfwPlatformSetWindowTitle(window, wndconfig->title);

    XRRSelectInput(_glfw.x11.display, window->x11.handle,
                   RRScreenChangeNotifyMask);

    _glfwPlatformGetWindowPos(window, &window->x11.xpos, &window->x11.ypos);
    _glfwPlatformGetWindowSize(window, &window->x11.width, &window->x11.height);

    return GL_TRUE;
}
コード例 #30
0
ファイル: glselectrectangle.cpp プロジェクト: Jasonic/slop
slop::GLSelectRectangle::GLSelectRectangle( int sx, int sy, int ex, int ey, int border, bool highlight, float r, float g, float b, float a ) {
    m_x = std::min( sx, ex );
    m_y = std::min( sy, ey );
    m_width = std::max( sx, ex ) - m_x;
    m_height = std::max( sy, ey ) - m_y;
    m_r = r;
    m_g = g;
    m_b = b;
    m_a = a;
    m_border = border;
    m_window = None;
    m_highlight = highlight;
    m_glassPixels = 64;
    m_glassx = xengine->m_mousex;
    m_glassy = xengine->m_mousey;
    m_realglassx = xengine->m_mousex;
    m_realglassy = xengine->m_mousey;
    m_glassSize = 4;
    m_glassBorder = 1;
    m_monitors = xengine->getCRTCS();
    m_themed = false;
    m_shader = "simple";
    m_time = 0;

    // If we don't have a border, we don't exist, so just die.
    if ( m_border == 0 ) {
        return;
    }

    if ( m_highlight ) {
        m_border = 0;
    }

    static int visdata[] = {
        GLX_RENDER_TYPE, GLX_RGBA_BIT,
        GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
        GLX_DOUBLEBUFFER, True,
        GLX_RED_SIZE, 8,
        GLX_GREEN_SIZE, 8,
        GLX_BLUE_SIZE, 8,
        GLX_ALPHA_SIZE, 8,
        GLX_DEPTH_SIZE, 16,
        None
    };

    int numfbconfigs = 0;
    GLXFBConfig* fbconfigs = glXChooseFBConfig( xengine->m_display,  DefaultScreen( xengine->m_display ), visdata, &numfbconfigs );
    m_fbconfig = 0;
    for ( int i=0; i<numfbconfigs; i++ ) {
        m_visual = (XVisualInfo*)glXGetVisualFromFBConfig( xengine->m_display, fbconfigs[i] );
        if ( !m_visual ) {
            continue;
        }
        m_pictFormat = XRenderFindVisualFormat( xengine->m_display, m_visual->visual );
        if ( !m_pictFormat ) {
            continue;
        }
        m_fbconfig = fbconfigs[i];
        if ( m_pictFormat->direct.alphaMask > 0 ) {
            break;
        }
    }

    if ( !m_fbconfig ) {
        fprintf( stderr, "Couldn't find a matching FB config for a transparent OpenGL window!\n");
    }

    m_cmap = XCreateColormap( xengine->m_display, xengine->m_root, m_visual->visual, AllocNone );

    XSetWindowAttributes attributes;
    attributes.colormap = m_cmap;
    attributes.background_pixmap = None;
    attributes.border_pixmap = None;
    attributes.border_pixel = 0;
    // Disable window decorations.
    attributes.override_redirect = True;
    // Make sure we know when we've been successfully destroyed later!
    attributes.event_mask = StructureNotifyMask;
    unsigned long valueMask = CWOverrideRedirect | CWEventMask | CWBackPixmap | CWColormap | CWBorderPixel;


    // Create the window
    m_window = XCreateWindow( xengine->m_display, xengine->m_root, 0, 0, xengine->getWidth(), xengine->getHeight(),
                              0, m_visual->depth, InputOutput,
                              m_visual->visual, valueMask, &attributes );

    if ( !m_window ) {
        fprintf( stderr, "Couldn't create a GL window!\n");
    }

    m_glxWindow = m_window;

    static char title[] = "OpenGL Slop";
    XWMHints* startup_state = XAllocWMHints();
    startup_state->initial_state = NormalState;
    startup_state->flags = StateHint;
    XTextProperty textprop;
    textprop.value = (unsigned char*)title;
    textprop.encoding = XA_STRING;
    textprop.format = 8;
    textprop.nitems = strlen( title );
    XSizeHints sizehints;
    sizehints.x = 0;
    sizehints.y = 0;
    sizehints.width = xengine->getWidth();
    sizehints.height = xengine->getHeight();
    sizehints.flags = USPosition | USSize;
    XClassHint classhints;
    char name[] = "slop";
    classhints.res_name = name;
    classhints.res_class = name;
    XSetClassHint( xengine->m_display, m_window, &classhints );
    XSetWMProperties( xengine->m_display, m_window, &textprop, &textprop, NULL, 0, &sizehints, startup_state, NULL );
    XFree( startup_state );

    // Make it so all input falls through
    XRectangle rect;
    rect.x = rect.y = rect.width = rect.height = 0;
    XShapeCombineRectangles( xengine->m_display, m_window, ShapeInput, 0, 0, &rect, 1, ShapeSet, 0);

    XMapWindow( xengine->m_display, m_window );

    int dummy;
    if ( !glXQueryExtension( xengine->m_display, &dummy, &dummy ) ) {
        fprintf( stderr, "OpenGL is not supported!\n" );
    }
    m_renderContext = glXCreateNewContext( xengine->m_display, m_fbconfig, GLX_RGBA_TYPE, 0, True );
    if ( !m_renderContext ) {
        fprintf( stderr, "Failed to create a GL context.\n" );
    }
    if ( !glXMakeContextCurrent( xengine->m_display, m_glxWindow, m_glxWindow, m_renderContext ) ) {
        fprintf( stderr, "Failed to attach GL context to window!\n" );
    }
    GLenum err = glewInit();
    if ( GLEW_OK != err ) {
        /* Problem: glewInit failed, something is seriously wrong. */
        fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
    }

    // Get an image of the entire desktop for use in shaders.
    XImage* image = XGetImage( xengine->m_display, xengine->m_root, 0, 0, xengine->getWidth(), xengine->getHeight(), 0xffffffff, ZPixmap );
    glEnable(GL_TEXTURE_2D);
    glGenTextures(1, &m_desktop);
    glBindTexture(GL_TEXTURE_2D, m_desktop);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, xengine->getWidth(), xengine->getHeight(), 0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)(&(image->data[0])));
    XDestroyImage( image );

    glDisable(GL_TEXTURE_2D);
    m_framebuffer = new slop::Framebuffer( xengine->getWidth(), xengine->getHeight(), slop::Framebuffer::color, m_shader );
    m_framebuffer->bind();
    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glClearColor( 0, 0, 0, 0 );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glXSwapBuffers( xengine->m_display, m_glxWindow );
    m_framebuffer->unbind();
}