📄 intf_gnome.c
字号:
/***************************************************************************** * intf_gnome.c: Gnome interface ***************************************************************************** * Copyright (C) 1999, 2000 VideoLAN * * Authors: * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include "defs.h"#include <errno.h> /* ENOMEM */#include <stdlib.h> /* free() */#include <string.h> /* strerror() */#include <sys/types.h> /* on BSD, uio.h needs types.h */#include <sys/uio.h> /* for input.h */#include <X11/Xlib.h>#include <X11/Xutil.h>#include <X11/keysym.h>#include "config.h"#include "common.h"#include "threads.h"#include "mtime.h"#include "plugins.h"#include "input.h"#include "video.h"#include "video_output.h"#include "audio_output.h" /* needed for mute */#include "intf_msg.h"#include "interface.h"#include "main.h"#include <stdio.h>#include <gnome.h>#include "intf_gnome_thread.h"#include "intf_gnome.h"#include "intf_gnome_interface.h"#include "intf_gnome_support.h"/***************************************************************************** * intf_SysCreate: initialize and create window *****************************************************************************/int intf_SysCreate( intf_thread_t *p_intf ){ char *psz_display; /* Allocate instance and initialize some members */ p_intf->p_sys = malloc( sizeof( intf_sys_t ) ); if( p_intf->p_sys == NULL ) { intf_ErrMsg("error: %s\n", strerror(ENOMEM)); return( 1 ); } p_intf->p_sys->p_gnome = malloc( sizeof( gnome_thread_t ) ); if( p_intf->p_sys->p_gnome == NULL ) { intf_ErrMsg("error: %s\n", strerror(ENOMEM)); free( p_intf->p_sys ); return( 1 ); } /* Open display, unsing 'vlc_display' or DISPLAY environment variable */ psz_display = XDisplayName( main_GetPszVariable( VOUT_DISPLAY_VAR, NULL ) ); p_intf->p_sys->p_display = XOpenDisplay( psz_display ); if( !p_intf->p_sys->p_display ) /* error */ { intf_ErrMsg("error: can't open display %s\n", psz_display ); free( p_intf->p_sys->p_gnome ); free( p_intf->p_sys ); return( 1 ); } p_intf->p_sys->i_screen = DefaultScreen( p_intf->p_sys->p_display ); /* Spawn base window - this window will include the video output window */ if( GnomeCreateWindow( p_intf ) ) { intf_ErrMsg("error: can't create output window\n" ); XCloseDisplay( p_intf->p_sys->p_display ); free( p_intf->p_sys->p_gnome ); free( p_intf->p_sys ); return( 1 ); } /* Spawn video output thread */ if( p_main->b_video ) { p_intf->p_vout = vout_CreateThread( psz_display, p_intf->p_sys->window, p_intf->p_sys->i_width, p_intf->p_sys->i_height, NULL, 0, (void *)&p_intf->p_sys->colormap ); if( p_intf->p_vout == NULL ) /* error */ { intf_ErrMsg("error: can't create video output thread\n" ); GnomeDestroyWindow( p_intf ); XCloseDisplay( p_intf->p_sys->p_display ); free( p_intf->p_sys->p_gnome ); free( p_intf->p_sys ); return( 1 ); } } /* Spawn Gnome thread */ /* FIXME: try to do this more nicely */ p_intf->p_sys->p_gnome->b_die = 0; p_intf->p_sys->p_gnome->b_error = 0; p_intf->p_sys->p_gnome->b_popup_changed = 0; p_intf->p_sys->p_gnome->b_window_changed = 0; p_intf->p_sys->p_gnome->b_playlist_changed = 0; vlc_thread_create( &p_intf->p_sys->p_gnome->thread_id, "gnome", (void *)GnomeThread, p_intf->p_sys->p_gnome ); /* Disable screen saver and return */ p_intf->p_sys->i_ss_count = 1; GnomeDisableScreenSaver( p_intf ); return( 0 );}/***************************************************************************** * intf_SysDestroy: destroy interface window *****************************************************************************/void intf_SysDestroy( intf_thread_t *p_intf ){ /* Enable screen saver */ GnomeEnableScreenSaver( p_intf ); /* Close input thread, if any (blocking) */ if( p_intf->p_input ) { input_DestroyThread( p_intf->p_input, NULL ); } /* Close video output thread, if any (blocking) */ if( p_intf->p_vout ) { vout_DestroyThread( p_intf->p_vout, NULL ); } /* Close gnome thread, if any (blocking) */ if( p_intf->p_sys->p_gnome->thread_id ) { p_intf->p_sys->p_gnome->b_die = 1; intf_Msg( "waiting for Gnome thread to terminate\n" ); vlc_thread_join( p_intf->p_sys->p_gnome->thread_id ); intf_Msg( "Gnome thread terminated\n" ); } /* Close main window and display */ GnomeDestroyWindow( p_intf ); XCloseDisplay( p_intf->p_sys->p_display ); /* Destroy structures */ free( p_intf->p_sys->p_gnome ); free( p_intf->p_sys );}/***************************************************************************** * intf_SysManage: event loop *****************************************************************************/void intf_SysManage( intf_thread_t *p_intf ){ /* Manage main window */ GnomeManageWindow( p_intf ); /* Manage messages from the Gnome interface */ GnomeManageInterface( p_intf );}/* following functions are local *//***************************************************************************** * GnomeCreateWindow: open and set-up X11 main window *****************************************************************************/static int GnomeCreateWindow( intf_thread_t *p_intf ){ XSizeHints xsize_hints; XSetWindowAttributes xwindow_attributes; XGCValues xgcvalues; XEvent xevent; boolean_t b_expose; boolean_t b_configure_notify; boolean_t b_map_notify; /* Set main window's size */ p_intf->p_sys->i_width = main_GetIntVariable( VOUT_WIDTH_VAR, VOUT_WIDTH_DEFAULT ); p_intf->p_sys->i_height = main_GetIntVariable( VOUT_HEIGHT_VAR, VOUT_HEIGHT_DEFAULT ); /* Prepare window manager hints and properties */ xsize_hints.base_width = p_intf->p_sys->i_width; xsize_hints.base_height = p_intf->p_sys->i_height; xsize_hints.flags = PSize; p_intf->p_sys->wm_protocols = XInternAtom( p_intf->p_sys->p_display, "WM_PROTOCOLS", True ); p_intf->p_sys->wm_delete_window = XInternAtom( p_intf->p_sys->p_display, "WM_DELETE_WINDOW", True ); /* Prepare window attributes */ xwindow_attributes.backing_store = Always; /* save the hidden part */ xwindow_attributes.background_pixel = WhitePixel( p_intf->p_sys->p_display, p_intf->p_sys->i_screen ); xwindow_attributes.event_mask = ExposureMask | StructureNotifyMask; /* Create the window and set hints - the window must receive ConfigureNotify * events, and, until it is displayed, Expose and MapNotify events. */ p_intf->p_sys->window = XCreateWindow( p_intf->p_sys->p_display, DefaultRootWindow( p_intf->p_sys->p_display ), 0, 0, p_intf->p_sys->i_width, p_intf->p_sys->i_height, 1, 0, InputOutput, 0, CWBackingStore | CWBackPixel | CWEventMask, &xwindow_attributes ); /* Set window manager hints and properties: size hints, command, * window's name, and accepted protocols */ XSetWMNormalHints( p_intf->p_sys->p_display, p_intf->p_sys->window, &xsize_hints ); XSetCommand( p_intf->p_sys->p_display, p_intf->p_sys->window, p_main->ppsz_argv, p_main->i_argc ); XStoreName( p_intf->p_sys->p_display, p_intf->p_sys->window, VOUT_TITLE ); if( (p_intf->p_sys->wm_protocols == None) /* use WM_DELETE_WINDOW */ || (p_intf->p_sys->wm_delete_window == None) || !XSetWMProtocols( p_intf->p_sys->p_display, p_intf->p_sys->window, &p_intf->p_sys->wm_delete_window, 1 ) ) { /* WM_DELETE_WINDOW is not supported by window manager */ intf_Msg("error: missing or bad window manager - please exit program kindly.\n"); } /* Creation of a graphic context that doesn't generate a GraphicsExpose * event when using functions like XCopyArea */ xgcvalues.graphics_exposures = False; p_intf->p_sys->gc = XCreateGC( p_intf->p_sys->p_display, p_intf->p_sys->window, GCGraphicsExposures, &xgcvalues); /* Send orders to server, and wait until window is displayed - three * events must be received: a MapNotify event, an Expose event allowing * drawing in the window, and a ConfigureNotify to get the window * dimensions. Once those events have been received, only ConfigureNotify * events need to be received. */ b_expose = 0; b_configure_notify = 0; b_map_notify = 0; XMapWindow( p_intf->p_sys->p_display, p_intf->p_sys->window); do { XNextEvent( p_intf->p_sys->p_display, &xevent); if( (xevent.type == Expose) && (xevent.xexpose.window == p_intf->p_sys->window) ) { b_expose = 1; } else if( (xevent.type == MapNotify) && (xevent.xmap.window == p_intf->p_sys->window) ) { b_map_notify = 1; } else if( (xevent.type == ConfigureNotify) && (xevent.xconfigure.window == p_intf->p_sys->window) ) { b_configure_notify = 1; p_intf->p_sys->i_width = xevent.xconfigure.width; p_intf->p_sys->i_height = xevent.xconfigure.height; } } while( !( b_expose && b_configure_notify && b_map_notify ) ); XSelectInput( p_intf->p_sys->p_display, p_intf->p_sys->window, StructureNotifyMask | KeyPressMask | ButtonPressMask ); if( XDefaultDepth( p_intf->p_sys->p_display, p_intf->p_sys->i_screen ) == 8 ) { /* Allocate a new palette */ p_intf->p_sys->colormap = XCreateColormap( p_intf->p_sys->p_display, DefaultRootWindow( p_intf->p_sys->p_display ), DefaultVisual( p_intf->p_sys->p_display, p_intf->p_sys->i_screen ), AllocAll ); xwindow_attributes.colormap = p_intf->p_sys->colormap; XChangeWindowAttributes( p_intf->p_sys->p_display, p_intf->p_sys->window, CWColormap, &xwindow_attributes ); } /* At this stage, the window is open, displayed, and ready to receive data */ return( 0 );}/***************************************************************************** * GnomeDestroyWindow: destroy X11 main window *****************************************************************************/static void GnomeDestroyWindow( intf_thread_t *p_intf ){ XUnmapWindow( p_intf->p_sys->p_display, p_intf->p_sys->window ); XFreeGC( p_intf->p_sys->p_display, p_intf->p_sys->gc ); XDestroyWindow( p_intf->p_sys->p_display, p_intf->p_sys->window );}/***************************************************************************** * GnomeManageWindow: manage X11 main window *****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -