예제 #1
0
/*
 * Setup X11 wnd System
 */
void
X11_SetupWindow (GF_VideoOutput * vout)
{
	X11VID ();
	const char *sOpt;

	xWindow->display = XOpenDisplay (NULL);
	xWindow->screennum = DefaultScreen (xWindow->display);
	xWindow->screenptr = DefaultScreenOfDisplay (xWindow->display);
	xWindow->visual = DefaultVisualOfScreen (xWindow->screenptr);
	xWindow->depth = DefaultDepth (xWindow->display, xWindow->screennum);

	switch (xWindow->depth) {
	case 8:
		xWindow->pixel_format = GF_PIXEL_GREYSCALE;
		break;
	case 16:
		xWindow->pixel_format = GF_PIXEL_RGB_565;
		break;
	case 24:
		xWindow->pixel_format = GF_PIXEL_RGB_32;
		break;
	default:
		xWindow->pixel_format = GF_PIXEL_GREYSCALE;
		break;
	}
	xWindow->bpp = xWindow->depth / 8;
	xWindow->bpp = xWindow->bpp == 3 ? 4 : xWindow->bpp;

	vout->max_screen_width = DisplayWidth(xWindow->display, xWindow->screennum);
	vout->max_screen_height = DisplayHeight(xWindow->display, xWindow->screennum);

	/*
	 * Full screen wnd
	 */
	xWindow->full_wnd = XCreateWindow (xWindow->display,
								   RootWindowOfScreen (xWindow->screenptr),
								   0, 0,
								   vout->max_screen_width,
								   vout->max_screen_height, 0,
								   xWindow->depth, InputOutput,
								   xWindow->visual, 0, NULL);

	XSelectInput(xWindow->display, xWindow->full_wnd,
					FocusChangeMask | ExposureMask | PointerMotionMask | ButtonReleaseMask | ButtonPressMask | KeyPressMask | KeyReleaseMask);

	if (!xWindow->par_wnd) {
		xWindow->w_width = 320;
		xWindow->w_height = 20;
		xWindow->wnd = XCreateWindow (xWindow->display,
					   RootWindowOfScreen(xWindow->screenptr), 0, 0,
					   xWindow->w_width, xWindow->w_height, 0,
					   xWindow->depth, InputOutput,
					   xWindow->visual, 0, NULL);
		XMapWindow (xWindow->display, (Window) xWindow->wnd);
	} else {
		XWindowAttributes pwa;
		XGetWindowAttributes(xWindow->display, xWindow->par_wnd, &pwa);
		xWindow->w_width = pwa.width;
		xWindow->w_height = pwa.height;
		xWindow->wnd = XCreateWindow (xWindow->display, xWindow->par_wnd, pwa.x, pwa.y,
					xWindow->w_width, xWindow->w_height, 0,
					   xWindow->depth, InputOutput,
					   xWindow->visual, 0, NULL);
		XMapWindow (xWindow->display, (Window) xWindow->wnd);
	}

	XSync(xWindow->display, False);
	XUnmapWindow (xWindow->display, (Window) xWindow->wnd);
	XSync(xWindow->display, False);
	old_handler = XSetErrorHandler(X11_BadAccess_ByPass);
	selectinput_err = 0;
	XSelectInput(xWindow->display, xWindow->wnd,
		FocusChangeMask | StructureNotifyMask | PropertyChangeMask | ExposureMask |
		PointerMotionMask | ButtonReleaseMask | ButtonPressMask |
		KeyPressMask | KeyReleaseMask);
	XSync(xWindow->display, False);
	XSetErrorHandler(old_handler);
	if (selectinput_err) {
       	XSelectInput(xWindow->display, xWindow->wnd,
			StructureNotifyMask | PropertyChangeMask | ExposureMask |
			KeyPressMask | KeyReleaseMask);

		GF_LOG(GF_LOG_ERROR, GF_LOG_MMIO, ("[X11] Cannot select input focus\n"));
	}
	XSync(xWindow->display, False);
	XMapWindow (xWindow->display, (Window) xWindow->wnd);

	XSizeHints *Hints = XAllocSizeHints ();
	Hints->flags = PSize | PMinSize;
	Hints->min_width = 32;
	Hints->min_height = 32;
	Hints->max_height = 4096;
	Hints->max_width = 4096;
	if (!xWindow->par_wnd) {
		XSetWMNormalHints (xWindow->display, xWindow->wnd, Hints);
		XStoreName (xWindow->display, xWindow->wnd, "GPAC X11 Output");
	}
	Hints->x = 0;
	Hints->y = 0;
	Hints->flags |= USPosition;
	XSetWMNormalHints (xWindow->display, xWindow->full_wnd, Hints);
	XFree (Hints);


	xWindow->the_gc = XCreateGC (xWindow->display, xWindow->wnd, 0, NULL);
	xWindow->videoaccesstype = VIDEO_XI_STANDARD;

#ifdef GPAC_HAS_X11_SHM
	sOpt = gf_modules_get_option((GF_BaseInterface *)vout, "Video", "UseHardwareMemory");
        if (sOpt && !strcmp(sOpt, "yes")) {
	  int XShmMajor, XShmMinor;
	  Bool XShmPixmaps;
	  if (XShmQueryVersion(xWindow->display, &XShmMajor, &XShmMinor, &XShmPixmaps)) {
	    /*this is disabled due to flip pb (we cannot reposition backbuffer)*/
	    if (0 && XShmPixmaps && (XShmPixmapFormat(xWindow->display) == ZPixmap)) {
		xWindow->videoaccesstype = VIDEO_XI_SHMPIXMAP;
	    } else {
	      xWindow->videoaccesstype = VIDEO_XI_SHMSTD;
	      GF_LOG(GF_LOG_INFO, GF_LOG_MMIO, ("[X11] Using X11 Hardware Blit\n"));
	    }
	  }
	}
#endif

	GF_SAFEALLOC(xWindow->back_buffer, X11WrapSurface);
	xWindow->back_buffer->id = -1;


	XSetWindowAttributes xsw;
	xsw.border_pixel = WhitePixel (xWindow->display, xWindow->screennum);
	xsw.background_pixel = BlackPixel (xWindow->display, xWindow->screennum);
	xsw.win_gravity = NorthWestGravity;
	XChangeWindowAttributes (xWindow->display, xWindow->wnd, CWBackPixel | CWWinGravity, &xsw);

	xsw.override_redirect = True;
	XChangeWindowAttributes(xWindow->display, xWindow->full_wnd,
				CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWWinGravity, &xsw);

	if (!xWindow->par_wnd) {
		xWindow->WM_DELETE_WINDOW = XInternAtom (xWindow->display, "WM_DELETE_WINDOW", False);
		XSetWMProtocols(xWindow->display, xWindow->wnd, &xWindow->WM_DELETE_WINDOW, 1);
	}

	{
		XEvent ev;
		long mask;

		memset (&ev, 0, sizeof (ev));
		ev.xclient.type = ClientMessage;
		ev.xclient.window = RootWindowOfScreen (xWindow->screenptr);
		ev.xclient.message_type = XInternAtom (xWindow->display, "KWM_KEEP_ON_TOP", False);
		ev.xclient.format = 32;
		ev.xclient.data.l[0] = xWindow->full_wnd;
		ev.xclient.data.l[1] = CurrentTime;
		mask = SubstructureRedirectMask;
		XSendEvent (xWindow->display,RootWindowOfScreen (xWindow->screenptr), False,
			    mask, &ev);
	}
#ifdef GPAC_HAS_OPENGL
	if (xWindow->is_3D_out) {
	  int attribs[64];
	  int i;

	  i=0;
	  attribs[i++] = GLX_RGBA;
	  attribs[i++] = GLX_RED_SIZE;
	  attribs[i++] = 5;
	  attribs[i++] = GLX_GREEN_SIZE;
	  attribs[i++] = 5;
	  attribs[i++] = GLX_BLUE_SIZE;
	  attribs[i++] = 5;
	  attribs[i++] = GLX_DEPTH_SIZE;
	  attribs[i++] = 16;
	  if (xWindow->gl_cfg.double_buffered) attribs[i++] = GLX_DOUBLEBUFFER;
	  attribs[i++] = None;
	  xWindow->glx_visualinfo = glXChooseVisual(xWindow->display, xWindow->screennum, attribs);
	  if (!xWindow->glx_visualinfo) {
		  GF_LOG(GF_LOG_ERROR, GF_LOG_MMIO, ("[X11] Error selecting GL display\n"));
	  }
	}
#endif
	xWindow->setup_done = 1;
}
예제 #2
0
static gboolean
clutter_backend_x11_post_parse (ClutterBackend  *backend,
                                GError         **error)
{
  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
  ClutterSettings *settings;
  Atom atoms[N_ATOM_NAMES];
  double dpi;

  if (_foreign_dpy)
    backend_x11->xdpy = _foreign_dpy;

  /* Only open connection if not already set by prior call to
   * clutter_x11_set_display()
   */
  if (backend_x11->xdpy == NULL)
    {
      if (clutter_display_name != NULL &&
          *clutter_display_name != '\0')
	{
	  CLUTTER_NOTE (BACKEND, "XOpenDisplay on '%s'", clutter_display_name);

	  backend_x11->xdpy = XOpenDisplay (clutter_display_name);
          if (backend_x11->xdpy == NULL)
            {
              g_set_error (error, CLUTTER_INIT_ERROR,
                           CLUTTER_INIT_ERROR_BACKEND,
                           "Unable to open display '%s'",
                           clutter_display_name);
              return FALSE;
            }
	}
      else
	{
	  g_set_error_literal (error, CLUTTER_INIT_ERROR,
                               CLUTTER_INIT_ERROR_BACKEND,
                               "Unable to open display. You have to set the "
                               "DISPLAY environment variable, or use the "
                               "--display command line argument");
	  return FALSE;
	}
    }

  g_assert (backend_x11->xdpy != NULL);

  CLUTTER_NOTE (BACKEND, "Getting the X screen");

  settings = clutter_settings_get_default ();

  /* add event filter for Cogl events */
  clutter_x11_add_filter (cogl_xlib_filter, NULL);

  if (clutter_screen == -1)
    backend_x11->xscreen = DefaultScreenOfDisplay (backend_x11->xdpy);
  else
    backend_x11->xscreen = ScreenOfDisplay (backend_x11->xdpy,
                                            clutter_screen);

  backend_x11->xscreen_num = XScreenNumberOfScreen (backend_x11->xscreen);
  backend_x11->xscreen_width = WidthOfScreen (backend_x11->xscreen);
  backend_x11->xscreen_height = HeightOfScreen (backend_x11->xscreen);

  backend_x11->xwin_root = RootWindow (backend_x11->xdpy,
                                       backend_x11->xscreen_num);

  backend_x11->display_name = g_strdup (clutter_display_name);

  dpi = (((double) DisplayHeight (backend_x11->xdpy, backend_x11->xscreen_num) * 25.4)
      / (double) DisplayHeightMM (backend_x11->xdpy, backend_x11->xscreen_num));

  g_object_set (settings, "font-dpi", (int) dpi * 1024, NULL);

  /* create XSETTINGS client */
  backend_x11->xsettings =
    _clutter_xsettings_client_new (backend_x11->xdpy,
                                   backend_x11->xscreen_num,
                                   clutter_backend_x11_xsettings_notify,
                                   NULL,
                                   backend_x11);

  /* add event filter for XSETTINGS events */
  clutter_x11_add_filter (xsettings_filter, backend_x11);

  if (clutter_synchronise)
    XSynchronize (backend_x11->xdpy, True);

  XInternAtoms (backend_x11->xdpy,
                (char **) atom_names, N_ATOM_NAMES,
                False, atoms);

  backend_x11->atom_NET_WM_PID = atoms[0];
  backend_x11->atom_NET_WM_PING = atoms[1];
  backend_x11->atom_NET_WM_STATE = atoms[2];
  backend_x11->atom_NET_WM_STATE_FULLSCREEN = atoms[3];
  backend_x11->atom_NET_WM_USER_TIME = atoms[4];
  backend_x11->atom_WM_PROTOCOLS = atoms[5];
  backend_x11->atom_WM_DELETE_WINDOW = atoms[6];
  backend_x11->atom_XEMBED = atoms[7];
  backend_x11->atom_XEMBED_INFO = atoms[8];
  backend_x11->atom_NET_WM_NAME = atoms[9];
  backend_x11->atom_UTF8_STRING = atoms[10];

  g_free (clutter_display_name);

  CLUTTER_NOTE (BACKEND,
                "X Display '%s'[%p] opened (screen:%d, root:%u, dpi:%f)",
                backend_x11->display_name,
                backend_x11->xdpy,
                backend_x11->xscreen_num,
                (unsigned int) backend_x11->xwin_root,
                clutter_backend_get_resolution (backend));

  return TRUE;
}
예제 #3
0
파일: hope.cpp 프로젝트: artfly/nsu_old
int main (int argc, char **argv) {
	if (argc != 2) {
		return help (std::string(argv[0]));
	}
	char *imageName = argv[1];
	struct timespec start, end;
	
	cv::Mat image;
	cv::Mat hope = cv::imread ("hopeless.png");

	clock_gettime (CLOCK_MONOTONIC_RAW, &start);
	cv::VideoCapture capture(0);
	clock_gettime (CLOCK_MONOTONIC_RAW, &end);
	std::cout <<  "Time taken to get capture : " 
						<< end.tv_sec-start.tv_sec + 0.000000001* (end.tv_nsec-start.tv_nsec)
						<< " sec \n";
	
	cv::Mat hope_resize;
	cv::Mat result;
	
	Display* disp = XOpenDisplay (NULL);
	Screen *scrn = DefaultScreenOfDisplay (disp);

	if (!capture.isOpened()) {
		std::cout << "Coudn't open camera" << std::endl;
		return -1;
	}
	while (1) {
		cv::Mat frame;
		capture >> frame;
		cv::imshow ("Camera", frame);
		cv::resizeWindow ("Camera", W_WIDTH, W_HEIGHT);
		cv::moveWindow ("Camera", (scrn->width-W_WIDTH)/2, (scrn->height-W_HEIGHT)/2);
		char c = cv::waitKey (33);
		if (c == SPACE) {

			clock_gettime (CLOCK_MONOTONIC_RAW, &start);
			cv::cvtColor (frame, image, CV_BGR2GRAY);
			cv::imwrite (imageName, image);
			image  = cv::imread (imageName);
			cv::resize (hope, hope_resize, cv::Size2i (image.cols, image.rows));
			cv::addWeighted (image, 1, hope_resize, 0.5, 0.0, result);
			cv::imwrite (imageName, result);
			clock_gettime (CLOCK_MONOTONIC_RAW, &end);
			std::cout <<  "Time taken to transform image : " 
							<< end.tv_sec-start.tv_sec + 0.000000001* (end.tv_nsec-start.tv_nsec)
							<< " sec \n";

			clock_gettime (CLOCK_MONOTONIC_RAW, &start);
			cv::imshow ("Camera", result);
			clock_gettime (CLOCK_MONOTONIC_RAW, &end);
			std::cout <<  "Time taken to show image : " 
							<< end.tv_sec-start.tv_sec + 0.000000001* (end.tv_nsec-start.tv_nsec)
							<< " sec \n";

			cv::waitKey (2500);
		}	
		if (c == ESC) {
			break;
		}
	}

	return 0;
}
예제 #4
0
static Window
hgu_remote_find_window (Display *dpy)
{
  int i;
  Window root = RootWindowOfScreen (DefaultScreenOfDisplay (dpy));
  Window root2, parent, *kids;
  unsigned int nkids;
  Window result = 0;
  Window tenative = 0;
  unsigned char *tenative_version = 0;

  if (! XQueryTree (dpy, root, &root2, &parent, &kids, &nkids))
    {
      fprintf (stderr, "%s: XQueryTree failed on display %s\n", progname,
	       DisplayString (dpy));
      return( (Window) 0 );
    }

  /* root != root2 is possible with virtual root WMs. */

  if (! (kids && nkids))
    {
      fprintf (stderr, "%s: root window has no children on display %s\n",
	       progname, DisplayString (dpy));
      return( (Window) 0 );
    }

  for (i = nkids-1; i >= 0; i--)
    {
      Atom type;
      int format;
      unsigned long nitems, bytesafter;
      unsigned char *version = 0;
      Window w = XmuClientWindow (dpy, kids[i]);
      int status = XGetWindowProperty (dpy, w, XA_MOZILLA_VERSION,
				       0, (65536 / sizeof (long)),
				       False, XA_STRING,
				       &type, &format, &nitems, &bytesafter,
				       &version);
      if (! version)
	continue;
      if (strcmp ((char *) version, expected_mozilla_version) &&
	  !tenative)
	{
	  tenative = w;
	  tenative_version = version;
	  continue;
	}
      XFree (version);
      if (status == Success && type != None)
	{
	  result = w;
	  break;
	}
    }

  if (result && tenative)
    {
      fprintf (stderr,
	       "%s: warning: both version %s (0x%x) and version\n"
	       "\t%s (0x%x) are running.  Using version %s.\n",
	       progname, tenative_version, (unsigned int) tenative,
	       expected_mozilla_version, (unsigned int) result,
	       expected_mozilla_version);
      XFree (tenative_version);
      return result;
    }
  else if (tenative)
    {
      fprintf (stderr,
	       "%s: warning: expected version %s but found version\n"
	       "\t%s (0x%x) instead.\n",
	       progname, expected_mozilla_version,
	       tenative_version, (unsigned int) tenative);
      XFree (tenative_version);
      return tenative;
    }
  else if (result)
    {
      return result;
    }
  else
    {
      fprintf (stderr, "%s: not running on display %s\n", progname,
	       DisplayString (dpy));
      return( (Window) 0 );
    }
}
예제 #5
0
/**
@brief   create pixmaps with the specified name if it is available, otherwise use a default name
@return  void
**/
void
create_frame_name(Display* display, struct Popup_menu *window_menu, struct Frame *temp
, struct Themes *themes, struct Atoms *atoms) {
  char untitled[] = "noname";

  //struct Frame temp = *frame;

  Screen* screen = DefaultScreenOfDisplay(display);
  int black = BlackPixelOfScreen(screen);

  /* Destroy/Free old title if it had one */
  free_frame_name(temp);

  {
    /* Recover EWMH UTF8 name first. If none exists, get the ICCCM ASCII name */
    /* If this succeeds, previous names will be freed if they exists later on */
    Atom ret_type;
    int  ret_format;
    unsigned long ret_nitems;
    unsigned long ret_trailing_bytes;
    temp->window_name = NULL;
    if((XGetWindowProperty (display, temp->framed_window, atoms->name, (long)0, (long)MAX_WM_NAME_LENGTH
    , False, atoms->utf8
    , &ret_type, &ret_format, &ret_nitems, &ret_trailing_bytes
    , (unsigned char **)&temp->window_name ) != Success) || temp->window_name == NULL) {

      //Try and get the non EWMH name
      if(!XFetchName(display, temp->framed_window, &temp->window_name)) {

        //Generate a blank name.
        printf("Warning: unnamed window\n");
        XStoreName(display, temp->framed_window, untitled);
        XFlush(display);
        XFetchName(display, temp->framed_window, &temp->window_name);
        XFlush(display);
      }
    }
  }
  /*
  if(temp->window_name == NULL
  && frame->window_name != NULL
  && strcmp(frame->window_name, untitled) == 0) {
    //it was null and already has the name from untitled above.
    return;
  }
  else
  if( (temp->window_name != NULL
  && frame->window_name != NULL )
  && (strcmp(temp->window_name, frame->window_name) == 0)) {
    XFree(temp->window_name);
    //skip this if the name hasn't changed
    return;
  }
  */

  if(!temp->menu.item) {
    temp->menu.item = XCreateSimpleWindow(display
    , window_menu->widgets[popup_menu_parent].widget
    , themes->popup_menu[l_edge].w, 0
    , XWidthOfScreen(screen), themes->popup_menu[menu_item_mid].h
    , 0, black, black);
    for(int i = 0; i <= inactive; i++) {
      temp->menu.state[i] = XCreateSimpleWindow(display
      , temp->menu.item
      , 0, 0
      , XWidthOfScreen(screen), themes->popup_menu[menu_item_mid].h
      , 0, black, black);
    }
    XSelectInput(display, temp->menu.item, ButtonReleaseMask | EnterWindowMask | LeaveWindowMask);
  }

  temp->menu.width = get_text_width(display, temp->window_name, &themes->font_theme[active]);

  //create corresponding title menu item for this frame
  for(int i = 0; i <= inactive; i++) {
    XUnmapWindow(display, temp->menu.state[i]);
    XUnmapWindow(display, temp->widgets[title_menu_text].state[i]);
    XFlush(display);
    //create the title menu item with the windows title
    create_text_background(display, temp->menu.state[i], temp->window_name
    , &themes->font_theme[i], themes->popup_menu[menu_item_mid].state_p[i]
    , XWidthOfScreen(screen), themes->popup_menu[menu_item_mid].h);

    //TODO make the title for unfocussed windows not bold?
    create_text_background(display, temp->widgets[title_menu_text].state[i], temp->window_name
    , &themes->font_theme[active], themes->window_type[temp->theme_type][title_menu_text].state_p[i]
    , XWidthOfScreen(screen), themes->window_type[temp->theme_type][title_menu_text].h);

    //If this is mapped here, it might be shown in the wrong workspace, //XMapWindow(display, temp->menu.item);
    /* Show changes to background pixmaps */
    XMapWindow(display, temp->menu.state[i]);
    XMapWindow(display, temp->widgets[title_menu_text].state[i]);
  }
  xcheck_raisewin(display, temp->menu.state[active]);
  //these are the items for inside the menu
  //need to create all these windows.

  {
    XWindowAttributes attr;
    XGetWindowAttributes(display, temp->menu.item, &attr);

    if(attr.map_state != IsUnmapped) { //remap all the state pixmaps
      XSelectInput(display, temp->menu.item, 0);
      XSync(display, False);
      XUnmapWindow(display, temp->menu.item);
      XSelectInput(display, temp->menu.item, ButtonReleaseMask | EnterWindowMask | LeaveWindowMask);
      XFlush(display);
      XMapWindow(display, temp->menu.item);
    }
  }
  XFlush(display);

  //*frame = temp;
}
예제 #6
0
파일: test2.c 프로젝트: melanj/lesstif
int
main(int argc, char **argv)
{
  XtAppContext theApp;
  Widget label;
  Pixel fg,bg;
  XmFontList fontlist;

  toplevel = XtVaAppInitialize(&theApp, "drawingArea", NULL, 0,
			       &argc, argv, Fallback, NULL);

  fontlist = XmFontListAppendEntry(NULL,
			   XmFontListEntryCreate("MY_FONT",
						 XmFONT_IS_FONT,
						 XLoadQueryFont(XtDisplay(toplevel), 
 	                                         "-adobe-helvetica-bold-o-normal--17-0-75-75-p-*-iso8859-1")));

  fontlist = XmFontListAppendEntry(fontlist,
			   XmFontListEntryCreate("MY_FONT1",
						 XmFONT_IS_FONT,
						 XLoadQueryFont(XtDisplay(toplevel), 
 	                                         "-adobe-helvetica-bold-r-normal--17-0-75-75-p-*-iso8859-1")));

#if 0
  label= XtVaCreateManagedWidget("Button1", xmLabelWidgetClass, toplevel, XmNfontList, fontlist,
				NULL);
#else
  label= XtVaCreateManagedWidget("Button1", xmLabelWidgetClass, toplevel,
				NULL);
#endif
  XtRealizeWidget(toplevel);

  theDisplay = XtDisplay(toplevel);
  theRootWindow = XDefaultRootWindow(theDisplay);

  fg = XBlackPixelOfScreen(DefaultScreenOfDisplay(theDisplay));
  bg = XWhitePixelOfScreen(DefaultScreenOfDisplay(theDisplay));

  Pix = XmGetPixmap(DefaultScreenOfDisplay(theDisplay),
                    "xlogo64",
                    fg, bg);
  if (Pix == XmUNSPECIFIED_PIXMAP) {
	printf("NO PIXMAP!\n");
	exit(0);
  }

  XtVaSetValues(label,
	        XmNlabelPixmap,Pix, 
                XmNlabelType,XmPIXMAP,
                NULL);

  printf("%p\n", XmDragStart(label, NULL, NULL, 0));
  
{
    static XtWidgetGeometry Expected[] = {
   CWWidth | CWHeight            ,   57,   73,   46,   17, 0,0,0, /* Button1 */ 
    };
    PrintDetails(  toplevel ,Expected);
};
   LessTifTestMainLoop(  toplevel );

  exit(0);
}
예제 #7
0
int x11_shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors)
{
	int index;
	Display* display;
	int displayWidth;
	int displayHeight;
	int numMonitors = 0;
	MONITOR_DEF* monitor;

	if (!getenv("DISPLAY"))
		setenv("DISPLAY", ":0", 1);

	display = XOpenDisplay(NULL);

	if (!display)
	{
		WLog_ERR(TAG, "failed to open display: %s", XDisplayName(NULL));
		return -1;
	}

	displayWidth = WidthOfScreen(DefaultScreenOfDisplay(display));
	displayHeight = HeightOfScreen(DefaultScreenOfDisplay(display));

#ifdef WITH_XINERAMA
	{
		int major, minor;
		int xinerama_event;
		int xinerama_error;
		XineramaScreenInfo* screen;
		XineramaScreenInfo* screens;

		if (XineramaQueryExtension(display, &xinerama_event, &xinerama_error) &&
				XDamageQueryVersion(display, &major, &minor) && XineramaIsActive(display))
		{
			screens = XineramaQueryScreens(display, &numMonitors);

			if (numMonitors > maxMonitors)
				numMonitors = maxMonitors;

			if (screens && (numMonitors > 0))
			{
				for (index = 0; index < numMonitors; index++)
				{
					screen = &screens[index];
					monitor = &monitors[index];

					monitor->left = screen->x_org;
					monitor->top = screen->y_org;
					monitor->right = monitor->left + screen->width;
					monitor->bottom = monitor->top + screen->height;
					monitor->flags = (index == 0) ? 1 : 0;
				}
			}

			XFree(screens);
		}
	}
#endif

	if (numMonitors < 1)
	{
		index = 0;
		numMonitors = 1;

		monitor = &monitors[index];

		monitor->left = 0;
		monitor->top = 0;
		monitor->right = displayWidth;
		monitor->bottom = displayHeight;
		monitor->flags = 1;
	}

	return numMonitors;
}
예제 #8
0
void
XmLStringDrawDirection(Display *dpy,
		       Window win,
		       XmFontList fontlist,
		       XmString string,
		       GC gc,
		       int x,
		       int y,
		       Dimension width,
		       unsigned char alignment,
		       unsigned char layout_direction,
		       unsigned char drawing_direction)
{
	Screen *screen;
	XFontStruct *fontStruct;
	XImage *sourceImage, *destImage;
	Pixmap pixmap;
	GC pixmapGC;
	/*	int sourceWidth, sourceHeight;*/
	int destWidth, destHeight;
	int stringWidth, stringHeight;
	int i, j, bytesPerLine;
	Dimension dW, dH;
	char *data;

	screen = DefaultScreenOfDisplay(dpy);
	XmStringExtent(fontlist, string, &dW, &dH);
	stringWidth = (int)dW;
	stringHeight = (int)dH;
	if (!stringWidth || !stringHeight)
		return;

	/* draw string into 1 bit deep pixmap */
	pixmap = XCreatePixmap(dpy, win, stringWidth, stringHeight, 1);
	pixmapGC = XCreateGC(dpy, pixmap, 0, NULL);
	fontStruct = XLoadQueryFont(dpy, "fixed");
	if (!fontStruct)
		{
		fprintf(stderr, "XmLStringDrawDirection: error - ");
		fprintf(stderr, "can't load fixed font\n");
		return;
		}
	XSetFont(dpy, pixmapGC, fontStruct->fid);
	XSetBackground(dpy, pixmapGC, 0L);
	XSetForeground(dpy, pixmapGC, 0L);
	XFillRectangle(dpy, pixmap, pixmapGC, 0, 0, stringWidth, stringHeight);
	XSetForeground(dpy, pixmapGC, 1L);
	XmStringDraw(dpy, pixmap, fontlist, string, pixmapGC, 0, 0, stringWidth,
		XmALIGNMENT_BEGINNING, layout_direction, 0);
	XFreeFont(dpy, fontStruct);

	/* copy 1 bit deep pixmap into source image */
	sourceImage = XGetImage(dpy, pixmap, 0, 0, stringWidth, stringHeight,
		1, XYPixmap);
	XFreePixmap(dpy, pixmap);

	/* draw rotated text into destination image */
	if (drawing_direction == XmSTRING_UP || drawing_direction == XmSTRING_DOWN)
		{
		destWidth = stringHeight;
		destHeight = stringWidth;
		}
	else
		{
		destWidth = stringWidth;
		destHeight = stringHeight;
		}
	bytesPerLine  = (destWidth - 1) / 8 + 1;
	data = (char *)malloc(bytesPerLine * destHeight);
	destImage = XCreateImage(dpy, DefaultVisualOfScreen(screen),
	    1, XYBitmap, 0, data, destWidth, destHeight, 8, 0);
	for (i = 0; i < stringWidth; i++)
		for (j = 0; j < stringHeight; j++)
			{
			if (drawing_direction == XmSTRING_UP)
				XPutPixel(destImage, j, i,
					XGetPixel(sourceImage, stringWidth - i - 1, j));
			else if (drawing_direction == XmSTRING_DOWN)
				XPutPixel(destImage, stringHeight - j - 1, stringWidth - i - 1,
					XGetPixel(sourceImage, stringWidth - i - 1, j));
			else if (drawing_direction == XmSTRING_LEFT)
				XPutPixel(destImage, i, stringHeight - j - 1,
					XGetPixel(sourceImage, stringWidth - i - 1, j));
			else
				XPutPixel(destImage, i, j,
					XGetPixel(sourceImage, i, j));
			}
	XDestroyImage(sourceImage);

	/* copy rotated image into 1 bit deep pixmap */
	pixmap = XCreatePixmap(dpy, win, destWidth, destHeight, 1);
	XPutImage(dpy, pixmap, pixmapGC, destImage, 0, 0, 0, 0,
	    destWidth, destHeight);
	XDestroyImage(destImage);
	XFreeGC(dpy, pixmapGC);

	/* adjust position for alignment */
	if (drawing_direction == XmSTRING_UP || drawing_direction == XmSTRING_DOWN)
		{
		if (alignment == XmALIGNMENT_BEGINNING)
			;
		else if (alignment == XmALIGNMENT_CENTER)
			y += width / 2 - stringWidth / 2;
		else if (alignment == XmALIGNMENT_END)
			y += (int)width - stringWidth;
		}
	else
		{
		if (alignment == XmALIGNMENT_BEGINNING)
			;
		else if (alignment == XmALIGNMENT_CENTER)
			x += width / 2 - stringWidth / 2;
		else if (alignment == XmALIGNMENT_END)
			x += (int)width - stringWidth;
		}

	/* draw the pixmap as a stipple in the window */
	XSetStipple(dpy, gc, pixmap);
	XSetFillStyle(dpy, gc, FillStippled);
	XSetTSOrigin(dpy, gc, x % destWidth, y % destHeight);
	XFillRectangle(dpy, win, gc, x, y, destWidth, destHeight);
	XFreePixmap(dpy, pixmap);
	XSetFillStyle(dpy, gc, FillSolid);
	}
예제 #9
0
파일: x11.c 프로젝트: lamproae/DirectFB
static DFBResult
InitLocal( DFBX11 *x11, DFBX11Shared *shared, CoreDFB *core )
{
     int i, n;

     XInitThreads();

     if (direct_config_get_int_value( "x11-sync" ))
          x11->Sync = sync_display;
     else
          x11->Sync = sync_display_noop;

     x11->shared = shared;
     x11->core   = core;

     x11->display = XOpenDisplay(getenv("DISPLAY"));
     if (!x11->display) {
          D_ERROR("X11: Error in XOpenDisplay for '%s'\n", getenv("DISPLAY"));
          return DFB_INIT;
     }

     x11->screenptr = DefaultScreenOfDisplay(x11->display);
     x11->screennum = DefaultScreen(x11->display);

     D_DEBUG_AT( X11_Core, "  -> ndepths %d\n", x11->screenptr->ndepths);

     for (i=0; i<x11->screenptr->ndepths; i++) {
          const Depth *depth = &x11->screenptr->depths[i];

          D_DEBUG_AT( X11_Core, "  -> [%d] depth %d, nvisuals %d\n", i, depth->depth, depth->nvisuals );

          for (n=0; n<depth->nvisuals; n++) {
               Visual *visual = &depth->visuals[n];

               D_DEBUG_AT( X11_Core, "[Visual %d] ID 0x%02lx, depth %d, RGB 0x%06lx/0x%06lx/0x%06lx, %d bpRGB, %d entr.\n",
                        n, visual->visualid, depth->depth,
                        visual->red_mask, visual->green_mask, visual->blue_mask,
                        visual->bits_per_rgb, visual->map_entries );

               //if (depth->depth != d)
               //     continue;

               //if (visual->visualid == 0x24) {
               //     x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_RGB32)] = visual;
               //     continue;
               //}

               switch (depth->depth) {
                    case 32:
                         if (visual->red_mask   == 0xff0000 &&
                             visual->green_mask == 0x00ff00 &&
                             visual->blue_mask  == 0x0000ff &&
                             !x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_ARGB)])
                              x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_ARGB)] = visual;
                         break;

                    case 24:
                         if (visual->red_mask   == 0xff0000 &&
                             visual->green_mask == 0x00ff00 &&
                             visual->blue_mask  == 0x0000ff &&
                             !x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_RGB32)])
                              x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_RGB32)] = visual;
                         break;

                    case 16:
                         if (visual->red_mask   == 0xf800 &&
                             visual->green_mask == 0x07e0 &&
                             visual->blue_mask  == 0x001f &&
                             !x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_RGB16)])
                              x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_RGB16)] = visual;
                         break;

                    case 15:
                         if (visual->red_mask   == 0x7c00 &&
                             visual->green_mask == 0x03e0 &&
                             visual->blue_mask  == 0x001f &&
                             !x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_RGB555)])
                              x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_RGB555)] = visual;
                         break;
               }
          }
     }


     DFBSurfacePixelFormat formats[] = { DSPF_ARGB, DSPF_RGB32, DSPF_RGB16, DSPF_RGB555 };

     for (i=0; i<D_ARRAY_SIZE(formats); i++) {
          Visual *visual = x11->visuals[DFB_PIXELFORMAT_INDEX(formats[i])];

          if (visual) {
               D_DEBUG_AT( X11_Core, "  %-20s [Visual ID 0x%02lx] RGB 0x%06lx/0x%06lx/0x%06lx, %d bpRGB, %d entr.\n",
                           dfb_pixelformat_name(formats[i]), visual->visualid, visual->red_mask, visual->green_mask, visual->blue_mask,
                           visual->bits_per_rgb, visual->map_entries );
          }
          else
               D_DEBUG_AT( X11_Core, "  %-20s [NO VISUAL]\n", dfb_pixelformat_name(formats[i]) );
     }


     if (XShmQueryExtension( x11->display ))
          XShmQueryVersion( x11->display, &x11->xshm_major, &x11->xshm_minor, &x11->use_shm );
     x11->use_shm = 0;


     x11->screen = dfb_screens_register( NULL, x11, x11PrimaryScreenFuncs );

     for (i=0; i<shared->outputs * shared->layers; i++) {
          if (!dfb_layers_register( x11->screen, x11, x11PrimaryLayerFuncs ))
               return DFB_INIT;
     }

     return DFB_OK;
}
예제 #10
0
int main(int argc, char *argv[])
{
    int i,j,k,ysize,xsize,header,winY,winX,bysize,bxsize,ret;
    int border,menubar,xmin,ymin,nrow,ncol,nwin;
    char cmdbuf[100],PR[80];

    Display *myDisplay;
    Screen  *myScreen;

    myDisplay= XOpenDisplay("");
    myScreen = DefaultScreenOfDisplay(myDisplay);
    winX = XWidthOfScreen(myScreen);
    winY = XHeightOfScreen(myScreen);
    ret = XCloseDisplay(myDisplay);

    sprintf(PR,"%s","tilesg");

    /* platform parameters (these are for MacOSX): */
    menubar=20;
    /* generic parameters: */
    header=20;
    border=2;

    /* handles args; determine which Vio object to create (file/unix/inet) */
    if (argc == 4) {
        nrow = atoi(argv[1]);
        ncol = atoi(argv[2]);
        nwin = atoi(argv[3]);
    } else {
        fprintf(stderr,"\n");
        fprintf(stderr, "Usage: %s rows cols nwin\n",PR);
        fprintf(stderr,"\n");
        fprintf(stderr,"   Parameter interpretation:\n\n");
        fprintf(stderr,"    rows = number of rows\n");
        fprintf(stderr,"    cols = number of columns\n");
        fprintf(stderr,"    nwin = number of windows\n");
        fprintf(stderr,"\n");
        return 0;
    }

    /* ratio=5/7 */
    ysize = (winY-menubar)/nrow - header - 2*border;
    xsize = winX/ncol - 2*border;
    if (5*xsize > 7*ysize) {
        xsize = (ysize*7)/5;
    } else {
        ysize = (xsize*5)/7;
    }
    fprintf(stderr,"xsize=<%d> ysize=<%d>\n",xsize,ysize);
    bysize = ysize + header + 2*border;
    bxsize = xsize + 2*border;
    for (i=0; i<ncol; i++) {
        for (j=0; j<nrow; j++) {
            k = j + i*nrow;
            if (k < nwin) {
                xmin = winX - (i+1)*bxsize;
                ymin = winY - (j+1)*bysize;
                fprintf(stderr,"k=<%d> xmin=<%d> ymin=<%d>\n",k,xmin,ymin);
                sprintf(cmdbuf, "sg -Mci %d -wpos %d,%d@%d,%d &",
                        k,xsize,ysize,xmin,ymin);
                system(cmdbuf);
            }
        }
    }

    return 0;
}
예제 #11
0
파일: x11.cpp 프로젝트: rhelmot/snes9x
void S9xInitDisplay (int argc, char **argv)
{
	GUI.display = XOpenDisplay(NULL);
	if (GUI.display == NULL)
		FatalError("Failed to connect to X server.");

	GUI.screen     = DefaultScreenOfDisplay(GUI.display);
	GUI.screen_num = XScreenNumberOfScreen(GUI.screen);
	GUI.visual     = DefaultVisualOfScreen(GUI.screen);

	XVisualInfo	plate, *matches;
	int			count;

	plate.visualid = XVisualIDFromVisual(GUI.visual);
	matches = XGetVisualInfo(GUI.display, VisualIDMask, &plate, &count);
	if (!count)
		FatalError("Your X Window System server is unwell!");

	GUI.depth = matches[0].depth;
	if ((GUI.depth != 15 && GUI.depth != 16 && GUI.depth != 24) || (matches[0].c_class != TrueColor))
		FatalError("Requiers 15, 16, 24 or 32-bit color depth supporting TrueColor.");

	GUI.red_shift   = ffs(matches[0].red_mask)   - 1;
	GUI.green_shift = ffs(matches[0].green_mask) - 1;
	GUI.blue_shift  = ffs(matches[0].blue_mask)  - 1;
	GUI.red_size    = matches[0].red_mask   >> GUI.red_shift;
	GUI.green_size  = matches[0].green_mask >> GUI.green_shift;
	GUI.blue_size   = matches[0].blue_mask  >> GUI.blue_shift;
	if (GUI.depth == 16 && GUI.green_size == 63)
		GUI.green_shift++;

	XFree(matches);

	switch (GUI.depth)
	{
		default:
		case 32:
		case 24:
			S9xSetRenderPixelFormat(RGB555);
			GUI.pixel_format = 555;
			break;

		case 16:
			if (GUI.red_size != GUI.green_size || GUI.blue_size != GUI.green_size)
			{
				// 565 format
				if (GUI.green_shift > GUI.blue_shift && GUI.green_shift > GUI.red_shift)
					S9xSetRenderPixelFormat(GBR565);
				else
				if (GUI.red_shift > GUI.blue_shift)
					S9xSetRenderPixelFormat(RGB565);
				else
					S9xSetRenderPixelFormat(BGR565);

				GUI.pixel_format = 565;
				break;
			}
			// FALL ...
		case 15:
			if (GUI.green_shift > GUI.blue_shift && GUI.green_shift > GUI.red_shift)
				S9xSetRenderPixelFormat(GBR555);
			else
			if (GUI.red_shift > GUI.blue_shift)
				S9xSetRenderPixelFormat(RGB555);
			else
				S9xSetRenderPixelFormat(BGR555);

			GUI.pixel_format = 555;
			break;
	}

	S9xBlitFilterInit();
	S9xBlit2xSaIFilterInit();
	S9xBlitHQ2xFilterInit();

	XSetWindowAttributes	attrib;

	memset(&attrib, 0, sizeof(attrib));
	attrib.background_pixel = BlackPixelOfScreen(GUI.screen);
	attrib.colormap = XCreateColormap(GUI.display, RootWindowOfScreen(GUI.screen), GUI.visual, AllocNone);

	GUI.window = XCreateWindow(GUI.display, RootWindowOfScreen(GUI.screen),
							   (WidthOfScreen(GUI.screen) - SNES_WIDTH * 2) / 2, (HeightOfScreen(GUI.screen) - SNES_HEIGHT_EXTENDED * 2) / 2,
							   SNES_WIDTH * 2, SNES_HEIGHT_EXTENDED * 2, 0, GUI.depth, InputOutput, GUI.visual, CWBackPixel | CWColormap, &attrib);

	static XColor	bg, fg;
	static char		data[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
	Pixmap			bitmap;

	bitmap = XCreateBitmapFromData(GUI.display, GUI.window, data, 8, 8);
	GUI.point_cursor = XCreatePixmapCursor(GUI.display, bitmap, bitmap, &fg, &bg, 0, 0);
	XDefineCursor(GUI.display, GUI.window, GUI.point_cursor);
	GUI.cross_hair_cursor = XCreateFontCursor(GUI.display, XC_crosshair);

	GUI.gc = DefaultGCOfScreen(GUI.screen);

	XSizeHints	Hints;
	XWMHints	WMHints;

	memset((void *) &Hints, 0, sizeof(XSizeHints));
	memset((void *) &WMHints, 0, sizeof(XWMHints));

	Hints.flags      = PSize | PMinSize | PMaxSize;
	Hints.min_width  = Hints.max_width  = Hints.base_width  = SNES_WIDTH * 2;
	Hints.min_height = Hints.max_height = Hints.base_height = SNES_HEIGHT_EXTENDED * 2;
	WMHints.input    = True;
	WMHints.flags    = InputHint;

	XSetWMHints(GUI.display, GUI.window, &WMHints);
	XSetWMNormalHints(GUI.display, GUI.window, &Hints);
	XSelectInput(GUI.display, GUI.window, FocusChangeMask | ExposureMask | KeyPressMask | KeyReleaseMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask);

	XMapRaised(GUI.display, GUI.window);
	XClearWindow(GUI.display, GUI.window);

	SetupImage();

	switch (GUI.depth)
	{
		default:
		case 32:
			GUI.bytes_per_pixel = 4;
			break;

		case 24:
			if (GUI.image->bits_per_pixel == 24)
				GUI.bytes_per_pixel = 3;
			else
				GUI.bytes_per_pixel = 4;
			break;

		case 15:
		case 16:
			GUI.bytes_per_pixel = 2;
			break;
	}

	wmDeleteMessage = XInternAtom(GUI.display, "WM_DELETE_WINDOW", false);
	XSetWMProtocols(GUI.display, GUI.window, &wmDeleteMessage, 1);
}
예제 #12
0
void wxTopLevelWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
    int old_x = m_x;
    int old_y = m_y;
    int old_width = m_width;
    int old_height = m_height;

    if (x != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
        m_x = x;

    if (y != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
        m_y = y;

    if (width != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
        m_width = width;

    if (height != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
        m_height = height;

    if (m_x == old_x && m_y == old_y && m_width == old_width && m_height == old_height)
        return;

    // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);

#if !wxUSE_NANOX
    XSizeHints size_hints;
    size_hints.flags = 0;
    size_hints.flags |= PPosition;
    size_hints.flags |= PSize;
    size_hints.x = m_x;
    size_hints.y = m_y;
    size_hints.width = m_width;
    size_hints.height = m_height;
    XSetWMNormalHints( wxGlobalDisplay(), (Window) X11GetMainWindow(), &size_hints);
#endif

    wxWindowX11::DoSetSize(x, y, width, height, sizeFlags);

#if 0
    Display *display = wxGlobalDisplay();
    Window root = RootWindowOfScreen(DefaultScreenOfDisplay(display));
    Window parent_window = window,
        next_parent   = window;

    // search for the parent that is child of ROOT, because the WM may
    // reparent twice and notify only the next parent (like FVWM)
    while (next_parent != root) {
        Window *theChildren;
#if wxUSE_NANOX
        GR_COUNT n;
#else
        unsigned int n;
#endif
        parent_window = next_parent;
        XQueryTree(display, parent_window, &root,
            &next_parent, &theChildren, &n);
        XFree(theChildren); // not needed
    }

    XWindowChanges windowChanges;
    windowChanges.x = x;
    windowChanges.y = y;
    windowChanges.width = width;
    windowChanges.height = height;
    windowChanges.stack_mode = 0;
    int valueMask = CWX | CWY | CWWidth | CWHeight;

    if (x != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
    {
        valueMask |= CWX;
    }
    if (y != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
    {
        valueMask |= CWY;
    }
    if (width != wxDefaultCoord)
    {
        windowChanges.width = wxMax(1, width);
        valueMask |= CWWidth;
    }
    if (height != wxDefaultCoord)
    {
        windowChanges.height = wxMax(1, height);
        valueMask |= CWHeight;
    }

    XConfigureWindow( display, parent_window, valueMask, &windowChanges );
#endif
}
예제 #13
0
/**
@brief    Reparents the specified framed_window to a newly created frame.
@return   returns 1 if successful or 0 if no window was created.
@todo     A the moment each pointer is totally valid, in the future it will merely be an alias from another datastructure.
**/
int
create_frame(Display *display, struct Frame* frame
, Window framed_window, struct Popup_menu *window_menu, struct Separators *seps, const struct Workarea *workarea, struct Themes *themes
, struct Cursors *cursors, struct Atoms *atoms) {
  XWindowAttributes get_attributes;

  //printf("Creating frames->list[%d] with window %lu, connection %lu\n"
  //, frames->used, (unsigned long)framed_window, (unsigned long)display);
  //add this window to the save set as soon as possible so that if an error occurs it is still available

  XAddToSaveSet(display, framed_window);
  XSync(display, False);
  XGetWindowAttributes(display, framed_window, &get_attributes);

  /*** Set up defaults ***/
  frame->focussed = False;
  frame->sticky = False;
  frame->window_name = NULL;
  frame->framed_window = framed_window;
  frame->type = unknown;
  frame->theme_type = unknown;
  frame->mode = unset;
  frame->state = none;
  frame->wants_attention = False;
  frame->transient = 0;
  frame->width_inc = 1;
  frame->height_inc = 1;
  frame->menu.item = 0;

  frame->w_inc_offset = 0;
  frame->h_inc_offset = 0;

  frame->w = get_attributes.width;
  frame->h = get_attributes.height;

  get_frame_type_and_mode (display, frame, atoms, themes);

  frame->x = get_attributes.x - themes->window_type[frame->theme_type][window].x;
  frame->y = get_attributes.y - themes->window_type[frame->theme_type][window].y;
  frame->hspace = 0 - themes->window_type[frame->theme_type][window].w;
  frame->vspace = 0 - themes->window_type[frame->theme_type][window].h;


  // This is not set to the something sensive, like the size of the workarea
  // as it may change and we can't tell if it's a default value or a real
  // one set by the client.
  // Instead, always use the MIN of the workarea dimension and these values
  frame->max_width  = INT_MAX;
  frame->max_height = INT_MAX;

  //prevent overly small windows with these sensible defaults
  frame->min_width  = MINWIDTH + frame->hspace;
  frame->min_height = MINHEIGHT + frame->vspace;

  #ifdef ALLOW_OVERSIZE_WINDOWS_WITHOUT_MINIMUM_HINTS
  Screen* screen = DefaultScreenOfDisplay(display);
  /* Ugh Horrible.  */
  /* Many apps that are resizeable ask to be the size of the screen and since windows
     often don't specifiy their minimum size, we have no other way of knowing if they
     really need to be that size or not.  In case they do, this specifies that their
     current width is their minimum size, in the hope that it is overridden by the
     size hints. This kind of behaviour causes problems on small screens like the
     eee pc. */
  if(frame->w > XWidthOfScreen(screen))  frame->min_width = frame->w;
  if(frame->h > XHeightOfScreen(screen)) frame->min_height = frame->h;
  #endif

  /* This requires hspace and vspace to be set as well as the incremental hints */
  get_frame_hints(display, frame);

  frame_type_settings(display, frame, workarea);

  //Don't manage splash screens, they just cause the workspace to be created and instantly destroyed
  if(frame->type == splash) {
    XMapWindow(display, framed_window);
    XFlush(display);
    return 0;
  }


  get_frame_state(display, frame, atoms);
  create_frame_subwindows(display, frame, themes, cursors);
  create_frame_name(display, window_menu, frame, themes, atoms);

  get_frame_wm_hints(display, frame);  //this might need to change the focus, it's mode (to hidden) and so on
  get_frame_strut_hints_as_normal_hints(display, frame, atoms);

  //_NET_FRAME_EXTENTS, left, right, top, bottom, CARDINAL[4]/32
  int32_t ewmh_frame_extents[4] = { themes->window_type[frame->theme_type][window].x
  , themes->window_type[frame->theme_type][window].y
  , - themes->window_type[frame->theme_type][window].x - themes->window_type[frame->theme_type][window].w
  , - themes->window_type[frame->theme_type][window].y - themes->window_type[frame->theme_type][window].h
  };

  XChangeProperty(display, framed_window, atoms->frame_extents, XA_CARDINAL
  , 32, PropModeReplace, (unsigned char *)ewmh_frame_extents, 4);

  XSetWindowBorderWidth(display, framed_window, 0);

  change_frame_mode(display, frame, unset, workarea, themes);

  #ifdef CRASH_ON_BUG
  XGrabServer(display);
  XSetErrorHandler(supress_xerror);
  #endif

  XSelectInput(display, framed_window,  0);

  //reparent the framed_window to frame->widgets[window].widget
  XReparentWindow(display, framed_window, frame->widgets[window].widget, 0, 0);
  //for some odd reason the reparent only reports an extra unmap event if the window was already unmapped
  XRaiseWindow(display, framed_window);
  XMapWindow(display, frame->widgets[window].widget);

  #ifdef CRASH_ON_BUG
  XSetErrorHandler(NULL);
  XUngrabServer(display);
  #endif

  XSelectInput(display, framed_window,  PropertyChangeMask); //Property notify is used to update titles
  XSelectInput(display, frame->widgets[window].widget
  , SubstructureRedirectMask | SubstructureNotifyMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask);

  //Some windows only send the destroy event (e.g., gimp splash screen)
  XSync(display, False);

  //Intercept clicks so we can set the focus and possibly raise floating windows
  XGrabButton(display, Button1, 0, frame->widgets[window].widget
  , False, ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);

  //do it for numlock as well
  XGrabButton(display, Button1, Mod2Mask, frame->widgets[window].widget
  , False, ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);

  frame->w += frame->hspace;
  frame->h += frame->vspace;

  check_frame_limits(display, frame, workarea, themes);

  resize_frame(display, frame, themes);
  stack_frame(display, frame, seps);
  change_frame_state(display, frame, frame->state, seps, workarea, themes, atoms);
  XMoveResizeWindow(display, framed_window, 0, 0, frame->w - frame->hspace, frame->h - frame->vspace);
  XMoveWindow(display, framed_window, 0, 0);
  XMapWindow(display, framed_window);

  XFlush(display);
  save_frame_initial_state(frame);
  return 1;
}
NS_METHOD 
compzillaRenderingContext::SetDimensions (PRInt32 width, PRInt32 height)
{
  DEBUG ("SetDimensions (%d,%d)\n", width, height);

    Destroy();

#if false
    // Check that the dimensions are sane
    if (!CheckSaneImageSize(width, height))
        return NS_ERROR_FAILURE;
#endif

    mWidth = width;
    mHeight = height;

#ifdef MOZ_CAIRO_GFX
    DEBUG ("thebes\n");

    mThebesSurface = gfxPlatform::GetPlatform()->CreateOffscreenSurface(gfxIntSize (width, height), gfxASurface::ImageFormatARGB32);
    mThebesContext = new gfxContext(mThebesSurface);

    mSurface = mThebesSurface->CairoSurface();
    cairo_surface_reference(mSurface);
    mCairo = mThebesContext->GetCairo();
    cairo_reference(mCairo);

    DEBUG ("/thebes\n");
#else
    // non-cairo gfx
    // On most current X servers, using the software-only surface
    // actually provides a much smoother and faster display.
    // However, we provide MOZ_CANVAS_USE_RENDER for whomever wants to
    // go that route.

    //if (getenv("MOZ_CANVAS_USE_RENDER")) {
        XRenderPictFormat *fmt = XRenderFindStandardFormat (GDK_DISPLAY(),
                                                            PictStandardARGB32);
        if (fmt) {
            int npfmts = 0;
            XPixmapFormatValues *pfmts = XListPixmapFormats(GDK_DISPLAY(), &npfmts);
            for (int i = 0; i < npfmts; i++) {
                if (pfmts[i].depth == 32) {
                    npfmts = -1;
                    break;
                }
            }
            XFree(pfmts);

            if (npfmts == -1) {
                mSurfacePixmap = XCreatePixmap (GDK_DISPLAY(),
                                                DefaultRootWindow(GDK_DISPLAY()),
                                                width, height, 32);
                mSurface = cairo_xlib_surface_create_with_xrender_format
                    (GDK_DISPLAY(), mSurfacePixmap, DefaultScreenOfDisplay(GDK_DISPLAY()),
                     fmt, mWidth, mHeight);
            }
        }
    //}

    // fall back to image surface
    if (!mSurface) {
        mImageSurfaceData = (PRUint8*) PR_Malloc (mWidth * mHeight * 4);
        if (!mImageSurfaceData)
            return NS_ERROR_OUT_OF_MEMORY;

        mSurface = cairo_image_surface_create_for_data (mImageSurfaceData,
                                                        CAIRO_FORMAT_ARGB32,
                                                        mWidth, mHeight,
                                                        mWidth * 4);
    }

    mCairo = cairo_create(mSurface);
#endif

    cairo_set_operator(mCairo, CAIRO_OPERATOR_CLEAR);
    cairo_new_path(mCairo);
    cairo_rectangle(mCairo, 0, 0, mWidth, mHeight);
    cairo_fill(mCairo);

    cairo_set_line_width(mCairo, 1.0);
    cairo_set_operator(mCairo, CAIRO_OPERATOR_OVER);
    cairo_set_miter_limit(mCairo, 10.0);
    cairo_set_line_cap(mCairo, CAIRO_LINE_CAP_BUTT);
    cairo_set_line_join(mCairo, CAIRO_LINE_JOIN_MITER);

    cairo_new_path(mCairo);

    return NS_OK;
}
예제 #15
0
EggTrayIcon *egg_tray_icon_new(const gchar * name)
{
	return egg_tray_icon_new_for_xscreen(DefaultScreenOfDisplay(gdk_display), name);
}
/**
 * Try the direct path.
 * @param status the status returned by the callback, if we took the direct path
 * @return True if we took the direct path
 */
static cairo_bool_t
_draw_with_xlib_direct (cairo_t *cr,
                        Display *default_display,
                        cairo_xlib_drawing_callback callback,
                        void *closure,
                        int bounds_width, int bounds_height,
                        cairo_xlib_drawing_support_t capabilities)
{
    cairo_surface_t *target;
    Drawable d;
    cairo_matrix_t matrix;
    short offset_x, offset_y;
    cairo_bool_t needs_clip;
    XRectangle rectangles[MAX_STATIC_CLIP_RECTANGLES];
    int rect_count;
    double device_offset_x, device_offset_y;
    int max_rectangles;
    Screen *screen;
    Visual *visual;
    cairo_bool_t have_rectangular_clip;

    target = cairo_get_group_target (cr);
    cairo_surface_get_device_offset (target, &device_offset_x, &device_offset_y);
    d = cairo_xlib_surface_get_drawable (target);

    cairo_get_matrix (cr, &matrix);
    
    /* Check that the matrix is a pure translation */
    /* XXX test some approximation to == 1.0 here? */
    if (matrix.xx != 1.0 || matrix.yy != 1.0 || matrix.xy != 0.0 || matrix.yx != 0.0) {
        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: matrix not a pure translation\n");
        return False;
    }
    /* Check that the matrix translation offsets (adjusted for
       device offset) are integers */
    if (!_convert_coord_to_short (matrix.x0 + device_offset_x, &offset_x) ||
        !_convert_coord_to_short (matrix.y0 + device_offset_y, &offset_y)) {
        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: non-integer offset\n");
        return False;
    }
    
    max_rectangles = 0;
    if (capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_RECT) {
      max_rectangles = 1;
    }
    if (capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_LIST) {
      max_rectangles = MAX_STATIC_CLIP_RECTANGLES;
    }
    
    /* Check that the clip is rectangular and aligned on unit boundaries. */
    /* Temporarily set the matrix for _get_rectangular_clip. It's basically
       the identity matrix, but we must adjust for the fact that our
       offset-rect is in device coordinates. */
    cairo_identity_matrix (cr);
    cairo_translate (cr, -device_offset_x, -device_offset_y);
    have_rectangular_clip =
        _get_rectangular_clip (cr,
                               offset_x, offset_y, bounds_width, bounds_height,
                               &needs_clip,
                               rectangles, max_rectangles, &rect_count);
    cairo_set_matrix (cr, &matrix);
    if (!have_rectangular_clip) {
        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: unsupported clip\n");
        return False;
    }

    /* Stop now if everything is clipped out */
    if (needs_clip && rect_count == 0) {
        CAIRO_XLIB_DRAWING_NOTE("TAKING FAST PATH: all clipped\n");
        return True;
    }
      
    /* Check that the operator is OVER */
    if (cairo_get_operator (cr) != CAIRO_OPERATOR_OVER) {
        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: non-OVER operator\n");
        return False;
    }
    
    /* Check that the offset is supported */  
    if (!(capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_OFFSET) &&
        (offset_x != 0 || offset_y != 0)) {
        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: unsupported offset\n");
        return False;
    }
    
    /* Check that the target surface is an xlib surface. Do this late because
       we might complete early above when when the object to be drawn is
       completely clipped out. */
    if (!d) {
        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: non-X surface\n");
        return False;
    }
    
    /* Check that the display is supported */  
    screen = cairo_xlib_surface_get_screen (target);
    if (!(capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_ALTERNATE_SCREEN) &&
        screen != DefaultScreenOfDisplay (default_display)) {
        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: non-default display\n");
        return False;
    }
        
    /* Check that there is a visual */
    visual = cairo_xlib_surface_get_visual (target);
    if (!visual) {
        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: no Visual for surface\n");
        return False;
    }        
    /* Check that the visual is supported */
    if (!(capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_NONDEFAULT_VISUAL) &&
        DefaultVisualOfScreen (screen) != visual) {
        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: non-default visual\n");
        return False;
    }
  
    /* we're good to go! */
    CAIRO_XLIB_DRAWING_NOTE("TAKING FAST PATH\n");
    cairo_surface_flush (target);
    callback (closure, screen, d, visual, offset_x, offset_y, rectangles,
              needs_clip ? rect_count : 0);
    cairo_surface_mark_dirty (target);
    return True;
}
예제 #17
0
파일: textbox-test.c 프로젝트: harj0/rofi
int main ( int argc, char **argv )
{

    // Get DISPLAY
    const char *display_str = getenv ( "DISPLAY" );
    if ( !( display = XOpenDisplay ( display_str ) ) ) {
        fprintf ( stderr, "cannot open display!\n" );
        return EXIT_FAILURE;
    }

    TASSERT( display != NULL );
    Screen *screen = DefaultScreenOfDisplay ( display );
    Window root    = RootWindow ( display, XScreenNumberOfScreen ( screen ) );
    Window mw = XCreateSimpleWindow ( display, root, 0, 0, 200, 100,
                                           config.menu_bw,
                                           color_get ( display, config.menu_bc ),
                                           color_get ( display, config.menu_bg ) );
    TASSERT( mw != None );

    textbox_setup ( config.menu_bg, config.menu_fg, 
                    config.menu_hlbg, config.menu_hlfg ); 
    textbox *box = textbox_create(mw , TB_EDITABLE|TB_AUTOWIDTH|TB_AUTOHEIGHT, 0,0, -1, -1, NORMAL, "test");
    TASSERT( box != NULL );

    textbox_cursor_end ( box );
    TASSERT ( box->cursor == 4); 
    textbox_cursor ( box, -1 );
    TASSERT ( box->cursor == 0 ); 
    textbox_cursor ( box, 8 );
    TASSERT ( box->cursor == 4 ); 
    textbox_cursor ( box, 2 );
    TASSERT ( box->cursor == 2 ); 
    textbox_insert ( box, 3, "bo");
    TASSERT ( strcmp(box->text, "tesbot") == 0 ); 
    textbox_cursor_end ( box );
    TASSERT ( box->cursor == 6); 

    TASSERT( textbox_get_width( box) > 0 );
    TASSERT( textbox_get_height( box) > 0 );

    TASSERT( textbox_get_width( box) >= textbox_get_font_width( box)  );
    TASSERT( textbox_get_height( box) >= textbox_get_font_height( box)  );

    TASSERT( textbox_get_estimated_char_width ( box) > 0 );

    textbox_cursor_bkspc ( box );
    TASSERT ( strcmp(box->text, "tesbo") == 0 ); 
    TASSERT ( box->cursor == 5); 

    textbox_cursor_dec ( box );
    TASSERT ( box->cursor == 4); 
    textbox_cursor_del ( box );
    TASSERT ( strcmp(box->text, "tesb") == 0 ); 
    textbox_cursor_dec ( box );
    TASSERT ( box->cursor == 3); 
    textbox_cursor_inc ( box );
    TASSERT ( box->cursor == 4); 
    textbox_cursor_inc ( box );
    TASSERT ( box->cursor == 4); 
    // Cursor after delete section.
    textbox_delete ( box, 0, 1 );
    TASSERT ( strcmp(box->text, "esb") == 0 ); 
    TASSERT ( box->cursor == 3); 
    // Cursor before delete.
    textbox_text( box, "aap noot mies");
    TASSERT ( strcmp(box->text, "aap noot mies") == 0 ); 
    textbox_cursor( box, 3 );
    TASSERT ( box->cursor == 3); 
    textbox_delete ( box, 3, 6 );
    TASSERT ( strcmp(box->text, "aapmies") == 0 ); 
    TASSERT ( box->cursor == 3); 

    // Cursor within delete
    textbox_text( box, "aap noot mies");
    TASSERT ( strcmp(box->text, "aap noot mies") == 0 ); 
    textbox_cursor( box, 5 );
    TASSERT ( box->cursor == 5); 
    textbox_delete ( box, 3, 6 );
    TASSERT ( strcmp(box->text, "aapmies") == 0 ); 
    TASSERT ( box->cursor == 3); 
    // Cursor after delete. 
    textbox_text( box, "aap noot mies");
    TASSERT ( strcmp(box->text, "aap noot mies") == 0 ); 
    textbox_cursor( box, 11 );
    TASSERT ( box->cursor == 11); 
    textbox_delete ( box, 3, 6 );
    TASSERT ( strcmp(box->text, "aapmies") == 0 ); 
    TASSERT ( box->cursor == 5); 


    textbox_font ( box, HIGHLIGHT );
    textbox_draw( box );

    textbox_show( box );
    textbox_move ( box, 12, 13);
    TASSERT ( box->x == 12 );
    TASSERT ( box->y == 13 );
    textbox_hide( box );

    textbox_free(box);
    textbox_cleanup();
    XDestroyWindow ( display, mw);
    XCloseDisplay ( display );
}
예제 #18
0
	BD_UINT32 LinuxWindow::Create( const BD_UINT32 p_Width,
		const BD_UINT32 p_Height, const BD_BOOL p_Fullscreen )
	{
		m_pDisplay = XOpenDisplay( 0 );

		if( !m_pDisplay )
		{
			bdTrace( BD_NULL, "[BD::LinuxWindow::Create] <ERROR> "
				"Failed to open X display\n" );

			return BD_ERROR;
		}

		m_Fullscreen = p_Fullscreen;

		// HARDCODED!
		BD_SINT32 GLXAttribs[ ] =
		{
			GLX_X_RENDERABLE,	True,
			GLX_DRAWABLE_TYPE,	GLX_WINDOW_BIT,
			GLX_RENDER_TYPE,	GLX_RGBA_BIT,
			GLX_X_VISUAL_TYPE,	GLX_TRUE_COLOR,
			GLX_RED_SIZE,		8,
			GLX_GREEN_SIZE,		8,
			GLX_BLUE_SIZE,		8,
			GLX_ALPHA_SIZE,		8,
			GLX_DEPTH_SIZE,		24,
			GLX_STENCIL_SIZE,	8,
			GLX_DOUBLEBUFFER,	True,
			None
		};
		// !HARDCODED

		// For now, we will only care about GLX 1.3
		BD_SINT32 Major = 0, Minor = 0;

		if( !glXQueryVersion( m_pDisplay, &Major, &Minor ) ||
			( ( Major == 1 ) && ( Minor < 3 ) ) || ( Major < 1 ) )
		{
			bdTrace( BD_NULL, "[BD::LinuxWindow::Create] <ERROR> "
				"GLX Version not 1.3 or greater\n" );
			return BD_ERROR;
		}

		bdTrace( BD_NULL, "[BD::LinuxWindow::Create] <INFO> "
			"Attempting to retrieve framebuffer configurations\n" );

		BD_SINT32 FBCount = 0;
		GLXFBConfig *pFBC = glXChooseFBConfig( m_pDisplay,
			DefaultScreen( m_pDisplay ), GLXAttribs, &FBCount );

		if( !pFBC )
		{
			bdTrace( BD_NULL, "[BD::LinuxWindow::Create] <ERROR> "
				"Failed to create a GLXFBConfig\n" );
			return BD_ERROR;
		}

		bdTrace( BD_NULL, "[BD::LinuxWindow::Create] <INFO> "
			"Found %d matching framebuffer configurations\n", FBCount );

		GLXFBConfig FBC = pFBC[ 0 ];

		m_pXVI = glXGetVisualFromFBConfig( m_pDisplay, FBC );

		XFree( pFBC );

		bdTrace( BD_NULL, "[BD::LinuxWindow::Create] <INFO> "
			"Visual ID in use: 0x%08X\n", m_pXVI->visualid );

		XSetWindowAttributes WinAttribs;
		Colormap ColourMap = XCreateColormap( m_pDisplay,
			RootWindow( m_pDisplay, m_pXVI->screen ), m_pXVI->visual,
			AllocNone );

		WinAttribs.colormap = ColourMap;
		WinAttribs.background_pixmap = None;
		WinAttribs.border_pixel = 0;
		WinAttribs.event_mask = StructureNotifyMask | ExposureMask |
			KeyPressMask | KeyReleaseMask |
			ButtonPressMask | ButtonReleaseMask | PointerMotionMask;

		Screen *pScreen = DefaultScreenOfDisplay( m_pDisplay );

		if( m_Fullscreen == BD_TRUE )
		{
			m_Width = WidthOfScreen( pScreen );
			m_Height = HeightOfScreen( pScreen );
		}
		else
		{
			m_Width = p_Width;
			m_Height = p_Height;
		}

		BD::GLWSExtBind( m_pDisplay, m_pXVI->screen );

		m_Window = XCreateWindow( m_pDisplay,
			RootWindow( m_pDisplay, m_pXVI->screen ),
			0, 0, m_Width, m_Height, 0, m_pXVI->depth, InputOutput,
			m_pXVI->visual, CWEventMask | CWColormap | CWBorderPixel,
			&WinAttribs );

		if( !m_Window )
		{
			bdTrace( BD_NULL, "[BD::LinuxWindow::CreateWindow] <INFO> "
				"Failed to create window\n" );
			return BD_ERROR;
		}

		bdTrace( BD_NULL, "[BD::LinuxWindow::CreateWindow] <INFO> "
			"m_Window: 0x%08X | Width: %d | Height %d | Fullscreen: %s\n",
			m_Window, m_Width, m_Height, ( m_Fullscreen ? "True" : "False" ) );

		XMapWindow( m_pDisplay, m_Window );
		XMapRaised( m_pDisplay, m_Window );

		XStoreName( m_pDisplay, m_Window, "BrainDead" );
		XMoveWindow( m_pDisplay, m_Window, 0, 0 );
		XRaiseWindow( m_pDisplay, m_Window );

		XSync( m_pDisplay, False );

		// Install an X error handler so the application won't exit if
		// GL 3.0+ context allocation fails
		g_sContextError = BD_FALSE;
		int ( *pOldHandler )( Display *, XErrorEvent * ) =
			XSetErrorHandler( &ContextErrorHandler );

		if( !bglwsCreateContextAttribsARB )
		{
			// Create a GLX 1.3 context for GL <2.1
			bdTrace( BD_NULL, "[BD::LinuxWindow::Create] <INFO> "
				"Creating a GLX 1.3 context\n" );
			m_GLXContext = glXCreateNewContext( m_pDisplay, FBC, GLX_RGBA_TYPE,
				0, True );
		}
		else
		{
			BD_SINT32 GLVersions [ ] =
			{
				4, 3,
				4, 2,
				4, 1,
				4, 0,
				3, 3,
				3, 2,
				3, 1,
				3, 0,
				2, 1,
				2, 0,
				1, 5,
				1, 4,
				1, 3, 
				1, 2,
				1, 1,
				1, 0
			};

			int ContextAttribs [ ] =
			{
				GLX_CONTEXT_MAJOR_VERSION_ARB,	0,
				GLX_CONTEXT_MINOR_VERSION_ARB,	0,
#ifdef BUILD_DEBUG
				GLX_CONTEXT_FLAGS_ARB,	GLX_CONTEXT_DEBUG_BIT_ARB,
#endif
				// Add forward-compatible and debug if debug
				None
			};

			for( BD_MEMSIZE i = 0;
				i < ( sizeof( GLVersions ) / sizeof( BD_SINT32 ) / 2 ); ++i )
			{
				bdTrace( BD_NULL, "[BD::LinuxWindow::Create] <INFO> "
					"Attempting to create a GLX context for OpenGL "
					"%ld.%ld... ",
					GLVersions[ i*2 ], GLVersions[ i*2+1 ] );	
				ContextAttribs[ 1 ] = GLVersions[ i*2 ];
				ContextAttribs[ 3 ] = GLVersions[ i*2+1 ];

				m_GLXContext = bglwsCreateContextAttribsARB( m_pDisplay, FBC,
					0, True, ContextAttribs );

				XSync( m_pDisplay, False );

				if( !g_sContextError && m_GLXContext )
				{
					bdTrace( BD_NULL, "[ OK ]\n" );
					break;
				}
				g_sContextError = BD_FALSE;
				bdTrace( BD_NULL, "\n" );
			}
		}

		// Sync to make sure any errors are processed
		XSync( m_pDisplay, False );

		// Restore the  original error handler
		XSetErrorHandler( pOldHandler );

		if( g_sContextError || !m_GLXContext )
		{
			bdTrace( BD_NULL, "[BD::LinuxWindow::Create] <ERROR> "
				"Failed to create an OpenGL context\n" );
			return BD_ERROR;
		}

		if( !glXIsDirect( m_pDisplay, m_GLXContext ) )
		{
			bdTrace( BD_NULL, "[BD::LinuxWindow::Create] <WARN> "
				"Indirect GLX rendering context\n" );
		}
		else
		{
			bdTrace( BD_NULL, "[BD::LinuxWindow::Create] <INFO> "
				"Direct GLX rendering context\n" );
		}

		glXMakeCurrent( m_pDisplay, m_Window, m_GLXContext );
		
		// Get the version information to initialise the GL Extensions
		GLint GLMajor = 0, GLMinor = 0;

		// Attempt to get the major and minor using the GL 3.0+ method
		bglGetIntegerv( GL_MAJOR_VERSION, &GLMajor );
		bglGetIntegerv( GL_MINOR_VERSION, &GLMinor );

		// The GL_*_VERSION parameters are not recognised
		GLenum GLErr = bglGetError( );
		if( GLErr == GL_INVALID_ENUM )
		{
			// Resort to using the <GL 3.0 method
			const char *pGLVersion = ( const char * )glGetString( GL_VERSION );

			// The first number up to the first period /should/ be the major
			BD_MEMSIZE Separator = 0;
			BD_MEMSIZE StrCount = 0;
			BD_MEMSIZE StrLoc = 0;

			GLMajor = 0;
			GLMinor = 0;

			char *pNum = BD_NULL;
			for( BD_MEMSIZE i = 0; i < strlen( pGLVersion ); ++i )
			{
				char c = pGLVersion[ i ];
				if( c == '.' )
				{
					pNum = new char[ StrCount+1 ];

					strncpy( pNum, pGLVersion+StrLoc, StrCount );
					pNum[ StrCount ] = '\0';

					StrLoc = StrCount+1;
					StrCount = 0;
					// Skip the '.'
					++i;

					if( GLMajor != 0 )
					{
						GLMinor = atoi( pNum );
						break;
					}	
					if( GLMajor == 0 )
					{
						GLMajor = atoi( pNum );
					}
				}
				StrCount++;
			}

			delete [ ] pNum;
		}

		if( BD::GLExtBind( GLMajor, GLMinor ) != BD_OK )
		{
			bdTrace( BD_NULL, "[BD::LinuxRenderer::Create] <ERROR> "
				"Failed to bind OpenGL %d.%d extensions\n", GLMajor, GLMinor );	
			bdTrace( BD_NULL, "[ FAIL ]\n" );
			return BD_ERROR;
		}

		bdTrace( BD_NULL, "[BD::LinuxRenderer::Create] <INFO> "
			"Bound OpenGL %d.%d extensions\n", GLMajor, GLMinor );

		bglViewport( 0, 0, m_Width, m_Height );

		return BD_OK;
	}
예제 #19
0
/**
@brief   This function creates the windows which make up the actual frame and its widgets.
@return  void
**/
static void
create_frame_subwindows (Display *display, struct Frame *frame, struct Themes *themes, struct Cursors *cursors) {
  Window root = DefaultRootWindow(display);
  Screen* screen = DefaultScreenOfDisplay(display);
  int black = BlackPixelOfScreen(screen);

  frame->widgets[frame_parent].widget = XCreateSimpleWindow(display, root
  , frame->x, frame->y,  frame->w, frame->h, 0, black, black);
  XFlush(display);
  for(int j = 0; j <= inactive; j++)  frame->widgets[frame_parent].state[j] = 0;

  for(int i = 0; i < frame_parent; i++) {
    frame->widgets[i].widget = 0;
    for(int j = 0; j <= inactive; j++)  frame->widgets[i].state[j] = 0;
  }
  for(int i = 0; i < frame_parent; i++) {
    int x = themes->window_type[frame->theme_type][i].x;
    int y = themes->window_type[frame->theme_type][i].y;
    int w = themes->window_type[frame->theme_type][i].w;
    int h = themes->window_type[frame->theme_type][i].h;

    if(!themes->window_type[frame->theme_type][i].exists) {
      //printf("Skipping window component %d\n", i);
      continue;
    }
    //TODO get the size of the window from somewhere else
    if(x <  0) x += frame->w;
    if(y <  0) y += frame->h;
    if(w <= 0) w += frame->w;
    if(h <= 0) h += frame->h;

    if(themes->window_type[frame->theme_type][i].exists < 0) { //the exists variable is -1 for hotspots
      frame->widgets[i].widget = XCreateWindow(display, frame->widgets[frame_parent].widget
      , x, y, w, h, 0, CopyFromParent, InputOnly, CopyFromParent, 0, NULL);
      XMapWindow(display, frame->widgets[i].widget);
    }
    else if(themes->window_type[frame->theme_type][i].exists) { //otherwise if it isn't an inputonly hotspot
      frame->widgets[i].widget = XCreateSimpleWindow(display, frame->widgets[frame_parent].widget
      , x, y, w, h, 0, black, black);
      XFlush(display);
      if(i != window) { //don't create state windows for the framed window
        //OPTIMIZATION: This makes the cropped state windows large so that they don't need to be resized
        if(themes->window_type[frame->theme_type][i].w <= 0 || i == mode_dropdown_text) w = XWidthOfScreen(screen);
        if(themes->window_type[frame->theme_type][i].h <= 0) h = XWidthOfScreen(screen);
        for(int j = 0; j <= inactive; j++) {
          frame->widgets[i].state[j] = XCreateSimpleWindow(display, frame->widgets[i].widget
          , 0, 0, w, h, 0, black, black);
          XSetWindowBackgroundPixmap(display, frame->widgets[i].state[j]
          , themes->window_type[frame->theme_type][i].state_p[j]);
          XMapWindow(display, frame->widgets[i].state[j]);
        }
      }
      //Map windows
      XMapWindow(display, frame->widgets[i].widget);
    }
  }
  frame->menu.width = 0;
  //select input
  XSelectInput(display, frame->widgets[frame_parent].widget
  , Button1MotionMask | ButtonPressMask | ButtonReleaseMask);

  XDefineCursor(display, frame->widgets[frame_parent].widget, cursors->normal);

  if(themes->window_type[frame->theme_type][close_button_hotspot].exists) {
    XSelectInput(display, frame->widgets[close_button_hotspot].widget
    ,  ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask);

    XDefineCursor(display, frame->widgets[close_button_hotspot].widget, cursors->pressable);
  }

  if(themes->window_type[frame->theme_type][mode_dropdown_hotspot].exists) {
    XSelectInput(display, frame->widgets[mode_dropdown_hotspot].widget, ButtonPressMask | ButtonReleaseMask);
    XDefineCursor(display, frame->widgets[mode_dropdown_hotspot].widget, cursors->pressable);
  }

  if(themes->window_type[frame->theme_type][title_menu_hotspot].exists) {
    XSelectInput(display, frame->widgets[title_menu_hotspot].widget, ButtonPressMask | ButtonReleaseMask);
    XDefineCursor(display, frame->widgets[title_menu_hotspot].widget , cursors->pressable);
  }

  if(themes->window_type[frame->theme_type][tl_corner].exists) {
    XSelectInput(display, frame->widgets[tl_corner].widget,  ButtonPressMask | ButtonReleaseMask);
    XDefineCursor(display, frame->widgets[tl_corner].widget, cursors->resize_tl_br);
  }
  if(themes->window_type[frame->theme_type][t_edge].exists) {
    XSelectInput(display, frame->widgets[t_edge].widget,     ButtonPressMask | ButtonReleaseMask);
    XDefineCursor(display, frame->widgets[t_edge].widget , cursors->resize_v);
  }
  if(themes->window_type[frame->theme_type][tr_corner].exists) {
    XSelectInput(display, frame->widgets[tr_corner].widget,  ButtonPressMask | ButtonReleaseMask);
    XDefineCursor(display, frame->widgets[tr_corner].widget, cursors->resize_tr_bl);
  }
  if(themes->window_type[frame->theme_type][l_edge].exists) {
    XSelectInput(display, frame->widgets[l_edge].widget,     ButtonPressMask | ButtonReleaseMask);
    XDefineCursor(display, frame->widgets[l_edge].widget , cursors->resize_h);
  }
  if(themes->window_type[frame->theme_type][bl_corner].exists) {
    XSelectInput(display, frame->widgets[bl_corner].widget,  ButtonPressMask | ButtonReleaseMask);
    XDefineCursor(display, frame->widgets[bl_corner].widget, cursors->resize_tr_bl);
  }
  if(themes->window_type[frame->theme_type][b_edge].exists) {
    XSelectInput(display, frame->widgets[b_edge].widget,     ButtonPressMask | ButtonReleaseMask);
    XDefineCursor(display, frame->widgets[b_edge].widget , cursors->resize_v);
  }
  if(themes->window_type[frame->theme_type][br_corner].exists) {
    XSelectInput(display, frame->widgets[br_corner].widget,  ButtonPressMask | ButtonReleaseMask);
    XDefineCursor(display, frame->widgets[br_corner].widget, cursors->resize_tl_br);
  }
  if(themes->window_type[frame->theme_type][r_edge].exists) {
    XSelectInput(display, frame->widgets[r_edge].widget,     ButtonPressMask | ButtonReleaseMask);
    XDefineCursor(display, frame->widgets[r_edge].widget , cursors->resize_h);
  }
  XFlush(display);
}