2020-01-18 09:38:21 +01:00
/*
2021-08-25 19:39:57 +02:00
* Copyright ( c ) 2018 - 2021 , Andreas Kling < kling @ serenityos . org >
2020-01-18 09:38:21 +01:00
*
2021-04-22 01:24:48 -07:00
* SPDX - License - Identifier : BSD - 2 - Clause
2020-01-18 09:38:21 +01:00
*/
2021-05-28 21:26:39 +02:00
# include <AK/QuickSort.h>
2021-01-03 08:39:46 +00:00
# include <AK/URL.h>
2021-08-25 19:39:57 +02:00
# include <LibConfig/Client.h>
2021-11-21 01:01:21 +01:00
# include <LibConfig/Listener.h>
2020-02-06 15:04:03 +01:00
# include <LibCore/ArgsParser.h>
2021-05-28 21:26:39 +02:00
# include <LibCore/DirIterator.h>
2021-08-06 01:05:32 +02:00
# include <LibCore/Process.h>
2021-11-23 10:59:50 +01:00
# include <LibCore/System.h>
2021-01-03 08:39:46 +00:00
# include <LibDesktop/Launcher.h>
2020-02-06 20:33:02 +01:00
# include <LibGUI/Action.h>
# include <LibGUI/ActionGroup.h>
# include <LibGUI/Application.h>
# include <LibGUI/BoxLayout.h>
2020-12-28 11:30:19 +02:00
# include <LibGUI/Button.h>
# include <LibGUI/CheckBox.h>
2021-05-28 21:26:39 +02:00
# include <LibGUI/ComboBox.h>
2020-12-28 11:30:19 +02:00
# include <LibGUI/Event.h>
2020-11-02 19:30:17 +00:00
# include <LibGUI/Icon.h>
2021-05-28 21:26:39 +02:00
# include <LibGUI/ItemListModel.h>
2020-02-15 01:56:30 +01:00
# include <LibGUI/Menu.h>
2021-04-13 16:18:20 +02:00
# include <LibGUI/Menubar.h>
2020-12-28 11:30:19 +02:00
# include <LibGUI/TextBox.h>
2020-02-06 20:33:02 +01:00
# include <LibGUI/Widget.h>
# include <LibGUI/Window.h>
2021-11-21 01:01:21 +01:00
# include <LibGfx/FontDatabase.h>
2020-02-15 01:18:12 +01:00
# include <LibGfx/Palette.h>
2021-11-22 16:12:40 +01:00
# include <LibMain/Main.h>
2019-10-21 19:50:07 +02:00
# include <LibVT/TerminalWidget.h>
2019-06-07 11:48:03 +02:00
# include <assert.h>
# include <errno.h>
2021-04-30 03:40:38 +02:00
# include <pty.h>
2019-06-07 11:48:03 +02:00
# include <pwd.h>
2019-12-02 16:50:10 +01:00
# include <signal.h>
2019-06-07 11:48:03 +02:00
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <sys/ioctl.h>
2020-11-29 21:03:42 -07:00
# include <sys/wait.h>
2019-06-07 11:48:03 +02:00
# include <unistd.h>
2019-01-15 04:30:55 +01:00
2021-11-21 01:01:21 +01:00
class TerminalChangeListener : public Config : : Listener {
public :
TerminalChangeListener ( VT : : TerminalWidget & parent_terminal )
: m_parent_terminal ( parent_terminal )
{
}
virtual void config_string_did_change ( String const & domain , String const & group , String const & key , String const & value )
{
VERIFY ( domain = = " Terminal " ) ;
if ( group = = " Window " ) {
if ( key = = " Bell " ) {
auto bell_mode = VT : : TerminalWidget : : BellMode : : Visible ;
if ( value = = " AudibleBeep " )
bell_mode = VT : : TerminalWidget : : BellMode : : AudibleBeep ;
if ( value = = " Visible " )
bell_mode = VT : : TerminalWidget : : BellMode : : Visible ;
if ( value = = " Disabled " )
bell_mode = VT : : TerminalWidget : : BellMode : : Disabled ;
m_parent_terminal . set_bell_mode ( bell_mode ) ;
} else if ( key = = " ColorScheme " ) {
m_parent_terminal . set_color_scheme ( value ) ;
}
} else if ( group = = " Text " & & key = = " Font " ) {
auto font = Gfx : : FontDatabase : : the ( ) . get_by_name ( value ) ;
if ( font . is_null ( ) )
font = Gfx : : FontDatabase : : default_fixed_width_font ( ) ;
m_parent_terminal . set_font_and_resize_to_fit ( * font ) ;
m_parent_terminal . window ( ) - > resize ( m_parent_terminal . size ( ) ) ;
}
}
virtual void config_i32_did_change ( String const & domain , String const & group , String const & key , i32 value )
{
VERIFY ( domain = = " Terminal " ) ;
if ( group = = " Terminal " & & key = = " MaxHistorySize " ) {
m_parent_terminal . set_max_history_size ( value ) ;
} else if ( group = = " Window " & & key = = " Opacity " ) {
m_parent_terminal . set_opacity ( value ) ;
}
}
private :
VT : : TerminalWidget & m_parent_terminal ;
} ;
2021-11-24 23:25:03 +01:00
static void utmp_update ( String const & tty , pid_t pid , bool create )
2020-09-06 16:14:46 +02:00
{
int utmpupdate_pid = fork ( ) ;
if ( utmpupdate_pid < 0 ) {
perror ( " fork " ) ;
return ;
}
2020-11-29 21:03:42 -07:00
if ( utmpupdate_pid = = 0 ) {
// Be careful here! Because fork() only clones one thread it's
// possible that we deadlock on anything involving a mutex,
// including the heap! So resort to low-level APIs
char pid_str [ 32 ] ;
snprintf ( pid_str , sizeof ( pid_str ) , " %d " , pid ) ;
2021-11-24 23:25:03 +01:00
execl ( " /bin/utmpupdate " , " /bin/utmpupdate " , " -f " , " Terminal " , " -p " , pid_str , ( create ? " -c " : " -d " ) , tty . characters ( ) , nullptr ) ;
2020-11-29 21:03:42 -07:00
} else {
wait_again :
int status = 0 ;
if ( waitpid ( utmpupdate_pid , & status , 0 ) < 0 ) {
int err = errno ;
if ( err = = EINTR )
goto wait_again ;
perror ( " waitpid " ) ;
return ;
}
if ( WIFEXITED ( status ) & & WEXITSTATUS ( status ) ! = 0 )
dbgln ( " Terminal: utmpupdate exited with status {} " , WEXITSTATUS ( status ) ) ;
else if ( WIFSIGNALED ( status ) )
dbgln ( " Terminal: utmpupdate exited due to unhandled signal {} " , WTERMSIG ( status ) ) ;
}
2020-09-06 16:14:46 +02:00
}
2021-07-04 10:59:40 +02:00
static void run_command ( String command , bool keep_open )
2019-01-15 06:30:19 +01:00
{
2021-04-30 03:40:38 +02:00
String shell = " /bin/Shell " ;
auto * pw = getpwuid ( getuid ( ) ) ;
if ( pw & & pw - > pw_shell ) {
shell = pw - > pw_shell ;
2020-05-25 17:04:57 +04:30
}
2021-04-30 03:40:38 +02:00
endpwent ( ) ;
2020-05-25 17:04:57 +04:30
2021-07-04 10:59:40 +02:00
const char * args [ 5 ] = { shell . characters ( ) , nullptr , nullptr , nullptr , nullptr } ;
2021-04-30 03:40:38 +02:00
if ( ! command . is_empty ( ) ) {
2021-07-04 10:59:40 +02:00
int arg_index = 1 ;
if ( keep_open )
args [ arg_index + + ] = " --keep-open " ;
args [ arg_index + + ] = " -c " ;
args [ arg_index + + ] = command . characters ( ) ;
2019-01-15 06:30:19 +01:00
}
2021-08-07 14:05:33 +02:00
const char * envs [ ] = { " TERM=xterm " , " PAGER=more " , " PATH=/usr/local/bin:/usr/bin:/bin " , nullptr } ;
2021-04-30 03:40:38 +02:00
int rc = execve ( shell . characters ( ) , const_cast < char * * > ( args ) , const_cast < char * * > ( envs ) ) ;
if ( rc < 0 ) {
perror ( " execve " ) ;
exit ( 1 ) ;
}
VERIFY_NOT_REACHED ( ) ;
2019-01-15 06:30:19 +01:00
}
2019-01-15 04:30:55 +01:00
2021-11-24 23:05:25 +01:00
static ErrorOr < NonnullRefPtr < GUI : : Window > > create_find_window ( VT : : TerminalWidget & terminal )
2020-12-28 11:30:19 +02:00
{
2021-11-24 23:05:25 +01:00
auto window = TRY ( GUI : : Window : : try_create ( ) ) ;
2021-02-16 16:20:39 +01:00
window - > set_window_type ( GUI : : WindowType : : ToolWindow ) ;
2020-12-28 11:30:19 +02:00
window - > set_title ( " Find in Terminal " ) ;
window - > set_resizable ( false ) ;
window - > resize ( 300 , 90 ) ;
2021-11-24 23:05:25 +01:00
auto main_widget = TRY ( window - > try_set_main_widget < GUI : : Widget > ( ) ) ;
main_widget - > set_fill_with_background_color ( true ) ;
main_widget - > set_background_role ( ColorRole : : Button ) ;
2021-12-03 09:53:24 +00:00
( void ) TRY ( main_widget - > try_set_layout < GUI : : VerticalBoxLayout > ( ) ) ;
2021-11-24 23:05:25 +01:00
main_widget - > layout ( ) - > set_margins ( 4 ) ;
2020-12-28 11:30:19 +02:00
2021-11-24 23:05:25 +01:00
auto find = TRY ( main_widget - > try_add < GUI : : Widget > ( ) ) ;
2021-12-03 09:53:24 +00:00
( void ) TRY ( find - > try_set_layout < GUI : : HorizontalBoxLayout > ( ) ) ;
2021-11-24 23:05:25 +01:00
find - > layout ( ) - > set_margins ( 4 ) ;
find - > set_fixed_height ( 30 ) ;
2020-12-28 11:30:19 +02:00
2021-11-24 23:05:25 +01:00
auto find_textbox = TRY ( find - > try_add < GUI : : TextBox > ( ) ) ;
find_textbox - > set_fixed_width ( 230 ) ;
find_textbox - > set_focus ( true ) ;
2021-09-11 02:15:44 +03:00
if ( terminal . has_selection ( ) )
2021-11-24 23:05:25 +01:00
find_textbox - > set_text ( terminal . selected_text ( ) . replace ( " \n " , " " , true ) ) ;
auto find_backwards = TRY ( find - > try_add < GUI : : Button > ( ) ) ;
find_backwards - > set_fixed_width ( 25 ) ;
find_backwards - > set_icon ( Gfx : : Bitmap : : try_load_from_file ( " /res/icons/16x16/upward-triangle.png " ) . release_value_but_fixme_should_propagate_errors ( ) ) ;
auto find_forwards = TRY ( find - > try_add < GUI : : Button > ( ) ) ;
find_forwards - > set_fixed_width ( 25 ) ;
find_forwards - > set_icon ( Gfx : : Bitmap : : try_load_from_file ( " /res/icons/16x16/downward-triangle.png " ) . release_value_but_fixme_should_propagate_errors ( ) ) ;
find_textbox - > on_return_pressed = [ find_backwards ] ( ) mutable {
find_backwards - > click ( ) ;
2020-12-28 11:30:19 +02:00
} ;
2021-11-24 23:05:25 +01:00
find_textbox - > on_shift_return_pressed = [ find_forwards ] ( ) mutable {
find_forwards - > click ( ) ;
2021-06-02 13:21:17 +02:00
} ;
2021-11-24 23:05:25 +01:00
auto match_case = TRY ( main_widget - > try_add < GUI : : CheckBox > ( " Case sensitive " ) ) ;
auto wrap_around = TRY ( main_widget - > try_add < GUI : : CheckBox > ( " Wrap around " ) ) ;
2020-12-28 11:30:19 +02:00
2021-11-24 23:05:25 +01:00
find_backwards - > on_click = [ & terminal , find_textbox , match_case , wrap_around ] ( auto ) mutable {
auto needle = find_textbox - > text ( ) ;
2020-12-28 11:30:19 +02:00
if ( needle . is_empty ( ) ) {
return ;
}
2021-11-24 23:05:25 +01:00
auto found_range = terminal . find_previous ( needle , terminal . normalized_selection ( ) . start ( ) , match_case - > is_checked ( ) , wrap_around - > is_checked ( ) ) ;
2020-12-28 11:30:19 +02:00
if ( found_range . is_valid ( ) ) {
terminal . scroll_to_row ( found_range . start ( ) . row ( ) ) ;
terminal . set_selection ( found_range ) ;
}
} ;
2021-11-24 23:32:43 +01:00
find_forwards - > on_click = [ & terminal , find_textbox , match_case , wrap_around ] ( auto ) {
2021-11-24 23:05:25 +01:00
auto needle = find_textbox - > text ( ) ;
2020-12-28 11:30:19 +02:00
if ( needle . is_empty ( ) ) {
return ;
}
2021-11-24 23:05:25 +01:00
auto found_range = terminal . find_next ( needle , terminal . normalized_selection ( ) . end ( ) , match_case - > is_checked ( ) , wrap_around - > is_checked ( ) ) ;
2020-12-28 11:30:19 +02:00
if ( found_range . is_valid ( ) ) {
terminal . scroll_to_row ( found_range . start ( ) . row ( ) ) ;
terminal . set_selection ( found_range ) ;
}
} ;
return window ;
}
2021-11-22 16:12:40 +01:00
ErrorOr < int > serenity_main ( Main : : Arguments arguments )
2019-01-16 12:57:07 +01:00
{
2021-11-27 14:26:34 -08:00
TRY ( Core : : System : : pledge ( " stdio tty rpath cpath wpath recvfd sendfd proc exec unix sigaction " ) ) ;
2020-01-11 21:07:18 +01:00
2019-12-02 16:50:10 +01:00
struct sigaction act ;
memset ( & act , 0 , sizeof ( act ) ) ;
act . sa_flags = SA_NOCLDWAIT ;
act . sa_handler = SIG_IGN ;
2021-11-23 10:59:50 +01:00
TRY ( Core : : System : : sigaction ( SIGCHLD , & act , nullptr ) ) ;
2019-02-11 14:56:23 +01:00
2021-11-24 22:54:49 +01:00
auto app = TRY ( GUI : : Application : : try_create ( arguments ) ) ;
2021-11-22 16:12:40 +01:00
2021-11-27 14:26:34 -08:00
TRY ( Core : : System : : pledge ( " stdio tty rpath cpath wpath recvfd sendfd proc exec unix " ) ) ;
2020-01-11 21:07:18 +01:00
2021-08-25 20:06:54 +02:00
Config : : pledge_domains ( " Terminal " ) ;
2020-02-03 20:42:46 -06:00
const char * command_to_execute = nullptr ;
2021-07-04 10:59:40 +02:00
bool keep_open = false ;
2019-09-02 15:28:52 +10:00
2020-02-02 12:34:39 +01:00
Core : : ArgsParser args_parser ;
2020-01-27 20:25:36 +03:00
args_parser . add_option ( command_to_execute , " Execute this command inside the terminal " , nullptr , ' e ' , " command " ) ;
2021-07-04 10:59:40 +02:00
args_parser . add_option ( keep_open , " Keep the terminal open after the command has finished executing " , nullptr , ' k ' ) ;
2020-03-15 18:20:19 +02:00
2021-11-22 19:03:05 -05:00
args_parser . parse ( arguments ) ;
2019-09-02 15:28:52 +10:00
2021-07-04 10:59:40 +02:00
if ( keep_open & & ! command_to_execute ) {
warnln ( " Option -k can only be used in combination with -e. " ) ;
return 1 ;
}
2021-05-06 13:52:46 +01:00
int ptm_fd ;
pid_t shell_pid = forkpty ( & ptm_fd , nullptr , nullptr , nullptr ) ;
2021-04-30 03:40:38 +02:00
if ( shell_pid < 0 ) {
perror ( " forkpty " ) ;
return 1 ;
}
if ( shell_pid = = 0 ) {
close ( ptm_fd ) ;
if ( command_to_execute )
2021-07-04 10:59:40 +02:00
run_command ( command_to_execute , keep_open ) ;
2021-04-30 03:40:38 +02:00
else
2021-08-25 19:39:57 +02:00
run_command ( Config : : read_string ( " Terminal " , " Startup " , " Command " , " " ) , false ) ;
2021-04-30 03:40:38 +02:00
VERIFY_NOT_REACHED ( ) ;
}
2020-09-06 16:14:46 +02:00
2021-11-24 23:25:03 +01:00
auto ptsname = TRY ( Core : : System : : ptsname ( ptm_fd ) ) ;
utmp_update ( ptsname , shell_pid , true ) ;
2019-01-15 06:30:19 +01:00
2020-11-02 19:30:17 +00:00
auto app_icon = GUI : : Icon : : default_icon ( " app-terminal " ) ;
2021-11-24 22:54:49 +01:00
auto window = TRY ( GUI : : Window : : try_create ( ) ) ;
2019-05-16 20:13:41 +02:00
window - > set_title ( " Terminal " ) ;
2019-04-10 14:29:47 +02:00
window - > set_background_color ( Color : : Black ) ;
2019-03-17 04:23:54 +01:00
window - > set_double_buffering_enabled ( false ) ;
2019-01-15 04:30:55 +01:00
2021-11-24 22:54:49 +01:00
auto terminal = TRY ( window - > try_set_main_widget < VT : : TerminalWidget > ( ptm_fd , true ) ) ;
terminal - > on_command_exit = [ & ] {
2020-07-04 14:05:19 +02:00
app - > quit ( 0 ) ;
2019-10-22 21:57:53 +02:00
} ;
2021-11-24 22:54:49 +01:00
terminal - > on_title_change = [ & ] ( auto title ) {
2019-10-21 22:07:59 +02:00
window - > set_title ( title ) ;
} ;
2021-11-24 22:54:49 +01:00
terminal - > on_terminal_size_change = [ & ] ( auto & size ) {
2021-02-20 16:57:31 +01:00
window - > resize ( size ) ;
} ;
2021-11-24 22:54:49 +01:00
terminal - > apply_size_increments_to_window ( * window ) ;
2020-11-02 19:30:17 +00:00
window - > set_icon ( app_icon . bitmap_for_size ( 16 ) ) ;
2020-12-19 21:47:45 +00:00
2021-11-21 01:01:21 +01:00
Config : : monitor_domain ( " Terminal " ) ;
TerminalChangeListener listener { terminal } ;
2021-08-25 19:39:57 +02:00
auto bell = Config : : read_string ( " Terminal " , " Window " , " Bell " , " Visible " ) ;
2020-12-19 21:47:45 +00:00
if ( bell = = " AudibleBeep " ) {
2021-11-24 22:54:49 +01:00
terminal - > set_bell_mode ( VT : : TerminalWidget : : BellMode : : AudibleBeep ) ;
2020-12-19 21:47:45 +00:00
} else if ( bell = = " Disabled " ) {
2021-11-24 22:54:49 +01:00
terminal - > set_bell_mode ( VT : : TerminalWidget : : BellMode : : Disabled ) ;
2020-12-19 21:47:45 +00:00
} else {
2021-11-24 22:54:49 +01:00
terminal - > set_bell_mode ( VT : : TerminalWidget : : BellMode : : Visible ) ;
2020-12-19 21:47:45 +00:00
}
2019-02-10 14:28:39 +01:00
2021-11-24 23:05:25 +01:00
auto find_window = TRY ( create_find_window ( terminal ) ) ;
2019-05-31 12:43:58 -07:00
2021-08-25 19:39:57 +02:00
auto new_opacity = Config : : read_i32 ( " Terminal " , " Window " , " Opacity " , 255 ) ;
2021-11-24 22:54:49 +01:00
terminal - > set_opacity ( new_opacity ) ;
2019-08-15 15:19:54 +02:00
window - > set_has_alpha_channel ( new_opacity < 255 ) ;
2019-05-25 16:43:15 -07:00
2021-11-24 22:54:49 +01:00
auto new_scrollback_size = Config : : read_i32 ( " Terminal " , " Terminal " , " MaxHistorySize " , terminal - > max_history_size ( ) ) ;
terminal - > set_max_history_size ( new_scrollback_size ) ;
2020-11-29 18:19:45 +03:30
2021-11-06 16:25:29 +01:00
auto open_settings_action = GUI : : Action : : create ( " &Settings " , Gfx : : Bitmap : : try_load_from_file ( " /res/icons/16x16/settings.png " ) . release_value_but_fixme_should_propagate_errors ( ) ,
2020-12-30 17:52:19 +01:00
[ & ] ( auto & ) {
2021-11-21 01:01:21 +01:00
Core : : Process : : spawn ( " /bin/TerminalSettings " ) ;
2020-12-30 17:52:19 +01:00
} ) ;
2021-11-24 22:54:49 +01:00
TRY ( terminal - > context_menu ( ) . try_add_separator ( ) ) ;
TRY ( terminal - > context_menu ( ) . try_add_action ( open_settings_action ) ) ;
2020-12-30 13:42:16 +01:00
2021-11-24 22:54:49 +01:00
auto file_menu = TRY ( window - > try_add_menu ( " &File " ) ) ;
TRY ( file_menu - > try_add_action ( GUI : : Action : : create ( " Open New &Terminal " , { Mod_Ctrl | Mod_Shift , Key_N } , Gfx : : Bitmap : : try_load_from_file ( " /res/icons/16x16/app-terminal.png " ) . release_value_but_fixme_should_propagate_errors ( ) , [ & ] ( auto & ) {
2021-08-06 01:05:32 +02:00
Core : : Process : : spawn ( " /bin/Terminal " ) ;
2021-11-24 22:54:49 +01:00
} ) ) ) ;
2020-12-30 13:42:16 +01:00
2021-11-24 22:54:49 +01:00
TRY ( file_menu - > try_add_action ( open_settings_action ) ) ;
TRY ( file_menu - > try_add_separator ( ) ) ;
TRY ( file_menu - > try_add_action ( GUI : : CommonActions : : make_quit_action ( [ ] ( auto & ) {
2020-10-06 19:12:42 +02:00
dbgln ( " Terminal: Quit menu activated! " ) ;
2020-07-04 16:52:01 +02:00
GUI : : Application : : the ( ) - > quit ( ) ;
2021-11-24 22:54:49 +01:00
} ) ) ) ;
2019-02-11 15:37:12 +01:00
2021-11-24 22:54:49 +01:00
auto edit_menu = TRY ( window - > try_add_menu ( " &Edit " ) ) ;
TRY ( edit_menu - > try_add_action ( terminal - > copy_action ( ) ) ) ;
TRY ( edit_menu - > try_add_action ( terminal - > paste_action ( ) ) ) ;
TRY ( edit_menu - > try_add_separator ( ) ) ;
TRY ( edit_menu - > try_add_action ( GUI : : Action : : create ( " &Find... " , { Mod_Ctrl | Mod_Shift , Key_F } , Gfx : : Bitmap : : try_load_from_file ( " /res/icons/16x16/find.png " ) . release_value_but_fixme_should_propagate_errors ( ) ,
2020-12-28 11:30:19 +02:00
[ & ] ( auto & ) {
find_window - > show ( ) ;
find_window - > move_to_front ( ) ;
2021-11-24 22:54:49 +01:00
} ) ) ) ;
2019-11-20 21:33:23 +01:00
2021-11-24 22:54:49 +01:00
auto view_menu = TRY ( window - > try_add_menu ( " &View " ) ) ;
TRY ( view_menu - > try_add_action ( GUI : : CommonActions : : make_fullscreen_action ( [ & ] ( auto & ) {
2021-03-13 03:49:39 +00:00
window - > set_fullscreen ( ! window - > is_fullscreen ( ) ) ;
2021-11-24 22:54:49 +01:00
} ) ) ) ;
TRY ( view_menu - > try_add_action ( terminal - > clear_including_history_action ( ) ) ) ;
2019-02-12 08:39:19 +01:00
2021-11-24 22:54:49 +01:00
auto help_menu = TRY ( window - > try_add_menu ( " &Help " ) ) ;
TRY ( help_menu - > try_add_action ( GUI : : CommonActions : : make_help_action ( [ ] ( auto & ) {
2021-01-03 08:39:46 +00:00
Desktop : : Launcher : : open ( URL : : create_with_file_protocol ( " /usr/share/man/man1/Terminal.md " ) , " /bin/Help " ) ;
2021-11-24 22:54:49 +01:00
} ) ) ) ;
TRY ( help_menu - > try_add_action ( GUI : : CommonActions : : make_about_action ( " Terminal " , app_icon , window ) ) ) ;
2019-02-11 15:37:12 +01:00
2021-06-02 12:28:52 +02:00
window - > on_close = [ & ] ( ) {
2021-11-24 23:05:25 +01:00
find_window - > close ( ) ;
2021-06-02 12:28:52 +02:00
} ;
2021-11-23 10:59:50 +01:00
TRY ( Core : : System : : unveil ( " /res " , " r " ) ) ;
TRY ( Core : : System : : unveil ( " /bin " , " r " ) ) ;
TRY ( Core : : System : : unveil ( " /bin/Terminal " , " x " ) ) ;
2021-11-21 01:01:21 +01:00
TRY ( Core : : System : : unveil ( " /bin/TerminalSettings " , " x " ) ) ;
2021-11-23 10:59:50 +01:00
TRY ( Core : : System : : unveil ( " /bin/utmpupdate " , " x " ) ) ;
TRY ( Core : : System : : unveil ( " /etc/FileIconProvider.ini " , " r " ) ) ;
TRY ( Core : : System : : unveil ( " /tmp/portal/launch " , " rw " ) ) ;
TRY ( Core : : System : : unveil ( " /tmp/portal/config " , " rw " ) ) ;
TRY ( Core : : System : : unveil ( nullptr , nullptr ) ) ;
2020-01-21 12:12:15 +01:00
2021-06-12 11:59:00 +02:00
window - > show ( ) ;
2020-09-06 16:14:46 +02:00
int result = app - > exec ( ) ;
2020-10-06 19:12:42 +02:00
dbgln ( " Exiting terminal, updating utmp " ) ;
2021-11-24 23:25:03 +01:00
utmp_update ( ptsname , 0 , false ) ;
2020-09-06 16:14:46 +02:00
return result ;
2019-01-15 04:30:55 +01:00
}