コード例 #1
0
ファイル: status.c プロジェクト: Sowhat2112/KreyosFirmware
/*
 battery is between 3.7 to 4.2
  4.2 => 2.1 / 2.5 * 255 = 214
  3.7 => 1.86 / 2.5 * 255 = 189
*/
static void check_battery()
{
  //uint8_t report = 0;
  // update battery status
  BATTERY_STATE state = battery_state();
  uint8_t level = battery_level(state);

  status &= ~BATTERY_STATUS;

  switch(level)
  {
    case 0: case 1:
    status |= BATTERY_EMPTY;
    break;
    case 2: case 3:
    status |= BATTERY_LESS;
    break;
    case 4: case 5: case 6:
    status |= BATTERY_MORE;
    break;
    default:
    status |= BATTERY_FULL;
  }

  if (window_current() != &charging_process)
  {
    if ((level == 0) && (state == BATTERY_STATE_DISCHARGING))
    {
      window_open(&charging_process, 0);
    }
  }

#ifndef UNITTEST
  if (window_current() == &menu_process ||
    window_current() == &analogclock_process ||
    window_current() == &digitclock_process)
  {
    if (state != BATTERY_STATE_DISCHARGING)
    {
      window_open(&charging_process, 0); 
    }
  }
#endif

  if (state == BATTERY_STATE_CHARGING)
  {
    status |= BATTERY_CHARGING;
    level |= 0x10;
  }

  hfp_battery(level);
}
コード例 #2
0
ファイル: main.c プロジェクト: mbresson/Arkanopong
int main(void) {
  window_open();

  glutils_init();

  Settings settings;
  settings.first_run = true;
  Level level;

  bool leave = false;
  while(!leave) {
    if(!menu_run(&settings)) {
      leave = true;
      break;
    }

    theme_load(settings.theme);
    level_load(settings.level_set, settings.level, &level);

    level_run(&level, &settings);
  }

  /*
   * unload the last used theme
   * if we loaded several themes one after another,
   * they have been automatically freed by theme_load
   */
  theme_unload();

  return EXIT_SUCCESS;
}
コード例 #3
0
ファイル: barber.c プロジェクト: jvesely/helenos
int main(int argc, char *argv[])
{
	if (argc < 2) {
		printf("Compositor server not specified.\n");
		return 1;
	}
	
	list_initialize(&led_devs);
	int rc = loc_register_cat_change_cb(loc_callback);
	if (rc != EOK) {
		printf("Unable to register callback for device discovery.\n");
		return 1;
	}
	
	led_timer = fibril_timer_create(NULL);
	if (!led_timer) {
		printf("Unable to create LED timer.\n");
		return 1;
	}
	
	frame_timer = fibril_timer_create(NULL);
	if (!frame_timer) {
		printf("Unable to create frame timer.\n");
		return 1;
	}
	
	if (!decode_frames())
		return 1;
	
	winreg = argv[1];
	window_t *main_window = window_open(argv[1], NULL,
	    WINDOW_MAIN | WINDOW_DECORATED, "barber");
	if (!main_window) {
		printf("Cannot open main window.\n");
		return 1;
	}
	
	frame_canvas = create_canvas(window_root(main_window), NULL,
	    FRAME_WIDTH, FRAME_HEIGHT, frames[frame]);
	
	if (!frame_canvas) {
		window_close(main_window);
		printf("Cannot create widgets.\n");
		return 1;
	}
	
	window_resize(main_window, 0, 0, FRAME_WIDTH + 8, FRAME_HEIGHT + 28,
	    WINDOW_PLACEMENT_RIGHT | WINDOW_PLACEMENT_BOTTOM);
	window_exec(main_window);
	
	plan_led_timer();
	plan_frame_timer(0);
	
	task_retval(0);
	async_manager();
	
	return 0;
}
コード例 #4
0
ファイル: vdemo.c プロジェクト: jvesely/helenos
int main(int argc, char *argv[])
{
	if (argc >= 2) {
		window_t *main_window = window_open(argv[1], NULL,
		    WINDOW_MAIN | WINDOW_DECORATED | WINDOW_RESIZEABLE, "vdemo");
		if (!main_window) {
			printf("Cannot open main window.\n");
			return 1;
		}

		pixel_t grd_bg = PIXEL(255, 240, 240, 240);
		
		pixel_t btn_bg = PIXEL(255, 240, 240, 240);
		pixel_t btn_fg = PIXEL(255, 186, 186, 186);
		pixel_t btn_text = PIXEL(255, 0, 0, 0);
		
		pixel_t lbl_bg = PIXEL(255, 240, 240, 240);
		pixel_t lbl_text = PIXEL(255, 0, 0, 0);

		my_label_t *lbl_action = create_my_label(NULL, "Hello there!", 16,
		    lbl_bg, lbl_text);
		button_t *btn_confirm = create_button(NULL, NULL, "Confirm", 16,
		    btn_bg, btn_fg, btn_text);
		button_t *btn_cancel = create_button(NULL, NULL, "Cancel", 16,
		    btn_bg, btn_fg, btn_text);
		grid_t *grid = create_grid(window_root(main_window), NULL, 2, 2,
		    grd_bg);
		if (!lbl_action || !btn_confirm || !btn_cancel || !grid) {
			window_close(main_window);
			printf("Cannot create widgets.\n");
			return 1;
		}

		sig_connect(
		    &btn_confirm->clicked,
		    &lbl_action->label.widget,
		    lbl_action->confirm);
		sig_connect(
		    &btn_cancel->clicked,
		    &lbl_action->label.widget,
		    lbl_action->cancel);

		grid->add(grid, &lbl_action->label.widget, 0, 0, 2, 1);
		grid->add(grid, &btn_confirm->widget, 0, 1, 1, 1);
		grid->add(grid, &btn_cancel->widget, 1, 1, 1, 1);
		window_resize(main_window, 0, 0, 200, 76,
		    WINDOW_PLACEMENT_CENTER);

		window_exec(main_window);
		task_retval(0);
		async_manager();
		return 1;
	} else {
		printf("Compositor server not specified.\n");
		return 1;
	}
}
コード例 #5
0
ファイル: gui.c プロジェクト: mmuman/NetSurf
/**
 * Create and open a gui window for a browsing context.
 *
 * \param bw		bw to create gui_window for
 * \param existing	an existing gui_window, may be NULL
 * \param flags		flags for gui window creation
 * \return gui window, or NULL on error
 *
 * If GW_CREATE_CLONE flag is set existing is non-NULL.
 *
 * The created gui_window must include a reference to the browser
 * window passed in the bw param.
 */
static struct gui_window *
gui_window_create(struct browser_window *bw,
		  struct gui_window *existing,
		  gui_window_create_flags flags)
{
    struct gui_window *gw=NULL;
    LOG("gw: %p, BW: %p, existing %p, flags: %d\n", gw, bw, existing, (int)flags);

    gw = calloc(1, sizeof(struct gui_window));
    if (gw == NULL)
	return NULL;

    LOG("new window: %p, bw: %p\n", gw, bw);
    window_create(gw, bw, existing, WIDGET_STATUSBAR|WIDGET_TOOLBAR|WIDGET_RESIZE\
		  |WIDGET_SCROLL);
    if (gw->root->win) {
	GRECT pos = {
	    option_window_x, option_window_y,
	    option_window_width, option_window_height
	};
	gui_window_set_url(gw, corestring_nsurl_about_blank);
	gui_window_set_pointer(gw, BROWSER_POINTER_DEFAULT);
	gui_set_input_gui_window(gw);
	window_open(gw->root, gw, pos);
    }

    /* add the window to the window list: */
    if( window_list == NULL ) {
	window_list = gw;
	gw->next = NULL;
	gw->prev = NULL;
    } else {
	struct gui_window * tmp = window_list;
	while( tmp->next != NULL ) {
	    tmp = tmp->next;
	}
	tmp->next = gw;
	gw->prev = tmp;
	gw->next = NULL;
    }

    /* Loose focus: */
    window_set_focus(gw->root, WIDGET_NONE, NULL );

    /* trigger on-focus event (select all text): */
    window_set_focus(gw->root, URL_WIDGET, NULL);

    /* delete selection: */
    toolbar_key_input(gw->root->toolbar, NK_DEL);

    return( gw );

}
コード例 #6
0
ファイル: glw_x11.c プロジェクト: edenhill/showtime
static void
window_change_fullscreen(glw_x11_t *gx11)
{
  if(gx11->wm_flags & GX11_WM_CAN_FULLSCREEN) {

    wm_set_fullscreen(gx11, gx11->want_fullscreen);
    gx11->is_fullscreen = gx11->want_fullscreen;
    
  } else {

    window_shutdown(gx11);
    if(window_open(gx11, gx11->want_fullscreen))
      exit(1);
  }
  glw_set_fullscreen(&gx11->gr, gx11->is_fullscreen);
}
コード例 #7
0
ファイル: gui.c プロジェクト: galexcode/NetSurf68k
struct gui_window *
gui_create_browser_window(struct browser_window *bw,
                          struct browser_window *clone,
                          bool new_tab) {
    struct gui_window *gw=NULL;
    LOG(( "gw: %p, BW: %p, clone %p, tab: %d\n" , gw,  bw, clone,
          (int)new_tab
        ));

    gw = calloc( sizeof(struct gui_window), 1);
    if (gw == NULL)
        return NULL;

    LOG(("new window: %p, bw: %p\n", gw, bw));
    window_create(gw, bw, clone, WIDGET_STATUSBAR|WIDGET_TOOLBAR|WIDGET_RESIZE\
                  |WIDGET_SCROLL);
    if (gw->root->win) {
        GRECT pos = {
            option_window_x, option_window_y,
            option_window_width, option_window_height
        };
        gui_window_set_url(gw, "");
        gui_window_set_pointer(gw, BROWSER_POINTER_DEFAULT);
        gui_set_input_gui_window(gw);
        window_open(gw->root, gw, pos);
    }

    /* add the window to the window list: */
    if( window_list == NULL ) {
        window_list = gw;
        gw->next = NULL;
        gw->prev = NULL;
    } else {
        struct gui_window * tmp = window_list;
        while( tmp->next != NULL ) {
            tmp = tmp->next;
        }
        tmp->next = gw;
        gw->prev = tmp;
        gw->next = NULL;
    }

    return( gw );

}
コード例 #8
0
ファイル: program.c プロジェクト: zlsa/defiance
void program_open_window(struct program *program) {
  ASSERT_PROGRAM(program);

  assert(!program->window);

  if(!window_init()) {
    util_log(LOG_ERROR, "could not initialize GLFW");
    program_exit(program, EXIT_FAILURE);
  }

  program->glfw_initialized = true;
  
  program->window = window_create();

  if(!window_open(program->window)) {
    util_log(LOG_ERROR, "could not open GLFW window");
    program_exit(program, EXIT_FAILURE);
  }

}
コード例 #9
0
void window_notify(const char* title, const char* msg, uint8_t buttons, char icon)
{
  message_title = title;
  message_subtitle = NULL;
  message = msg;
  message_buttons = buttons;
  message_icon = icon;
  skip = 0;

  push_uid(SPECIAL, 0);

  selectidx = 0;

  motor_on(50, CLOCK_SECOND);
  backlight_on(window_readconfig()->light_level, CLOCK_SECOND * 3);

  if (state & STATE_ACTIVE)
    window_invalid(NULL);
  else 
    window_open(notify_process, NULL);
}
コード例 #10
0
ファイル: clockt.c プロジェクト: osgroup/HelenOSProject
int main(int argc, char *argv[])
{
char buffer[30];
struct timeval tv;
struct tm result;
window_t *main_window = window_open(argv[1], true, true," ",0,720);
	if (!main_window) {
	printf("Cannot open main window.\n");
		return 1;
	}

	time_t curtime;
	gettimeofday(&tv, NULL); 
	curtime=tv.tv_sec;
	time_utc2tm(curtime,&result);
	strftime(buffer,30,"%T %m-%d-%Y",&result);

	pixel_t grd_bg = PIXEL(255, 25, 25, 112);
	
	pixel_t lbl_bg = PIXEL(255, 25, 25, 112);//(255, 240, 240, 240);
	pixel_t lbl_fg = PIXEL(255, 255, 255, 255);

	my_label_t *stime= create_my_label(NULL,buffer, 16, lbl_bg, lbl_fg);

	grid_t *grid = create_grid(window_root(main_window),1, 10, grd_bg);
	grid->add(grid, &stime->label.widget, 0, 7, 1, 2);
	window_resize(main_window,1024,60);
	window_exec(main_window);

	while(1){
		gettimeofday(&tv, NULL); 
		curtime=tv.tv_sec;
		time_utc2tm(curtime,&result);

//Converting month to integer		
		char month[5];
		strftime(month,5,"%m",&result);
		char *mon;
		mon=month;
		int value=0;
		value=toInteger1(mon);

		switch(value){
case 0:
			strftime(buffer,30,"%T Jan-%d, %Y",&result);		
			break;
case 1:
			strftime(buffer,30,"%T Feb-%d, %Y",&result);		
			break;
case 2:
			strftime(buffer,30,"%T Mar-%d, %Y",&result);		
			break;
case 3:
			strftime(buffer,30,"%T Apr-%d, %Y",&result);		
			break;
case 4:
			strftime(buffer,30,"%T May-%d, %Y",&result);		
			break;
case 5:
			strftime(buffer,30,"%T Jun-%d, %Y",&result);		
			break;
case 6:
			strftime(buffer,30,"%T Jul-%d, %Y",&result);		
			break;
case 7:
			strftime(buffer,30,"%T Aug-%d, %Y",&result);		
			break;
case 8:
			strftime(buffer,30,"%T Sep-%d, %Y",&result);		
			break;
case 9:
			strftime(buffer,30,"%T Oct-%d, %Y",&result);		
			break;
case 10:
			strftime(buffer,30,"%T Nov-%d, %Y",&result);		
			break;
case 11:
			strftime(buffer,30,"%T Dec-%d, %Y",&result);		
			break;
		}	
		stime->label.rewrite(&stime->label.widget, (void *)buffer);
	}

	task_retval(0);
	async_manager();

return 0;
}
コード例 #11
0
void window_notify_ancs(uint8_t command, uint32_t uid, uint8_t flag, uint8_t category)
{
  if (command == 0) // add
  {
    if (lastmessageid != -1 && lastmessageid >= uid)
    {
      return;
    }

    message_title = NULL;
    message = NULL;
    push_uid(uid, (flag << 8) | category);
    selectidx = 0;
    motor_on(50, CLOCK_SECOND);
    backlight_on(window_readconfig()->light_level, CLOCK_SECOND * 3);

    lastmessageid = uid;
    if (state & STATE_ACTIVE)
      window_invalid(NULL);
    else 
      window_open(notify_process, NULL);

    fetch_content();    
  }
  else if (command == 1)
  {
    if (state & STATE_ACTIVE)
    {
      // check if the current 
      if (uids[0] == uid)
      {
        fetch_content();
      }
      window_invalid(NULL);
      motor_on(50, CLOCK_SECOND);
    }
  }
  else if (command == 2) // remove
  {
    if (!(state & STATE_ACTIVE))
      return;

    uint8_t refresh = 0;
    if (uids[0] == uid)
    {
      refresh = 1;
    }

    // find the item
    int i;
    for(i = 0; i < num_uids; i++)
    {
      if (uids[i] == uid)
        break;
    }

    if (i == num_uids)
      return;

    for (int j = i ; j < num_uids; j++)
    {
      uids[j] = uids[j+1];
      attributes[j] = attributes[j+1];
    }
    num_uids--;

    if (refresh)
      fetch_content();
  }
}
コード例 #12
0
ファイル: glw_x11.c プロジェクト: edenhill/showtime
static int
glw_x11_init(glw_x11_t *gx11)
{
  int attribs[10];
  int na = 0;
  
  XInitThreads();

  int use_locales = XSupportsLocale() && XSetLocaleModifiers("") != NULL;

  if((gx11->display = XOpenDisplay(gx11->displayname_real)) == NULL) {
    TRACE(TRACE_ERROR, "GLW", "Unable to open X display \"%s\"\n",
	    gx11->displayname_real);
    return 1;
  }

  if(!glXQueryExtension(gx11->display, NULL, NULL)) {
    TRACE(TRACE_ERROR, "GLW", 
	  "OpenGL GLX extension not supported by display \"%s\"\n",
	    gx11->displayname_real);
    return 1;
  }


  gx11->screen        = DefaultScreen(gx11->display);
  gx11->screen_width  = DisplayWidth(gx11->display, gx11->screen);
  gx11->screen_height = DisplayHeight(gx11->display, gx11->screen);
  gx11->root          = RootWindow(gx11->display, gx11->screen);
 
  attribs[na++] = GLX_RGBA;
  attribs[na++] = GLX_RED_SIZE;
  attribs[na++] = 1;
  attribs[na++] = GLX_GREEN_SIZE;
  attribs[na++] = 1;
  attribs[na++] = GLX_BLUE_SIZE; 
  attribs[na++] = 1;
  attribs[na++] = GLX_DOUBLEBUFFER;
  attribs[na++] = None;
  
  gx11->xvi = glXChooseVisual(gx11->display, gx11->screen, attribs);

  if(gx11->xvi == NULL) {
    TRACE(TRACE_ERROR, "GLW", "Unable to find an adequate Visual on \"%s\"\n",
	    gx11->displayname_real);
    return 1;
  }
  
  if(GLXExtensionSupported(gx11->display, "GLX_SGI_swap_control")) {
    TRACE(TRACE_DEBUG, "GLW", "GLX_SGI_swap_control extension is present");
    gx11->glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)
      glXGetProcAddress((const GLubyte*)"glXSwapIntervalSGI");
  }

  build_blank_cursor(gx11);

  if(use_locales)
    gx11->im = XOpenIM(gx11->display, NULL, NULL, NULL);


  gx11->atom_deletewindow = 
    XInternAtom(gx11->display, "WM_DELETE_WINDOW", 0);

#if ENABLE_VDPAU
  if(GLXExtensionSupported(gx11->display, "GLX_EXT_texture_from_pixmap")) {

    gx11->gr.gr_be.gbr_bind_tex_image = (PFNGLXBINDTEXIMAGEEXTPROC)
      glXGetProcAddress((const GLubyte*)"glXBindTexImageEXT");

    gx11->gr.gr_be.gbr_release_tex_image = (PFNGLXRELEASETEXIMAGEEXTPROC)
      glXGetProcAddress((const GLubyte*)"glXReleaseTexImageEXT");

    gx11->gr.gr_be.gbr_vdpau_dev = vdpau_init_x11(gx11->display, gx11->screen,
						  vdpau_preempted, gx11);

  } else {
    TRACE(TRACE_DEBUG, "VDPAU", 
	  "GLX_EXT_texture_from_pixmap extension not present, disabling VDPAU");
  }
#endif

  probe_wm(gx11);


  gx11->is_fullscreen = gx11->want_fullscreen;

  int fs = 0;
  if(gx11->wm_flags == 0) {
    fs = 1; // No window manager, open in fullscreen mode
  } else {
    /* If window manager cannot do fullscreen, ask window to open 
       in fullscreen mode */
    fs = gx11->want_fullscreen && !(gx11->wm_flags & GX11_WM_CAN_FULLSCREEN);
  }

  if(window_open(gx11, fs))
    return -1;

  // Fullscreen via window manager
  if(gx11->want_fullscreen && !fs)
    wm_set_fullscreen(gx11, 1);

  return 0;
}
コード例 #13
0
/*
=======================================
    WinMain 程序入口
=======================================
*/
int WINAPI
WinMain (
  __CR_IN__ HINSTANCE   curt_app,
  __CR_IN__ HINSTANCE   prev_app,
  __CR_IN__ LPSTR       cmd_line,
  __CR_IN__ int         cmd_show
    )
{
    CR_NOUSE(prev_app);
    CR_NOUSE(cmd_line);
    CR_NOUSE(cmd_show);

    /* 只允许一个例程 */
    if (misc_is_running(EXE_XNAME))
        return (QST_ERROR);

    /* 建立 CrHack 系统 */
    if (!set_app_type(CR_APP_GUI))
        return (QST_ERROR);
    mem_zero(&s_wrk_ctx, sizeof(s_wrk_ctx));

    sint_t  x1, y1;
    uint_t  ww, hh;

    /* 生成一个可变大小的窗口 */
    mtlock_init(&s_wrk_ctx.lock);
    qst_load_cfg(&s_wrk_ctx.cfgs);
    misc_desk_init(WIN_ICONF, &x1, &y1, &ww, &hh,
                   QV2D_DEF_WIDTH, QV2D_DEF_HEIGHT);
    if (ww < QV2D_DEF_WIDTH)  ww = QV2D_DEF_WIDTH;
    if (hh < QV2D_DEF_HEIGHT) hh = QV2D_DEF_HEIGHT;
    s_wrk_ctx.hwnd = (HWND)window_open(curt_app, (void_t*)WindowProc,
                        x1, y1, ww, hh, WIN_TITLE, WIN_CLASS, (ansi_t*)101,
                                    CR_WSTYLE_NORMAL);
    if (s_wrk_ctx.hwnd == NULL)
        return (QST_ERROR);
    SetWindowLongPtr(s_wrk_ctx.hwnd, GWL_STYLE,
        GetWindowLongPtr(s_wrk_ctx.hwnd, GWL_STYLE) & (~WS_MAXIMIZEBOX));

    iGFX2*  draw;
    sIMAGE* imgs;

    /* 创建 GDI 绘制对象 (只支持32位色屏幕) */
    draw = (iGFX2*)create_gdi_canvas(s_wrk_ctx.hwnd, 0, 0, FALSE);
    if (draw == NULL) {
        window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS);
        return (QST_ERROR);
    }
    imgs = CR_VCALL(draw)->lock(draw);
    if (imgs == NULL || imgs->fmt != CR_ARGB8888) {
        window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS);
        return (QST_ERROR);
    }
    CR_VCALL(draw)->unlock(draw);
    CR_VCALL(draw)->clear(draw, s_wrk_ctx.cfgs.bkcolor, 0);
    s_wrk_ctx.draw = draw;

    /* 初始化网络 */
    if (!socket_init()) {
        window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS);
        return (QST_ERROR);
    }
    s_wrk_ctx.netw = netw_cli_open(EXE_XNAME);
    if (s_wrk_ctx.netw == NULL) {
        window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS);
        return (QST_ERROR);
    }
    /* 读取需要超时, 不然线程无法退出 */
    socket_set_timeout(s_wrk_ctx.netw, -1, QST_TCP_TOUT);

    thrd_t  thrd;

    /* 生成工作线程 */
    s_wrk_ctx.send = TRUE;
    s_wrk_ctx.quit = FALSE;
    s_wrk_ctx.cur_busy = LoadCursor(NULL, IDC_WAIT);
    s_wrk_ctx.cur_free = LoadCursor(NULL, IDC_ARROW);
    s_wrk_ctx.res_loader = res_loader_get();
    if (s_wrk_ctx.res_loader->init != NULL)
        s_wrk_ctx.res_loader->init(s_wrk_ctx.netw, NULL);
    qst_load_filter(&s_wrk_ctx);
    thrd = thread_new(0, qst_v2d_main, &s_wrk_ctx, FALSE);
    if (thrd == NULL) {
        window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS);
        return (QST_ERROR);
    }

    /* 消息循环 */
    while (!s_wrk_ctx.quit)
    {
        MSG     msg;

        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
            if (msg.message == WM_QUIT) {
                s_wrk_ctx.quit = TRUE;
                break;
            }
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else {
            qst_do_keyboard(&s_wrk_ctx);
        }
    }
    thread_wait(thrd);
    thread_del(thrd);
    window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS);
    netw_cli_close(s_wrk_ctx.netw);
    return (QST_OKAY);
}
コード例 #14
0
ファイル: glw_x11.c プロジェクト: kacinoman/movian
static int
glw_x11_init(glw_x11_t *gx11)
{
  int attribs[10];
  int na = 0;
  
  int use_locales = XSupportsLocale() && XSetLocaleModifiers("@im=none") != NULL;

  if((gx11->display = XOpenDisplay(gx11->displayname_real)) == NULL) {
    TRACE(TRACE_ERROR, "GLW", "Unable to open X display \"%s\"\n",
          gx11->displayname_real);
    return 1;
  }

  if(!glXQueryExtension(gx11->display, NULL, NULL)) {
    TRACE(TRACE_ERROR, "GLW", 
	  "OpenGL GLX extension not supported by display \"%s\"\n",
          gx11->displayname_real);
    return 1;
  }


  gx11->screen        = DefaultScreen(gx11->display);
  gx11->screen_width  = DisplayWidth(gx11->display, gx11->screen);
  gx11->screen_height = DisplayHeight(gx11->display, gx11->screen);
  gx11->root          = RootWindow(gx11->display, gx11->screen);
 
  attribs[na++] = GLX_RGBA;
  attribs[na++] = GLX_RED_SIZE;
  attribs[na++] = 1;
  attribs[na++] = GLX_GREEN_SIZE;
  attribs[na++] = 1;
  attribs[na++] = GLX_BLUE_SIZE; 
  attribs[na++] = 1;
  attribs[na++] = GLX_DOUBLEBUFFER;
  attribs[na++] = None;
  
  gx11->xvi = glXChooseVisual(gx11->display, gx11->screen, attribs);

  if(gx11->xvi == NULL) {
    TRACE(TRACE_ERROR, "GLW", "Unable to find an adequate Visual on \"%s\"\n",
          gx11->displayname_real);
    return 1;
  }
  
  if(GLXExtensionSupported(gx11->display, "GLX_SGI_swap_control")) {
    TRACE(TRACE_DEBUG, "GLW", "GLX_SGI_swap_control extension is present");
    gx11->glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)
      glXGetProcAddress((const GLubyte*)"glXSwapIntervalSGI");
  }

  build_blank_cursor(gx11);

  if(use_locales)
    gx11->im = XOpenIM(gx11->display, NULL, NULL, NULL);


  gx11->atom_deletewindow = 
    XInternAtom(gx11->display, "WM_DELETE_WINDOW", 0);

#if ENABLE_VDPAU

  gx11->gr.gr_be.gbr_glVDPAUInitNV =
    (PFNGLVDPAUINITNVPROC)
    glXGetProcAddress((const GLubyte*)"glVDPAUInitNV");

  if(gx11->gr.gr_be.gbr_glVDPAUInitNV != NULL) {

    vdpau_dev_t *vd;
    vd = vdpau_init_x11(gx11->display, gx11->screen, vdpau_preempted, gx11);
    gx11->gr.gr_be.gbr_vdpau_dev = vd;

    gx11->gr.gr_be.gbr_glVDPAUUnregisterSurfaceNV =
      (PFNGLVDPAUUNREGISTERSURFACENVPROC)
      glXGetProcAddress((const GLubyte*)"glVDPAUUnregisterSurfaceNV");

    gx11->gr.gr_be.gbr_glVDPAUUnmapSurfacesNV =
      (PFNGLVDPAUUNMAPSURFACESNVPROC)
      glXGetProcAddress((const GLubyte*)"glVDPAUUnmapSurfacesNV");

    gx11->gr.gr_be.gbr_glVDPAURegisterOutputSurfaceNV =
      (PFNGLVDPAUREGISTEROUTPUTSURFACENVPROC)
      glXGetProcAddress((const GLubyte*)"glVDPAURegisterOutputSurfaceNV");

    gx11->gr.gr_be.gbr_glVDPAUMapSurfacesNV =
      (PFNGLVDPAUMAPSURFACESNVPROC)
      glXGetProcAddress((const GLubyte*)"glVDPAUMapSurfacesNV");
  }
#endif

  probe_wm(gx11);


  gx11->is_fullscreen = gx11->want_fullscreen;

  int fs = 0;
  if(gx11->wm_flags == 0) {
    fs = 1; // No window manager, open in fullscreen mode
  } else {
    /* If window manager cannot do fullscreen, ask window to open 
       in fullscreen mode */
    fs = gx11->want_fullscreen && !(gx11->wm_flags & GX11_WM_CAN_FULLSCREEN);
  }

  if(window_open(gx11, fs))
    return -1;

  // Fullscreen via window manager
  if(gx11->want_fullscreen && !fs)
    wm_set_fullscreen(gx11, 1);

  return 0;
}