Prima

 view release on metacpan or  search on metacpan

unix/app.c  view on Meta::CPAN

	XQueryBestCursor( DISP, guts. root,
							guts. displaySize. x,     /* :-) */
							guts. displaySize. y,
							&guts. cursor_width,
							&guts. cursor_height);
#endif
	XCHECKPOINT;

	TAILQ_INIT( &guts.paintq);
	TAILQ_INIT( &guts.peventq);
	TAILQ_INIT( &guts.bitmap_gc_pool);
	TAILQ_INIT( &guts.screen_gc_pool);
	TAILQ_INIT( &guts.argb_gc_pool);

	guts. currentFocusTime = CurrentTime;
	guts. windows = hash_create();
	guts. menu_windows = hash_create();
	guts. ximages = hash_create();
	gcv. graphics_exposures = false;
	gcv. cap_style = CapProjecting;
	guts. menugc = XCreateGC( DISP, guts. root, GCGraphicsExposures | GCCapStyle, &gcv);
	guts. resolution. x = ( DisplayWidthMM( DISP, SCREEN) > 0) ? 
		25.4 * guts. displaySize. x / DisplayWidthMM( DISP, SCREEN) + .5:
		96;
	guts. resolution. y = ( DisplayHeightMM( DISP, SCREEN) > 0) ? 
		25.4 * DisplayHeight( DISP, SCREEN) / DisplayHeightMM( DISP, SCREEN) + .5:
		96;
	guts. depth = DefaultDepth( DISP, SCREEN);
	guts. idepth = get_idepth();
	if ( guts.depth == 1) guts. qdepth = 1; else
	if ( guts.depth <= 4) guts. qdepth = 4; else
	if ( guts.depth <= 8) guts. qdepth = 8; else
		guts. qdepth = 24;
	guts. byte_order = ImageByteOrder( DISP);
	guts. bit_order = BitmapBitOrder( DISP);
	if ( BYTEORDER == LSB32 || BYTEORDER == LSB64)
		guts. machine_byte_order = LSBFirst;
	else if ( BYTEORDER == MSB32 || BYTEORDER == MSB64)
		guts. machine_byte_order = MSBFirst;
	else {
		sprintf( error_buf, "UAA_001: weird machine byte order: %08x", BYTEORDER);
		return false;
	}

	XInternAtoms( DISP, atom_names, AI_count, 0, guts. atoms);

	guts. null_pointer = NULL_HANDLE;
	guts. pointer_invisible_count = 0;
	guts. files = plist_create( 16, 16);
	prima_rebuild_watchers();
	guts. wm_event_timeout = 100;
	guts. menu_timeout = 200;
	guts. scroll_first = 200;
	guts. scroll_next = 50;
	apc_timer_create( CURSOR_TIMER);
	apc_timer_set_timeout(CURSOR_TIMER, 2);
	apc_timer_create( MENU_TIMER);
	apc_timer_set_timeout( MENU_TIMER,  guts. menu_timeout);
	apc_timer_create( MENU_UNFOCUS_TIMER);
	apc_timer_set_timeout( MENU_UNFOCUS_TIMER, 50);
	if ( !prima_init_clipboard_subsystem (error_buf)) return false;
	if ( !prima_init_color_subsystem     (error_buf)) return false;
	if ( !do_no_xrender)
		if ( !prima_init_xrender_subsystem(error_buf)) return false;
	if ( !prima_init_font_subsystem      (error_buf)) return false;
#ifdef WITH_GTK
	guts. use_gtk = do_no_gtk ? false : ( prima_gtk_init() != NULL );
#endif
#ifdef WITH_COCOA
	if ( prima_cocoa_is_x11_local())
		guts. use_quartz = !do_no_quartz;
#endif
	bzero( &guts. cursor_gcv, sizeof( guts. cursor_gcv));
	guts. cursor_gcv. cap_style = CapButt;
	guts. cursor_gcv. function = GXcopy;

	gethostname( hostname, 256);
	hostname[255] = '\0';
	XStringListToTextProperty((char **)&hostname, 1, &guts. hostname);

	guts. net_wm_maximization = prima_wm_net_state_read_maximization( guts. root, NET_SUPPORTED);

	env = getenv("XDG_SESSION_TYPE");
	if (( env != NULL) && (strcmp(env, "wayland") == 0)) {
		guts. is_xwayland = true;
		Mdebug("XWayland detected\n");
	}

	if ( !do_no_xim )
		prima_xim_init();

	if ( do_sync) XSynchronize( DISP, true);
	return true;
}

Bool
window_subsystem_init( char * error_buf)
{
	bzero( &guts, sizeof( guts));
	guts. debug = do_debug;
	guts. icccm_only = do_icccm_only;
	Mdebug("init x11:%d, debug:%x, sync:%d, display:%s\n", do_x11, guts.debug,
			do_sync, do_display ? do_display : "(default)");
	if ( do_x11) {
		Bool ret = init_x11( error_buf );
		if ( !ret && DISP) {
			XCloseDisplay(DISP);
			DISP = NULL;
		}
		return ret;
	}
	return true;
}

int
prima_debug( const char *format, ...)
{
	int rc = 0;
	va_list args;
	va_start( args, format);
	rc = vfprintf( stderr, format, args);
	va_end( args);
	return rc;
}

Bool
window_subsystem_get_options( int * argc, char *** argv)
{
	static char * x11_argv[] = {
	"no-x11", "runs Prima without X11 display initialized",
	"display", "selects X11 DISPLAY (--display=:0.0)",
	"visual", "X visual id (--visual=0x21, run `xdpyinfo` for list of supported visuals)",
	"sync", "synchronize X connection",
	"icccm", "do not use NET_WM (kde/gnome) and MOTIF extensions, ICCCM only",
	"debug", "turns on debugging on subsystems, selected by characters (--debug=FC). "\
				"Recognized characters are: "\
				" 0(none),"\
				" C(clipboard),"\
				" E(events),"\
				" F(fonts),"\
				" M(miscellaneous),"\
				" P(palettes and colors),"\
				" X(XRDB),"\
				" A(all together)",
#ifdef USE_MITSHM
	"no-shmem",       "do not use shared memory for images",
#endif
#ifdef X_HAVE_UTF8_STRING
	"no-xim",         "do not use XIM",
#endif
	"no-core-fonts", "do not use core fonts",
#ifdef USE_XFT
	"no-xft",        "do not use XFT",
	"no-aa",         "do not anti-alias XFT fonts",
	"font-priority", "match unknown fonts against: 'xft' (default) or 'core'",
#endif
#ifdef WITH_GTK
	"no-gtk",        "do not use GTK",
#endif
#ifdef WITH_HARFBUZZ
	"no-harfbuzz",   "do not use harfbuzz",
#endif
#ifdef WITH_COCOA
	"no-quartz",     "do not use Quartz",
#endif
#ifdef HAVE_X11_EXTENSIONS_XRENDER_H
	"no-xrender",    "do not use XRender",
#endif
	"font",
#ifdef USE_XFT
				"default prima font in XLFD (-helv-misc-*-*-) or XFT(Helv-12) format",
#else
				"default prima font in XLFD (-helv-misc-*-*-) format",
#endif
	"menu-font", "default menu font",
	"msg-font", "default message box font",
	"widget-font", "default widget font",
	"caption-font", "MDI caption font",
	"noscaled", "do not use scaled instances of fonts",
	"fg", "default foreground color",
	"bg", "default background color",
	"hilite-fg", "default highlight foreground color",
	"hilite-bg", "default highlight background color",
	"disabled-fg", "default disabled foreground color",
	"disabled-bg", "default disabled background color",
	"light", "default light-3d color",
	"dark", "default dark-3d color"
	};
	*argv = x11_argv;
	*argc = sizeof( x11_argv) / sizeof( char*);
	return true;
}

Bool
window_subsystem_set_option( char * option, char * value)
{
	Mdebug("%s=%s\n", option, value);
	if ( strcmp( option, "no-x11") == 0) {

unix/app.c  view on Meta::CPAN

	return false;
}

void
window_subsystem_cleanup( void)
{
	if ( !DISP) return;
	/*XXX*/
	prima_end_menu();
#ifdef WITH_GTK
	if ( guts. use_gtk) prima_gtk_done();
#endif
}

static void
free_gc_pool( struct gc_head *head)
{
	GCList *n1, *n2;

	n1 = TAILQ_FIRST(head);
	while (n1 != NULL) {
		n2 = TAILQ_NEXT(n1, gc_link);
		XFreeGC( DISP, n1-> gc);
		/* XXX */ free(n1);
		n1 = n2;
	}
	TAILQ_INIT(head);
}

void
window_subsystem_done( void)
{
	int i;
	if ( !DISP) return;

	if ( guts.use_xim )
		prima_xim_done();

	for ( i = 0; i < sizeof(guts.xdnd_pointers) / sizeof(CustomPointer); i++) {
		CustomPointer *cp = guts.xdnd_pointers + i;
		if ( cp-> cursor )
			XFreeCursor( DISP, cp->cursor);
#ifdef HAVE_X11_XCURSOR_XCURSOR_H
		if ( cp-> xcursor != NULL)
			XcursorImageDestroy(cp-> xcursor);
#endif
	}

	if ( guts. hostname. value) {
		XFree( guts. hostname. value);
		guts. hostname. value = NULL;
	}

	prima_end_menu();

	free_gc_pool(&guts.bitmap_gc_pool);
	free_gc_pool(&guts.screen_gc_pool);
	free_gc_pool(&guts.argb_gc_pool);
	prima_done_color_subsystem();
	prima_done_xrender_subsystem();
	free( guts. clipboard_formats);

	XFreeGC( DISP, guts. menugc);
	prima_gc_ximages();          /* verrry dangerous, very quiet please */
	if ( guts.pointer_font) {
		XFreeFont( DISP, guts.pointer_font);
		guts.pointer_font = NULL;
	}
	XCloseDisplay( DISP);
	DISP = NULL;

	plist_destroy( guts. files);
	guts. files = NULL;

	XrmDestroyDatabase( guts.db);
	if (guts.ximages)            hash_destroy( guts.ximages, false);
	if (guts.menu_windows)       hash_destroy( guts.menu_windows, false);
	if (guts.windows)            hash_destroy( guts.windows, false);
	if (guts.clipboards)         hash_destroy( guts.clipboards, false);
	if (guts.clipboard_xfers)    hash_destroy( guts.clipboard_xfers, false);
	prima_cleanup_font_subsystem();
	bzero(&guts, sizeof(guts));
}

static int
can_access_root_screen(void)
{
	static int result = -1;
	XImage * im;
	XErrorEvent xr;

	if ( result >= 0 ) return result;
	result = 0;

	XFlush(DISP);
	prima_save_xerror_event(&xr);
	im = XGetImage( DISP, guts.root, 0, 0, 1, 1, AllPlanes, ZPixmap); /* XWayland fails here */
	prima_restore_xerror_event(NULL);
	if (im == NULL) goto EXIT;

	XDestroyImage( im);

#ifdef WITH_GTK_NONX11
	/* detect XQuartz */
	{
		char * display_str = getenv("DISPLAY");
		if ( display_str ) {
			struct stat s;
			if ((stat( display_str, &s) >= 0) && S_ISSOCK(s.st_mode))  /* is a socket */
				goto EXIT;
		}
	}
#endif

	result = 1;
EXIT:
	return result;
}

Bool
apc_application_begin_paint( Handle self)
{
	DEFXX;
	if ( guts. appLock > 0) return false;
	if ( !can_access_root_screen()) return false;
	prima_prepare_drawable_for_painting( self, false);
	XX-> flags. force_flush = 1;
	return true;
}

Bool
apc_application_begin_paint_info( Handle self)
{
	prima_prepare_drawable_for_painting( self, false);
	return true;
}

Bool
apc_application_create( Handle self)
{



( run in 0.732 second using v1.01-cache-2.11-cpan-2398b32b56e )