diff options
Diffstat (limited to 'src/display.c')
-rw-r--r-- | src/display.c | 78 |
1 files changed, 32 insertions, 46 deletions
diff --git a/src/display.c b/src/display.c index 25c6437..806b78e 100644 --- a/src/display.c +++ b/src/display.c @@ -55,6 +55,7 @@ static DRMData_d drmData = {0,}; static int vtPipe[2] = { -1, -1 }; static struct termios termOldConfig; +static struct vt_mode vtModeOld = {0,}; static err _open_graphics_device( void ); static err _get_drm_resources( void ); @@ -66,8 +67,6 @@ static Size _init_vt_switch( void ); static void _vt_release( void ); static void _vt_acquire( void ); static void _vt_switch_sighandler(int sig); -static Size _has_signal(Size signo); -static Size _set_signal(Size signo, void(*sig_handler)(int)); err display_init( void ) @@ -139,6 +138,9 @@ err display_init( void ) __display.surface.data = __display.fb.map[0]; __display.active = 1; + free( drmData.drmRes_fbs ); + free( drmData.drmRes_encs ); + free( drmData.drmRes_conns ); return E33_EXIT_SUCCESS; } @@ -173,34 +175,32 @@ void display_flip( void ) void display_term( void ) { if( e33_ioctl( __display.devfd, DRM_IOCTL_DROP_MASTER, 0 ) == -1 ) { - logw( "Failed to drop drm master. Oh well." ); - } - - if( ioctl(__display.ttyfd, VT_RELDISP, 1) == -1 ) { - logw( "Failed to drop release vt. Oh well." ); + logw( "Failed to drop drm master. Oh well" ); } if( munmap( __display.fb.map[0], (uSize)__display.fb.size ) == -1 ) { - logw( "Failed to unmap framebuffer[0]. Oh well." ); + logw( "Failed to unmap framebuffer[0]. Oh well" ); } if( munmap( __display.fb.map[1], (uSize)__display.fb.size ) == -1 ) { - logw( "Failed to unmap framebuffer[1]. Oh well." ); + logw( "Failed to unmap framebuffer[1]. Oh well" ); + } + + if( close( __display.devfd ) ) { + logw( "Failed to close graphics device. Oh well" ); } - free( drmData.drmRes_fbs ); free( drmData.drmRes_crtcs ); - free( drmData.drmRes_encs ); - free( drmData.drmRes_conns ); - if( close( __display.ttyfd ) == -1 ) { - logw( "Failed to close TTY. Oh well." ); - } - if( close( __display.devfd ) ) { - logw( "Failed to close graphics device. Oh well." ); + if( ioctl(__display.ttyfd, VT_SETMODE, &vtModeOld) < 0 ) { + logw( "Could not reset VT mode. Oh well" ); } if( tcsetattr(STDIN_FILENO, TCSAFLUSH, &termOldConfig) == -1 ) { - logw( "Failed to set stdin attributes. Oh well." ); + logw( "Failed to set stdin attributes. Oh well" ); + } + + if( close( __display.ttyfd ) == -1 ) { + logw( "Failed to close TTY. Oh well" ); } } @@ -329,7 +329,7 @@ static Size _get_drm_connector( void ) { struct drm_mode_modeinfo *mode = &drmData.connModes[j]; - if( strcomp( mode->name, DRM_MODE ) && (mode->vrefresh == DRM_RATE) ) + if( e33_strcmp( mode->name, DRM_MODE ) && (mode->vrefresh == DRM_RATE) ) { /* TODO there has to be a better way */ if( mode->hdisplay % 8 ) { @@ -506,21 +506,6 @@ static int _set_pipe(int fd) return E33_EXIT_SUCCESS; } -static Size _has_signal(Size signo) -{ - struct sigaction sact = {0}; - sigaction(signo, 0, &sact); - return sact.sa_handler != 0; -} - -static Size _set_signal(Size signo, void(*sig_handler)(int)) -{ - struct sigaction sact = {0}; - sact.sa_handler = sig_handler; - sigemptyset(&sact.sa_mask); - sact.sa_flags = SA_RESTART; - return sigaction(signo, &sact, NULL); -} static void _vt_switch_sighandler(int sig) { @@ -535,13 +520,13 @@ static void _vt_switch_sighandler(int sig) static Size _init_vt_switch( void ) { - struct vt_mode vt_mode = {0,}; + struct vt_mode vtMode = {0,}; sigset_t set; __display.ttyfd = -1; - if( pipe(vtPipe) == -1 ) + if( pipe2(vtPipe, 0) == -1 ) { vtPipe[0] = vtPipe[1] = -1; loge( "Could not set VT pipes"); @@ -564,36 +549,37 @@ static Size _init_vt_switch( void ) } - if( _has_signal(REL_SIGNAL) ) { + if( e33_has_signal(REL_SIGNAL) ) { loge( "VT release signal is already in use"); return E33_EXIT_FAILURE; } - if( _has_signal(ACQ_SIGNAL) ) { + if( e33_has_signal(ACQ_SIGNAL) ) { loge( "VT acquire signal is already in use"); return E33_EXIT_FAILURE; } - if( _set_signal( REL_SIGNAL, _vt_switch_sighandler ) ) { + if( e33_set_signal( REL_SIGNAL, _vt_switch_sighandler ) ) { loge( "Could not set relese signal handler"); return E33_EXIT_FAILURE; } - if( _set_signal( ACQ_SIGNAL, _vt_switch_sighandler ) ) { + if( e33_set_signal( ACQ_SIGNAL, _vt_switch_sighandler ) ) { loge( "Could not set acquire signal handler"); return E33_EXIT_FAILURE; } - if( ioctl(__display.ttyfd, VT_GETMODE, &vt_mode) < 0 ) { + if( ioctl(__display.ttyfd, VT_GETMODE, &vtModeOld) < 0 ) { logw( "Could not get VT mode" ); return E33_EXIT_FAILURE; } - vt_mode.mode = VT_PROCESS; - vt_mode.relsig = REL_SIGNAL; - vt_mode.acqsig = ACQ_SIGNAL; - vt_mode.frsig = SIGIO; + vtMode = vtModeOld; + vtMode.mode = VT_PROCESS; + vtMode.relsig = REL_SIGNAL; + vtMode.acqsig = ACQ_SIGNAL; + vtMode.frsig = SIGIO; - if( ioctl(__display.ttyfd, VT_SETMODE, &vt_mode) < 0 ) { + if( ioctl(__display.ttyfd, VT_SETMODE, &vtMode) < 0 ) { logw( "Could not set VT mode" ); return E33_EXIT_FAILURE; } |