2017-04-15 06:32:05 -04:00
|
|
|
/*
|
2014-03-01 11:27:52 -05:00
|
|
|
* rofi
|
2014-01-10 04:35:38 -05:00
|
|
|
*
|
2013-07-19 10:55:01 -04:00
|
|
|
* MIT/X11 License
|
2017-04-15 06:32:05 -04:00
|
|
|
* Copyright © 2012 Sean Pringle <sean.pringle@gmail.com>
|
2021-06-09 08:50:39 -04:00
|
|
|
* Copyright © 2013-2021 Qball Cow <qball@gmpclient.org>
|
2014-01-10 04:35:38 -05:00
|
|
|
*
|
2013-07-19 10:55:01 -04:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
2014-01-10 04:35:38 -05:00
|
|
|
*
|
2013-07-19 10:55:01 -04:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2014-01-10 04:35:38 -05:00
|
|
|
*
|
2013-07-19 10:55:01 -04:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2017-04-15 06:32:05 -04:00
|
|
|
*
|
2013-07-19 10:55:01 -04:00
|
|
|
*/
|
2015-11-14 07:47:45 -05:00
|
|
|
|
2018-06-12 06:31:34 -04:00
|
|
|
/** Log domain */
|
2017-04-15 05:58:49 -04:00
|
|
|
#define G_LOG_DOMAIN "Rofi"
|
|
|
|
|
2014-08-22 03:26:46 -04:00
|
|
|
#include <config.h>
|
2012-06-29 13:10:13 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2014-06-05 11:48:25 -04:00
|
|
|
#include <stdint.h>
|
2014-01-21 08:56:25 -05:00
|
|
|
#include <errno.h>
|
2014-03-16 08:47:44 -04:00
|
|
|
#include <time.h>
|
2015-11-22 07:57:51 -05:00
|
|
|
#include <locale.h>
|
2017-02-14 02:52:17 -05:00
|
|
|
#include <gmodule.h>
|
2016-02-19 16:43:53 -05:00
|
|
|
#include <xcb/xcb.h>
|
2015-02-01 04:03:16 -05:00
|
|
|
#include <sys/types.h>
|
2019-01-07 11:19:33 -05:00
|
|
|
#include <sysexits.h>
|
2014-03-18 05:55:25 -04:00
|
|
|
|
2016-01-18 14:51:35 -05:00
|
|
|
#include <glib-unix.h>
|
|
|
|
|
2016-02-19 16:43:53 -05:00
|
|
|
#include <libgwater-xcb.h>
|
|
|
|
|
2017-10-15 11:51:45 -04:00
|
|
|
#ifdef USE_NK_GIT_VERSION
|
|
|
|
#include "nkutils-git-version.h"
|
|
|
|
#ifdef NK_GIT_VERSION
|
2017-11-07 14:04:07 -05:00
|
|
|
#define GIT_VERSION NK_GIT_VERSION
|
2017-10-15 11:51:45 -04:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-10-31 13:16:08 -04:00
|
|
|
#include "resources.h"
|
2017-10-31 13:00:24 -04:00
|
|
|
|
2017-08-18 05:38:54 -04:00
|
|
|
#include "rofi.h"
|
2017-06-01 08:55:17 -04:00
|
|
|
#include "display.h"
|
2015-09-13 11:29:50 -04:00
|
|
|
|
2016-01-07 10:01:56 -05:00
|
|
|
#include "settings.h"
|
2016-01-09 10:22:09 -05:00
|
|
|
#include "mode.h"
|
2015-01-30 15:55:31 -05:00
|
|
|
#include "helper.h"
|
2016-10-08 12:57:59 -04:00
|
|
|
#include "widgets/textbox.h"
|
2015-02-09 13:35:51 -05:00
|
|
|
#include "xrmoptions.h"
|
2015-08-31 01:57:29 -04:00
|
|
|
#include "dialogs/dialogs.h"
|
2015-09-19 06:21:30 -04:00
|
|
|
|
2016-02-07 06:31:17 -05:00
|
|
|
#include "view.h"
|
|
|
|
#include "view-internal.h"
|
|
|
|
|
2016-12-09 13:49:49 -05:00
|
|
|
#include "theme.h"
|
2018-06-09 13:13:57 -04:00
|
|
|
#include "rofi-icon-fetcher.h"
|
2016-12-09 13:49:49 -05:00
|
|
|
|
2017-02-14 02:52:17 -05:00
|
|
|
#include "timings.h"
|
|
|
|
|
2017-02-14 12:12:07 -05:00
|
|
|
// Plugin abi version.
|
|
|
|
// TODO: move this check to mode.c
|
|
|
|
#include "mode-private.h"
|
|
|
|
|
2018-06-12 06:31:34 -04:00
|
|
|
/** Location of pidfile for this instance. */
|
2018-08-08 09:55:13 -04:00
|
|
|
char *pidfile = NULL;
|
2018-06-12 06:31:34 -04:00
|
|
|
/** Location of Cache directory. */
|
2016-10-26 02:24:34 -04:00
|
|
|
const char *cache_dir = NULL;
|
2016-10-25 16:45:11 -04:00
|
|
|
|
2017-01-09 16:40:11 -05:00
|
|
|
/** List of error messages.*/
|
2017-01-09 12:32:26 -05:00
|
|
|
GList *list_of_error_msgs = NULL;
|
|
|
|
|
2017-03-04 06:00:59 -05:00
|
|
|
static void rofi_collect_modi_destroy ( void );
|
2017-01-09 12:32:26 -05:00
|
|
|
void rofi_add_error_message ( GString *str )
|
|
|
|
{
|
|
|
|
list_of_error_msgs = g_list_append ( list_of_error_msgs, str );
|
|
|
|
}
|
2021-06-27 06:21:26 -04:00
|
|
|
void rofi_clear_error_messages ( void )
|
|
|
|
{
|
|
|
|
if ( list_of_error_msgs ) {
|
|
|
|
for ( GList *iter = g_list_first ( list_of_error_msgs );
|
|
|
|
iter != NULL; iter = g_list_next ( iter ) ) {
|
|
|
|
g_string_free ( (GString *) iter->data, TRUE );
|
|
|
|
}
|
|
|
|
g_list_free ( list_of_error_msgs );
|
|
|
|
list_of_error_msgs = NULL;
|
|
|
|
}
|
|
|
|
}
|
2016-10-25 16:45:11 -04:00
|
|
|
|
|
|
|
/** Path to the configuration file */
|
2018-08-08 09:55:13 -04:00
|
|
|
G_MODULE_EXPORT char *config_path = NULL;
|
2018-06-12 06:31:34 -04:00
|
|
|
/** Path to the configuration file in the new format */
|
2016-10-25 16:45:11 -04:00
|
|
|
/** Array holding all activated modi. */
|
2021-06-01 04:44:23 -04:00
|
|
|
Mode **modi = NULL;
|
2017-03-31 07:47:44 -04:00
|
|
|
|
|
|
|
/** List of (possibly uninitialized) modi's */
|
|
|
|
Mode ** available_modi = NULL;
|
|
|
|
/** Length of #num_available_modi */
|
|
|
|
unsigned int num_available_modi = 0;
|
2016-10-25 16:45:11 -04:00
|
|
|
/** Number of activated modi in #modi array */
|
2016-10-26 02:24:34 -04:00
|
|
|
unsigned int num_modi = 0;
|
2016-10-25 16:45:11 -04:00
|
|
|
/** Current selected mode */
|
2016-10-26 02:24:34 -04:00
|
|
|
unsigned int curr_switcher = 0;
|
2015-09-26 14:34:34 -04:00
|
|
|
|
2018-06-12 06:31:34 -04:00
|
|
|
/** Handle to NkBindings object for input devices. */
|
2018-08-08 09:55:13 -04:00
|
|
|
NkBindings *bindings = NULL;
|
2017-06-01 08:55:17 -04:00
|
|
|
|
2016-10-25 16:45:11 -04:00
|
|
|
/** Glib main loop. */
|
2017-06-03 14:35:50 -04:00
|
|
|
GMainLoop *main_loop = NULL;
|
2016-01-20 14:57:26 -05:00
|
|
|
|
2016-10-25 16:45:11 -04:00
|
|
|
/** Flag indicating we are in dmenu mode. */
|
2021-06-01 04:44:23 -04:00
|
|
|
static int dmenu_mode = FALSE;
|
2016-10-25 16:45:11 -04:00
|
|
|
/** Rofi's return code */
|
2021-06-01 04:44:23 -04:00
|
|
|
int return_code = EXIT_SUCCESS;
|
2020-01-02 06:00:44 -05:00
|
|
|
|
2016-02-19 13:29:06 -05:00
|
|
|
void process_result ( RofiViewState *state );
|
2015-12-14 15:02:36 -05:00
|
|
|
|
2016-02-19 13:29:06 -05:00
|
|
|
void rofi_set_return_code ( int code )
|
|
|
|
{
|
|
|
|
return_code = code;
|
|
|
|
}
|
|
|
|
|
2016-02-11 02:41:19 -05:00
|
|
|
unsigned int rofi_get_num_enabled_modi ( void )
|
|
|
|
{
|
|
|
|
return num_modi;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Mode * rofi_get_mode ( unsigned int index )
|
|
|
|
{
|
|
|
|
return modi[index];
|
|
|
|
}
|
|
|
|
|
2014-12-02 02:11:53 -05:00
|
|
|
/**
|
|
|
|
* @param name Name of the switcher to lookup.
|
|
|
|
*
|
|
|
|
* Find the index of the switcher with name.
|
|
|
|
*
|
2015-11-25 03:26:38 -05:00
|
|
|
* @returns index of the switcher in modi, -1 if not found.
|
2014-12-02 02:11:53 -05:00
|
|
|
*/
|
|
|
|
static int switcher_get ( const char *name )
|
2014-07-21 15:39:24 -04:00
|
|
|
{
|
2015-11-25 03:26:38 -05:00
|
|
|
for ( unsigned int i = 0; i < num_modi; i++ ) {
|
2016-02-06 07:40:25 -05:00
|
|
|
if ( strcmp ( mode_get_name ( modi[i] ), name ) == 0 ) {
|
2014-07-21 15:39:24 -04:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-07-30 02:57:09 -04:00
|
|
|
/**
|
|
|
|
* Teardown the gui.
|
|
|
|
*/
|
|
|
|
static void teardown ( int pfd )
|
|
|
|
{
|
2017-04-15 05:37:50 -04:00
|
|
|
g_debug ( "Teardown" );
|
2014-08-05 03:07:41 -04:00
|
|
|
// Cleanup font setup.
|
2015-01-21 04:04:15 -05:00
|
|
|
textbox_cleanup ( );
|
|
|
|
|
2017-06-01 08:55:17 -04:00
|
|
|
display_early_cleanup ();
|
2015-11-30 04:15:53 -05:00
|
|
|
|
2016-02-06 08:27:36 -05:00
|
|
|
// Cleanup view
|
|
|
|
rofi_view_cleanup ();
|
2015-07-28 16:22:18 -04:00
|
|
|
// Cleanup pid file.
|
2015-07-30 02:57:09 -04:00
|
|
|
remove_pid_file ( pfd );
|
|
|
|
}
|
2015-11-25 03:26:38 -05:00
|
|
|
static void run_switcher ( ModeMode mode )
|
2014-01-20 16:58:10 -05:00
|
|
|
{
|
2014-07-21 15:39:24 -04:00
|
|
|
// Otherwise check if requested mode is enabled.
|
2015-11-25 03:26:38 -05:00
|
|
|
for ( unsigned int i = 0; i < num_modi; i++ ) {
|
2016-02-06 07:40:25 -05:00
|
|
|
if ( !mode_init ( modi[i] ) ) {
|
2017-04-02 06:32:11 -04:00
|
|
|
GString *str = g_string_new ( "Failed to initialize the mode: " );
|
2017-03-31 11:47:04 -04:00
|
|
|
g_string_append ( str, modi[i]->name );
|
2017-04-02 06:32:11 -04:00
|
|
|
g_string_append ( str, "\n" );
|
2017-03-31 11:47:04 -04:00
|
|
|
|
|
|
|
rofi_view_error_dialog ( str->str, ERROR_MSG_MARKUP );
|
2017-04-02 06:32:11 -04:00
|
|
|
g_string_free ( str, FALSE );
|
2017-03-31 11:51:23 -04:00
|
|
|
break;
|
2016-01-08 03:16:59 -05:00
|
|
|
}
|
2015-03-27 15:28:53 -04:00
|
|
|
}
|
2016-11-02 13:20:17 -04:00
|
|
|
// Error dialog must have been created.
|
|
|
|
if ( rofi_view_get_active () != NULL ) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-08 12:57:59 -04:00
|
|
|
curr_switcher = mode;
|
2017-10-30 16:40:13 -04:00
|
|
|
RofiViewState * state = rofi_view_create ( modi[mode], config.filter, 0, process_result );
|
2020-03-29 06:56:47 -04:00
|
|
|
|
|
|
|
// User can pre-select a row.
|
2020-08-28 10:41:59 -04:00
|
|
|
if ( find_arg ( "-selected-row" ) >= 0 ) {
|
|
|
|
unsigned int sr = 0;
|
|
|
|
find_arg_uint ( "-selected-row", &( sr ) );
|
|
|
|
rofi_view_set_selected_line ( state, sr );
|
2020-03-29 06:56:47 -04:00
|
|
|
}
|
2016-10-08 12:57:59 -04:00
|
|
|
if ( state ) {
|
|
|
|
rofi_view_set_active ( state );
|
|
|
|
}
|
|
|
|
if ( rofi_view_get_active () == NULL ) {
|
|
|
|
g_main_loop_quit ( main_loop );
|
|
|
|
}
|
2016-01-20 14:57:26 -05:00
|
|
|
}
|
2016-02-19 13:29:06 -05:00
|
|
|
void process_result ( RofiViewState *state )
|
2016-01-20 14:57:26 -05:00
|
|
|
{
|
2016-02-19 13:29:06 -05:00
|
|
|
Mode *sw = state->sw;
|
2020-11-03 17:57:02 -05:00
|
|
|
// rofi_view_set_active ( NULL );
|
2016-02-19 13:29:06 -05:00
|
|
|
if ( sw != NULL ) {
|
|
|
|
unsigned int selected_line = rofi_view_get_selected_line ( state );;
|
|
|
|
MenuReturn mretv = rofi_view_get_return_value ( state );
|
|
|
|
char *input = g_strdup ( rofi_view_get_user_input ( state ) );
|
2016-04-19 16:10:34 -04:00
|
|
|
ModeMode retv = mode_result ( sw, mretv, &input, selected_line );
|
2021-06-01 07:14:45 -04:00
|
|
|
{
|
|
|
|
if ( state->text ){
|
|
|
|
if ( input == NULL ) {
|
|
|
|
textbox_text ( state->text, "" );
|
|
|
|
} else if ( strcmp ( rofi_view_get_user_input ( state ), input ) != 0 ) {
|
|
|
|
textbox_text ( state->text, input );
|
|
|
|
textbox_cursor_end ( state->text );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-08 12:57:59 -04:00
|
|
|
g_free ( input );
|
2016-02-19 13:29:06 -05:00
|
|
|
|
2016-10-08 12:57:59 -04:00
|
|
|
ModeMode mode = curr_switcher;
|
2016-02-19 13:29:06 -05:00
|
|
|
// Find next enabled
|
|
|
|
if ( retv == NEXT_DIALOG ) {
|
|
|
|
mode = ( mode + 1 ) % num_modi;
|
|
|
|
}
|
|
|
|
else if ( retv == PREVIOUS_DIALOG ) {
|
|
|
|
if ( mode == 0 ) {
|
|
|
|
mode = num_modi - 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mode = ( mode - 1 ) % num_modi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( retv == RELOAD_DIALOG ) {
|
|
|
|
// do nothing.
|
|
|
|
}
|
2016-12-12 02:52:27 -05:00
|
|
|
else if ( retv == RESET_DIALOG ) {
|
|
|
|
rofi_view_clear_input ( state );
|
|
|
|
}
|
2016-02-19 13:29:06 -05:00
|
|
|
else if ( retv < MODE_EXIT ) {
|
|
|
|
mode = ( retv ) % num_modi;
|
2015-03-27 15:28:53 -04:00
|
|
|
}
|
|
|
|
else {
|
2016-02-19 13:29:06 -05:00
|
|
|
mode = retv;
|
2015-03-27 15:28:53 -04:00
|
|
|
}
|
2016-02-19 13:29:06 -05:00
|
|
|
if ( mode != MODE_EXIT ) {
|
|
|
|
/**
|
|
|
|
* Load in the new mode.
|
|
|
|
*/
|
2016-10-08 12:57:59 -04:00
|
|
|
rofi_view_switch_mode ( state, modi[mode] );
|
|
|
|
curr_switcher = mode;
|
|
|
|
return;
|
2020-11-03 17:57:02 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// On exit, free current view, and pop to one above.
|
|
|
|
rofi_view_remove_active ( state );
|
|
|
|
rofi_view_free ( state );
|
|
|
|
return;
|
2016-02-19 13:29:06 -05:00
|
|
|
}
|
2014-07-21 15:39:24 -04:00
|
|
|
}
|
2020-09-13 15:56:25 -04:00
|
|
|
// rofi_view_set_active ( NULL );
|
2020-11-03 17:57:02 -05:00
|
|
|
rofi_view_remove_active ( state );
|
2016-02-19 13:29:06 -05:00
|
|
|
rofi_view_free ( state );
|
2012-06-29 13:10:13 -04:00
|
|
|
}
|
|
|
|
|
2014-01-19 07:57:54 -05:00
|
|
|
/**
|
2015-10-21 03:42:55 -04:00
|
|
|
* Help function.
|
2014-01-19 07:57:54 -05:00
|
|
|
*/
|
2017-04-20 03:24:09 -04:00
|
|
|
static void print_list_of_modi ( int is_term )
|
|
|
|
{
|
|
|
|
for ( unsigned int i = 0; i < num_available_modi; i++ ) {
|
|
|
|
gboolean active = FALSE;
|
|
|
|
for ( unsigned int j = 0; j < num_modi; j++ ) {
|
|
|
|
if ( modi[j] == available_modi[i] ) {
|
|
|
|
active = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf ( " * %s%s%s%s\n",
|
2017-04-27 16:59:14 -04:00
|
|
|
active ? "+" : "",
|
|
|
|
is_term ? ( active ? color_green : color_red ) : "",
|
|
|
|
available_modi[i]->name,
|
|
|
|
is_term ? color_reset : ""
|
|
|
|
);
|
2017-04-20 03:24:09 -04:00
|
|
|
}
|
|
|
|
}
|
2016-11-25 14:00:27 -05:00
|
|
|
static void print_main_application_options ( int is_term )
|
2015-10-21 03:42:55 -04:00
|
|
|
{
|
2015-11-15 07:12:43 -05:00
|
|
|
print_help_msg ( "-no-config", "", "Do not load configuration, use default values.", NULL, is_term );
|
|
|
|
print_help_msg ( "-v,-version", "", "Print the version number and exit.", NULL, is_term );
|
|
|
|
print_help_msg ( "-dmenu", "", "Start in dmenu mode.", NULL, is_term );
|
|
|
|
print_help_msg ( "-display", "[string]", "X server to contact.", "${DISPLAY}", is_term );
|
|
|
|
print_help_msg ( "-h,-help", "", "This help message.", NULL, is_term );
|
|
|
|
print_help_msg ( "-e", "[string]", "Show a dialog displaying the passed message and exit.", NULL, is_term );
|
|
|
|
print_help_msg ( "-markup", "", "Enable pango markup where possible.", NULL, is_term );
|
2020-05-10 09:47:20 -04:00
|
|
|
print_help_msg ( "-normal-window", "", "Behave as a normal window. (experimental)", NULL, is_term );
|
2015-11-14 13:59:56 -05:00
|
|
|
print_help_msg ( "-show", "[mode]", "Show the mode 'mode' and exit. The mode has to be enabled.", NULL, is_term );
|
2017-02-02 13:00:45 -05:00
|
|
|
print_help_msg ( "-no-lazy-grab", "", "Disable lazy grab that, when fail to grab keyboard, does not block but retry later.", NULL, is_term );
|
2017-04-21 03:48:03 -04:00
|
|
|
print_help_msg ( "-no-plugins", "", "Disable loading of external plugins.", NULL, is_term );
|
2020-04-19 05:55:53 -04:00
|
|
|
print_help_msg ( "-plugin-path", "", "Directory used to search for rofi plugins. *DEPRECATED*", NULL, is_term );
|
2017-09-04 10:46:06 -04:00
|
|
|
print_help_msg ( "-dump-config", "", "Dump the current configuration in rasi format and exit.", NULL, is_term );
|
2017-06-21 02:19:47 -04:00
|
|
|
print_help_msg ( "-dump-theme", "", "Dump the current theme in rasi format and exit.", NULL, is_term );
|
2015-10-21 03:42:55 -04:00
|
|
|
}
|
2015-10-15 16:33:44 -04:00
|
|
|
static void help ( G_GNUC_UNUSED int argc, char **argv )
|
2014-01-19 07:57:54 -05:00
|
|
|
{
|
2016-11-25 14:00:27 -05:00
|
|
|
int is_term = isatty ( fileno ( stdout ) );
|
2015-10-15 16:33:44 -04:00
|
|
|
printf ( "%s usage:\n", argv[0] );
|
|
|
|
printf ( "\t%s [-options ...]\n\n", argv[0] );
|
2015-10-21 12:58:01 -04:00
|
|
|
printf ( "Command line only options:\n" );
|
2016-11-25 14:00:27 -05:00
|
|
|
print_main_application_options ( is_term );
|
2015-10-21 12:58:01 -04:00
|
|
|
printf ( "DMENU command line options:\n" );
|
|
|
|
print_dmenu_options ();
|
|
|
|
printf ( "Global options:\n" );
|
2015-10-15 16:33:44 -04:00
|
|
|
print_options ();
|
|
|
|
printf ( "\n" );
|
2017-06-01 08:55:17 -04:00
|
|
|
display_dump_monitor_layout ();
|
2017-04-27 16:59:14 -04:00
|
|
|
printf ( "\n" );
|
|
|
|
printf ( "Detected modi:\n" );
|
2017-04-20 03:24:09 -04:00
|
|
|
print_list_of_modi ( is_term );
|
2016-11-25 14:00:27 -05:00
|
|
|
printf ( "\n" );
|
2017-01-08 15:36:06 -05:00
|
|
|
printf ( "Compile time options:\n" );
|
2016-11-25 14:00:27 -05:00
|
|
|
#ifdef WINDOW_MODE
|
2017-01-08 15:36:06 -05:00
|
|
|
printf ( "\t* window %senabled%s\n", is_term ? color_green : "", is_term ? color_reset : "" );
|
2016-11-25 14:00:27 -05:00
|
|
|
#else
|
2017-01-08 15:36:06 -05:00
|
|
|
printf ( "\t* window %sdisabled%s\n", is_term ? color_red : "", is_term ? color_reset : "" );
|
2016-11-25 14:00:27 -05:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_DRUN
|
2017-01-08 15:36:06 -05:00
|
|
|
printf ( "\t* drun %senabled%s\n", is_term ? color_green : "", is_term ? color_reset : "" );
|
2016-11-25 14:00:27 -05:00
|
|
|
#else
|
2017-01-08 15:36:06 -05:00
|
|
|
printf ( "\t* drun %sdisabled%s\n", is_term ? color_red : "", is_term ? color_reset : "" );
|
2016-11-25 14:00:27 -05:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_GCOV
|
2017-01-08 15:36:06 -05:00
|
|
|
printf ( "\t* gcov %senabled%s\n", is_term ? color_green : "", is_term ? color_reset : "" );
|
2016-11-25 14:00:27 -05:00
|
|
|
#else
|
2017-01-08 15:36:06 -05:00
|
|
|
printf ( "\t* gcov %sdisabled%s\n", is_term ? color_red : "", is_term ? color_reset : "" );
|
2016-11-25 14:00:27 -05:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_ASAN
|
2017-01-08 15:36:06 -05:00
|
|
|
printf ( "\t* asan %senabled%s\n", is_term ? color_green : "", is_term ? color_reset : "" );
|
2016-11-25 14:00:27 -05:00
|
|
|
#else
|
2017-01-08 15:36:06 -05:00
|
|
|
printf ( "\t* asan %sdisabled%s\n", is_term ? color_red : "", is_term ? color_reset : "" );
|
2016-11-25 14:00:27 -05:00
|
|
|
#endif
|
|
|
|
printf ( "\n" );
|
2017-01-08 15:36:06 -05:00
|
|
|
printf ( "For more information see: %sman rofi%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
|
2016-03-12 08:00:19 -05:00
|
|
|
#ifdef GIT_VERSION
|
2017-01-08 15:36:06 -05:00
|
|
|
printf ( " Version: %s"GIT_VERSION "%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
|
2016-04-05 10:56:06 -04:00
|
|
|
#else
|
2017-01-08 15:36:06 -05:00
|
|
|
printf ( " Version: %s"VERSION "%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
|
2016-03-12 08:00:19 -05:00
|
|
|
#endif
|
2017-01-08 15:36:06 -05:00
|
|
|
printf ( " Bugreports: %s"PACKAGE_BUGREPORT "%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
|
|
|
|
printf ( " Support: %s"PACKAGE_URL "%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
|
2021-05-22 18:24:06 -04:00
|
|
|
printf ( " %s#rofi @ libera.chat%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
|
2016-12-06 13:24:17 -05:00
|
|
|
if ( find_arg ( "-no-config" ) < 0 ) {
|
2021-06-01 04:43:25 -04:00
|
|
|
if ( config_path ) {
|
2017-06-20 03:16:12 -04:00
|
|
|
printf ( " Configuration file: %s%s%s\n", is_term ? color_bold : "", config_path, is_term ? color_reset : "" );
|
|
|
|
}
|
2017-01-08 15:36:06 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf ( " Configuration file: %sDisabled%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
|
2016-12-06 13:24:17 -05:00
|
|
|
}
|
2014-01-19 07:57:54 -05:00
|
|
|
}
|
|
|
|
|
2017-03-31 07:59:46 -04:00
|
|
|
static void help_print_disabled_mode ( const char *mode )
|
|
|
|
{
|
|
|
|
int is_term = isatty ( fileno ( stdout ) );
|
|
|
|
// Only output to terminal
|
|
|
|
if ( is_term ) {
|
2017-04-27 16:59:14 -04:00
|
|
|
fprintf ( stderr, "Mode %s%s%s is not enabled. I have enabled it for now.\n",
|
2017-04-02 06:32:11 -04:00
|
|
|
color_red, mode, color_reset );
|
2017-04-27 16:59:14 -04:00
|
|
|
fprintf ( stderr, "Please consider adding %s%s%s to the list of enabled modi: %smodi: %s%s%s,%s%s.\n",
|
2017-04-02 06:32:11 -04:00
|
|
|
color_red, mode, color_reset,
|
|
|
|
color_green, config.modi, color_reset,
|
|
|
|
color_red, mode, color_reset
|
|
|
|
);
|
2017-03-31 07:59:46 -04:00
|
|
|
}
|
|
|
|
}
|
2017-04-20 03:24:09 -04:00
|
|
|
static void help_print_mode_not_found ( const char *mode )
|
|
|
|
{
|
2020-02-02 07:56:37 -05:00
|
|
|
GString *str = g_string_new ( "" );
|
|
|
|
g_string_printf ( str, "Mode %s is not found.\nThe following modi are known:\n", mode );
|
2019-03-23 21:30:16 -04:00
|
|
|
for ( unsigned int i = 0; i < num_available_modi; i++ ) {
|
|
|
|
gboolean active = FALSE;
|
|
|
|
for ( unsigned int j = 0; j < num_modi; j++ ) {
|
|
|
|
if ( modi[j] == available_modi[i] ) {
|
|
|
|
active = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-02-02 07:56:37 -05:00
|
|
|
g_string_append_printf ( str, " * %s%s\n",
|
|
|
|
active ? "+" : "",
|
|
|
|
available_modi[i]->name
|
|
|
|
);
|
2019-03-23 21:30:16 -04:00
|
|
|
}
|
|
|
|
rofi_add_error_message ( str );
|
2017-04-20 03:24:09 -04:00
|
|
|
}
|
2017-03-31 07:47:44 -04:00
|
|
|
static void help_print_no_arguments ( void )
|
|
|
|
{
|
|
|
|
int is_term = isatty ( fileno ( stdout ) );
|
|
|
|
// Daemon mode
|
|
|
|
fprintf ( stderr, "Rofi is unsure what to show.\n" );
|
|
|
|
fprintf ( stderr, "Please specify the mode you want to show.\n\n" );
|
|
|
|
fprintf ( stderr, " %srofi%s -show %s{mode}%s\n\n",
|
|
|
|
is_term ? color_bold : "", is_term ? color_reset : "",
|
|
|
|
is_term ? color_green : "", is_term ? color_reset : "" );
|
|
|
|
fprintf ( stderr, "The following modi are enabled:\n" );
|
|
|
|
for ( unsigned int j = 0; j < num_modi; j++ ) {
|
|
|
|
fprintf ( stderr, " * %s%s%s\n",
|
|
|
|
is_term ? color_green : "",
|
|
|
|
modi[j]->name,
|
|
|
|
is_term ? color_reset : "" );
|
|
|
|
}
|
|
|
|
fprintf ( stderr, "\nThe following can be enabled:\n" );
|
|
|
|
for ( unsigned int i = 0; i < num_available_modi; i++ ) {
|
|
|
|
gboolean active = FALSE;
|
|
|
|
for ( unsigned int j = 0; j < num_modi; j++ ) {
|
|
|
|
if ( modi[j] == available_modi[i] ) {
|
|
|
|
active = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !active ) {
|
|
|
|
fprintf ( stderr, " * %s%s%s\n",
|
|
|
|
is_term ? color_red : "",
|
|
|
|
available_modi[i]->name,
|
|
|
|
is_term ? color_reset : "" );
|
|
|
|
}
|
|
|
|
}
|
2017-04-15 15:50:55 -04:00
|
|
|
fprintf ( stderr, "\nTo activate a mode, add it to the list of modi in the %smodi%s setting.\n",
|
2017-04-02 06:32:11 -04:00
|
|
|
is_term ? color_green : "", is_term ? color_reset : "" );
|
2017-03-31 07:47:44 -04:00
|
|
|
}
|
|
|
|
|
2014-09-23 03:24:24 -04:00
|
|
|
/**
|
|
|
|
* Cleanup globally allocated memory.
|
|
|
|
*/
|
2014-05-19 15:58:13 -04:00
|
|
|
static void cleanup ()
|
2014-05-19 15:02:05 -04:00
|
|
|
{
|
2016-04-19 16:10:34 -04:00
|
|
|
for ( unsigned int i = 0; i < num_modi; i++ ) {
|
|
|
|
mode_destroy ( modi[i] );
|
|
|
|
}
|
2016-02-10 13:40:19 -05:00
|
|
|
rofi_view_workers_finalize ();
|
2016-01-22 12:18:26 -05:00
|
|
|
if ( main_loop != NULL ) {
|
|
|
|
g_main_loop_unref ( main_loop );
|
|
|
|
main_loop = NULL;
|
|
|
|
}
|
2014-05-19 15:02:05 -04:00
|
|
|
// Cleanup
|
2017-06-01 08:55:17 -04:00
|
|
|
display_cleanup ();
|
|
|
|
|
|
|
|
nk_bindings_free ( bindings );
|
2016-08-22 02:39:22 -04:00
|
|
|
|
2014-05-19 15:58:13 -04:00
|
|
|
// Cleaning up memory allocated by the Xresources file.
|
2015-02-03 02:21:59 -05:00
|
|
|
config_xresource_free ();
|
2015-11-25 03:26:38 -05:00
|
|
|
g_free ( modi );
|
2015-04-30 16:42:04 -04:00
|
|
|
|
2016-04-01 11:58:41 -04:00
|
|
|
g_free ( config_path );
|
|
|
|
|
2021-06-27 06:21:26 -04:00
|
|
|
rofi_clear_error_messages();
|
2017-01-09 17:08:11 -05:00
|
|
|
|
|
|
|
if ( rofi_theme ) {
|
|
|
|
rofi_theme_free ( rofi_theme );
|
|
|
|
rofi_theme = NULL;
|
|
|
|
}
|
2015-11-24 16:53:40 -05:00
|
|
|
TIMINGS_STOP ();
|
2017-03-04 06:00:59 -05:00
|
|
|
rofi_collect_modi_destroy ( );
|
2018-06-09 13:13:57 -04:00
|
|
|
rofi_icon_fetcher_destroy ( );
|
2021-06-14 13:29:05 -04:00
|
|
|
|
|
|
|
if ( rofi_configuration ) {
|
|
|
|
rofi_theme_free ( rofi_configuration );
|
|
|
|
rofi_configuration = NULL;
|
|
|
|
}
|
2017-03-04 06:00:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Collected modi
|
|
|
|
*/
|
|
|
|
|
|
|
|
Mode * rofi_collect_modi_search ( const char *name )
|
|
|
|
{
|
2017-03-04 13:41:06 -05:00
|
|
|
for ( unsigned int i = 0; i < num_available_modi; i++ ) {
|
2017-03-04 06:00:59 -05:00
|
|
|
if ( g_strcmp0 ( name, available_modi[i]->name ) == 0 ) {
|
|
|
|
return available_modi[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @param mode Add mode to list.
|
|
|
|
*
|
|
|
|
* @returns TRUE when success.
|
|
|
|
*/
|
|
|
|
static gboolean rofi_collect_modi_add ( Mode *mode )
|
|
|
|
{
|
|
|
|
Mode *m = rofi_collect_modi_search ( mode->name );
|
|
|
|
if ( m == NULL ) {
|
2017-03-04 13:41:06 -05:00
|
|
|
available_modi = g_realloc ( available_modi, sizeof ( Mode * ) * ( num_available_modi + 1 ) );
|
2017-03-04 06:00:59 -05:00
|
|
|
// Set mode.
|
|
|
|
available_modi[num_available_modi] = mode;
|
|
|
|
num_available_modi++;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-03-04 06:22:28 -05:00
|
|
|
static void rofi_collect_modi_dir ( const char *base_dir )
|
|
|
|
{
|
2020-04-19 05:34:28 -04:00
|
|
|
g_debug ( "Looking into: %s for plugins", base_dir );
|
2017-03-04 06:22:28 -05:00
|
|
|
GDir *dir = g_dir_open ( base_dir, 0, NULL );
|
2017-03-04 06:00:59 -05:00
|
|
|
if ( dir ) {
|
|
|
|
const char *dn = NULL;
|
2017-03-04 13:41:06 -05:00
|
|
|
while ( ( dn = g_dir_read_name ( dir ) ) ) {
|
2017-03-04 06:00:59 -05:00
|
|
|
if ( !g_str_has_suffix ( dn, G_MODULE_SUFFIX ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-08-28 10:41:59 -04:00
|
|
|
char *fn = g_build_filename ( base_dir, dn, NULL );
|
2020-04-19 05:34:28 -04:00
|
|
|
g_debug ( "Trying to open: %s plugin", fn );
|
2017-03-04 13:41:06 -05:00
|
|
|
GModule *mod = g_module_open ( fn, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL );
|
2017-03-04 06:00:59 -05:00
|
|
|
if ( mod ) {
|
|
|
|
Mode *m = NULL;
|
2017-03-04 13:41:06 -05:00
|
|
|
if ( g_module_symbol ( mod, "mode", (gpointer *) &m ) ) {
|
2017-03-04 06:00:59 -05:00
|
|
|
if ( m->abi_version != ABI_VERSION ) {
|
2017-04-21 03:48:03 -04:00
|
|
|
g_warning ( "ABI version of plugin: '%s' does not match: %08X expecting: %08X", dn, m->abi_version, ABI_VERSION );
|
2017-03-04 06:00:59 -05:00
|
|
|
g_module_close ( mod );
|
2017-03-04 13:41:06 -05:00
|
|
|
}
|
|
|
|
else {
|
2017-03-04 06:00:59 -05:00
|
|
|
m->module = mod;
|
2017-03-04 13:41:06 -05:00
|
|
|
if ( !rofi_collect_modi_add ( m ) ) {
|
2017-03-04 06:00:59 -05:00
|
|
|
g_module_close ( mod );
|
|
|
|
}
|
|
|
|
}
|
2017-03-04 13:41:06 -05:00
|
|
|
}
|
|
|
|
else {
|
2017-04-21 03:48:03 -04:00
|
|
|
g_warning ( "Symbol 'mode' not found in module: %s", dn );
|
2017-03-04 06:00:59 -05:00
|
|
|
g_module_close ( mod );
|
|
|
|
}
|
2017-05-27 20:18:09 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
g_warning ( "Failed to open 'mode' plugin: '%s', error: %s", dn, g_module_error () );
|
2017-03-04 06:00:59 -05:00
|
|
|
}
|
|
|
|
g_free ( fn );
|
|
|
|
}
|
|
|
|
g_dir_close ( dir );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-04 06:22:28 -05:00
|
|
|
/**
|
|
|
|
* Find all available modi.
|
|
|
|
*/
|
|
|
|
static void rofi_collect_modi ( void )
|
|
|
|
{
|
|
|
|
#ifdef WINDOW_MODE
|
|
|
|
rofi_collect_modi_add ( &window_mode );
|
|
|
|
rofi_collect_modi_add ( &window_mode_cd );
|
|
|
|
#endif
|
|
|
|
rofi_collect_modi_add ( &run_mode );
|
|
|
|
rofi_collect_modi_add ( &ssh_mode );
|
|
|
|
#ifdef ENABLE_DRUN
|
|
|
|
rofi_collect_modi_add ( &drun_mode );
|
|
|
|
#endif
|
|
|
|
rofi_collect_modi_add ( &combi_mode );
|
|
|
|
rofi_collect_modi_add ( &help_keys_mode );
|
2020-10-12 14:17:21 -04:00
|
|
|
rofi_collect_modi_add ( &file_browser_mode );
|
2017-03-04 06:22:28 -05:00
|
|
|
|
2017-04-21 03:48:03 -04:00
|
|
|
if ( find_arg ( "-no-plugins" ) < 0 ) {
|
2017-11-07 14:04:07 -05:00
|
|
|
find_arg_str ( "-plugin-path", &( config.plugin_path ) );
|
2017-10-16 12:25:16 -04:00
|
|
|
g_debug ( "Parse plugin path: %s", config.plugin_path );
|
2017-04-21 03:48:03 -04:00
|
|
|
rofi_collect_modi_dir ( config.plugin_path );
|
2020-04-19 05:34:28 -04:00
|
|
|
/* ROFI_PLUGIN_PATH */
|
2020-08-28 10:41:59 -04:00
|
|
|
const char *path = g_getenv ( "ROFI_PLUGIN_PATH" );
|
2020-04-19 05:34:28 -04:00
|
|
|
if ( path != NULL ) {
|
|
|
|
gchar ** paths = g_strsplit ( path, ":", -1 );
|
|
|
|
for ( unsigned int i = 0; paths[i]; i++ ) {
|
|
|
|
rofi_collect_modi_dir ( paths[i] );
|
|
|
|
}
|
|
|
|
g_strfreev ( paths );
|
|
|
|
}
|
2017-04-21 03:48:03 -04:00
|
|
|
}
|
2017-03-04 06:22:28 -05:00
|
|
|
}
|
|
|
|
|
2017-03-04 06:00:59 -05:00
|
|
|
/**
|
|
|
|
* Setup configuration for config.
|
|
|
|
*/
|
|
|
|
static void rofi_collect_modi_setup ( void )
|
|
|
|
{
|
2017-03-04 13:41:06 -05:00
|
|
|
for ( unsigned int i = 0; i < num_available_modi; i++ ) {
|
|
|
|
mode_set_config ( available_modi[i] );
|
2017-03-04 06:00:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
static void rofi_collect_modi_destroy ( void )
|
|
|
|
{
|
2017-03-04 13:41:06 -05:00
|
|
|
for ( unsigned int i = 0; i < num_available_modi; i++ ) {
|
2017-03-04 06:00:59 -05:00
|
|
|
if ( available_modi[i]->module ) {
|
2017-09-10 14:55:45 -04:00
|
|
|
GModule *mod = available_modi[i]->module;
|
|
|
|
available_modi[i] = NULL;
|
|
|
|
g_module_close ( mod );
|
|
|
|
}
|
|
|
|
if ( available_modi[i] ) {
|
2017-10-05 11:45:50 -04:00
|
|
|
mode_free ( &( available_modi[i] ) );
|
2017-03-04 06:00:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free ( available_modi );
|
2017-03-04 13:41:06 -05:00
|
|
|
available_modi = NULL;
|
2017-03-04 06:00:59 -05:00
|
|
|
num_available_modi = 0;
|
2014-05-19 15:02:05 -04:00
|
|
|
}
|
2014-05-20 05:41:39 -04:00
|
|
|
|
2014-09-23 03:24:24 -04:00
|
|
|
/**
|
2015-11-25 03:26:38 -05:00
|
|
|
* Parse the switcher string, into internal array of type Mode.
|
2014-09-23 03:24:24 -04:00
|
|
|
*
|
|
|
|
* String is split on separator ','
|
|
|
|
* First the three build-in modi are checked: window, run, ssh
|
|
|
|
* if that fails, a script-switcher is created.
|
|
|
|
*/
|
2016-02-04 03:20:10 -05:00
|
|
|
static int add_mode ( const char * token )
|
|
|
|
{
|
|
|
|
unsigned int index = num_modi;
|
|
|
|
// Resize and add entry.
|
2016-02-06 07:40:25 -05:00
|
|
|
modi = (Mode * *) g_realloc ( modi, sizeof ( Mode* ) * ( num_modi + 1 ) );
|
2016-02-04 03:20:10 -05:00
|
|
|
|
2017-03-04 06:00:59 -05:00
|
|
|
Mode *mode = rofi_collect_modi_search ( token );
|
|
|
|
if ( mode ) {
|
|
|
|
modi[num_modi] = mode;
|
2016-02-04 03:20:10 -05:00
|
|
|
num_modi++;
|
2017-03-04 13:41:06 -05:00
|
|
|
}
|
2017-04-27 16:59:14 -04:00
|
|
|
else if ( script_switcher_is_valid ( token ) ) {
|
2016-02-04 03:20:10 -05:00
|
|
|
// If not build in, use custom modi.
|
|
|
|
Mode *sw = script_switcher_parse_setup ( token );
|
|
|
|
if ( sw != NULL ) {
|
2017-09-10 14:06:01 -04:00
|
|
|
// Add to available list, so combi can find it.
|
2017-10-05 11:45:50 -04:00
|
|
|
rofi_collect_modi_add ( sw );
|
2021-06-01 06:17:59 -04:00
|
|
|
mode_set_config ( sw );
|
2016-02-06 07:40:25 -05:00
|
|
|
modi[num_modi] = sw;
|
2016-02-04 03:20:10 -05:00
|
|
|
num_modi++;
|
2017-03-04 13:41:06 -05:00
|
|
|
}
|
2016-02-04 03:20:10 -05:00
|
|
|
}
|
|
|
|
return ( index == num_modi ) ? -1 : (int) index;
|
|
|
|
}
|
2017-04-20 03:24:09 -04:00
|
|
|
static gboolean setup_modi ( void )
|
2014-07-21 15:39:24 -04:00
|
|
|
{
|
2017-03-31 14:57:42 -04:00
|
|
|
const char *const sep = ",#";
|
2016-03-20 05:16:55 -04:00
|
|
|
char *savept = NULL;
|
2015-01-08 07:16:44 -05:00
|
|
|
// Make a copy, as strtok will modify it.
|
2016-03-20 05:16:55 -04:00
|
|
|
char *switcher_str = g_strdup ( config.modi );
|
2014-12-02 02:11:53 -05:00
|
|
|
// Split token on ','. This modifies switcher_str.
|
2016-03-19 08:29:04 -04:00
|
|
|
for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) {
|
2017-04-27 16:59:14 -04:00
|
|
|
if ( add_mode ( token ) == -1 ) {
|
2017-04-20 03:24:09 -04:00
|
|
|
help_print_mode_not_found ( token );
|
|
|
|
}
|
2014-07-21 15:39:24 -04:00
|
|
|
}
|
2014-12-02 02:11:53 -05:00
|
|
|
// Free string that was modified by strtok_r
|
2014-08-09 05:40:42 -04:00
|
|
|
g_free ( switcher_str );
|
2017-04-20 03:24:09 -04:00
|
|
|
return FALSE;
|
2014-11-05 04:52:10 -05:00
|
|
|
}
|
|
|
|
|
2018-06-12 06:31:34 -04:00
|
|
|
/**
|
|
|
|
* Quit rofi mainloop.
|
|
|
|
* This will exit program.
|
|
|
|
**/
|
2017-06-01 07:30:29 -04:00
|
|
|
void rofi_quit_main_loop ( void )
|
|
|
|
{
|
|
|
|
g_main_loop_quit ( main_loop );
|
|
|
|
}
|
|
|
|
|
2016-01-19 02:10:17 -05:00
|
|
|
static gboolean main_loop_signal_handler_int ( G_GNUC_UNUSED gpointer data )
|
2016-01-18 14:51:35 -05:00
|
|
|
{
|
|
|
|
// Break out of loop.
|
|
|
|
g_main_loop_quit ( main_loop );
|
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
2019-03-23 21:30:16 -04:00
|
|
|
static void show_error_dialog ()
|
|
|
|
{
|
|
|
|
GString *emesg = g_string_new ( "The following errors were detected when starting rofi:\n" );
|
|
|
|
GList *iter = g_list_first ( list_of_error_msgs );
|
|
|
|
int index = 0;
|
|
|
|
for (; iter != NULL && index < 2; iter = g_list_next ( iter ) ) {
|
|
|
|
GString *msg = (GString *) ( iter->data );
|
|
|
|
g_string_append ( emesg, "\n\n" );
|
|
|
|
g_string_append ( emesg, msg->str );
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
if ( g_list_length ( iter ) > 1 ) {
|
|
|
|
g_string_append_printf ( emesg, "\nThere are <b>%d</b> more errors.", g_list_length ( iter ) - 1 );
|
|
|
|
}
|
|
|
|
rofi_view_error_dialog ( emesg->str, ERROR_MSG_MARKUP );
|
|
|
|
g_string_free ( emesg, TRUE );
|
|
|
|
rofi_set_return_code ( EX_DATAERR );
|
|
|
|
}
|
2016-01-18 14:51:35 -05:00
|
|
|
|
2016-02-19 13:29:06 -05:00
|
|
|
static gboolean startup ( G_GNUC_UNUSED gpointer data )
|
|
|
|
{
|
2016-02-19 13:50:48 -05:00
|
|
|
TICK_N ( "Startup" );
|
2016-02-19 13:29:06 -05:00
|
|
|
// flags to run immediately and exit
|
2016-04-19 16:10:34 -04:00
|
|
|
char *sname = NULL;
|
|
|
|
char *msg = NULL;
|
|
|
|
MenuFlags window_flags = MENU_NORMAL;
|
|
|
|
|
|
|
|
if ( find_arg ( "-normal-window" ) >= 0 ) {
|
|
|
|
window_flags |= MENU_NORMAL_WINDOW;
|
|
|
|
}
|
2016-11-06 10:50:12 -05:00
|
|
|
TICK_N ( "Grab keyboard" );
|
2016-04-19 16:10:34 -04:00
|
|
|
__create_window ( window_flags );
|
2016-10-08 12:57:59 -04:00
|
|
|
TICK_N ( "Create Window" );
|
2016-02-19 13:50:48 -05:00
|
|
|
// Parse the keybindings.
|
|
|
|
TICK_N ( "Parse ABE" );
|
2016-10-08 12:57:59 -04:00
|
|
|
// Sanity check
|
2017-01-09 12:32:26 -05:00
|
|
|
config_sanity_check ( );
|
|
|
|
TICK_N ( "Config sanity check" );
|
|
|
|
|
|
|
|
if ( list_of_error_msgs != NULL ) {
|
2019-03-23 21:30:16 -04:00
|
|
|
show_error_dialog ();
|
2016-10-08 12:57:59 -04:00
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
2016-02-19 13:29:06 -05:00
|
|
|
// Dmenu mode.
|
|
|
|
if ( dmenu_mode == TRUE ) {
|
|
|
|
// force off sidebar mode:
|
|
|
|
config.sidebar_mode = FALSE;
|
2016-04-20 02:08:18 -04:00
|
|
|
int retv = dmenu_switcher_dialog ();
|
2016-02-19 13:29:06 -05:00
|
|
|
if ( retv ) {
|
2016-02-19 13:50:48 -05:00
|
|
|
rofi_set_return_code ( EXIT_SUCCESS );
|
2016-02-19 13:29:06 -05:00
|
|
|
// Directly exit.
|
2016-02-19 13:50:48 -05:00
|
|
|
g_main_loop_quit ( main_loop );
|
2016-02-19 13:29:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( find_arg_str ( "-e", &( msg ) ) ) {
|
|
|
|
int markup = FALSE;
|
|
|
|
if ( find_arg ( "-markup" ) >= 0 ) {
|
|
|
|
markup = TRUE;
|
|
|
|
}
|
2016-04-19 16:10:34 -04:00
|
|
|
if ( !rofi_view_error_dialog ( msg, markup ) ) {
|
2016-03-03 02:21:28 -05:00
|
|
|
g_main_loop_quit ( main_loop );
|
|
|
|
}
|
2016-02-19 13:29:06 -05:00
|
|
|
}
|
|
|
|
else if ( find_arg_str ( "-show", &sname ) == TRUE ) {
|
|
|
|
int index = switcher_get ( sname );
|
|
|
|
if ( index < 0 ) {
|
|
|
|
// Add it to the list
|
|
|
|
index = add_mode ( sname );
|
|
|
|
// Complain
|
|
|
|
if ( index >= 0 ) {
|
2017-03-31 07:59:46 -04:00
|
|
|
help_print_disabled_mode ( sname );
|
2016-02-19 13:29:06 -05:00
|
|
|
}
|
|
|
|
// Run it anyway if found.
|
|
|
|
}
|
|
|
|
if ( index >= 0 ) {
|
|
|
|
run_switcher ( index );
|
|
|
|
}
|
|
|
|
else {
|
2017-04-20 03:24:09 -04:00
|
|
|
help_print_mode_not_found ( sname );
|
2019-03-23 21:30:16 -04:00
|
|
|
show_error_dialog ();
|
2016-02-19 13:29:06 -05:00
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
}
|
2016-07-13 02:55:40 -04:00
|
|
|
else if ( find_arg ( "-show" ) >= 0 && num_modi > 0 ) {
|
|
|
|
run_switcher ( 0 );
|
|
|
|
}
|
2016-02-19 13:29:06 -05:00
|
|
|
else{
|
2017-03-31 07:47:44 -04:00
|
|
|
help_print_no_arguments ( );
|
2017-03-31 04:11:50 -04:00
|
|
|
|
2016-03-13 15:11:39 -04:00
|
|
|
g_main_loop_quit ( main_loop );
|
2016-02-19 13:29:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
2017-04-28 03:15:01 -04:00
|
|
|
static gboolean record ( G_GNUC_UNUSED void *data )
|
2017-04-27 16:59:14 -04:00
|
|
|
{
|
|
|
|
rofi_capture_screenshot ();
|
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
2016-10-25 16:45:11 -04:00
|
|
|
/**
|
|
|
|
* @param argc number of input arguments.
|
|
|
|
* @param argv array of the input arguments.
|
|
|
|
*
|
|
|
|
* Main application entry point.
|
|
|
|
*
|
|
|
|
* @returns return code of rofi.
|
|
|
|
*/
|
2014-05-22 03:33:32 -04:00
|
|
|
int main ( int argc, char *argv[] )
|
|
|
|
{
|
2015-11-24 16:53:40 -05:00
|
|
|
TIMINGS_START ();
|
2015-11-14 07:47:45 -05:00
|
|
|
|
2015-03-11 13:32:37 -04:00
|
|
|
cmd_set_arguments ( argc, argv );
|
2016-04-02 16:11:38 -04:00
|
|
|
|
2015-02-03 02:21:59 -05:00
|
|
|
// Version
|
2015-03-11 13:32:37 -04:00
|
|
|
if ( find_arg ( "-v" ) >= 0 || find_arg ( "-version" ) >= 0 ) {
|
2016-03-12 08:00:19 -05:00
|
|
|
#ifdef GIT_VERSION
|
2017-04-15 05:58:49 -04:00
|
|
|
g_print ( "Version: "GIT_VERSION "\n" );
|
2016-04-05 10:56:06 -04:00
|
|
|
#else
|
2017-04-15 05:58:49 -04:00
|
|
|
g_print ( "Version: "VERSION "\n" );
|
2016-03-12 08:00:19 -05:00
|
|
|
#endif
|
2017-03-25 09:23:31 -04:00
|
|
|
return EXIT_SUCCESS;
|
2015-02-03 02:21:59 -05:00
|
|
|
}
|
|
|
|
|
2021-01-26 11:27:32 -05:00
|
|
|
if ( find_arg ( "-rasi-validate" ) >= 0 ) {
|
|
|
|
char *str = NULL;
|
|
|
|
find_arg_str ( "-rasi-validate", &str );
|
|
|
|
if ( str != NULL ) {
|
|
|
|
int retv = rofi_theme_rasi_validate ( str );
|
|
|
|
cleanup ();
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
fprintf ( stderr, "Usage: %s -rasi-validate my-theme.rasi", argv[0] );
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2020-05-21 03:35:55 -04:00
|
|
|
{
|
2020-08-28 10:41:59 -04:00
|
|
|
const char *ro_pid = g_getenv ( "ROFI_OUTSIDE" );
|
2020-05-21 03:35:55 -04:00
|
|
|
if ( ro_pid != NULL ) {
|
|
|
|
int ro_pidi = g_ascii_strtoll ( ro_pid, NULL, 0 );
|
|
|
|
if ( kill ( ro_pidi, 0 ) == 0 ) {
|
2020-08-28 10:41:59 -04:00
|
|
|
printf ( "Do not launch rofi from inside rofi.\r\n" );
|
|
|
|
return EXIT_FAILURE;
|
2020-05-21 03:35:55 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-17 04:31:59 -05:00
|
|
|
// Detect if we are in dmenu mode.
|
|
|
|
// This has two possible causes.
|
|
|
|
// 1 the user specifies it on the command-line.
|
2015-03-11 13:32:37 -04:00
|
|
|
if ( find_arg ( "-dmenu" ) >= 0 ) {
|
2015-02-17 04:31:59 -05:00
|
|
|
dmenu_mode = TRUE;
|
|
|
|
}
|
|
|
|
// 2 the binary that executed is called dmenu (e.g. symlink to rofi)
|
|
|
|
else{
|
|
|
|
// Get the base name of the executable called.
|
2016-04-10 06:05:34 -04:00
|
|
|
char *base_name = g_path_get_basename ( argv[0] );
|
|
|
|
const char * const dmenu_str = "dmenu";
|
2016-04-05 15:26:21 -04:00
|
|
|
dmenu_mode = ( strcmp ( base_name, dmenu_str ) == 0 );
|
2015-02-17 04:31:59 -05:00
|
|
|
// Free the basename for dmenu detection.
|
|
|
|
g_free ( base_name );
|
|
|
|
}
|
2015-11-24 16:53:40 -05:00
|
|
|
TICK ();
|
2016-11-12 05:28:40 -05:00
|
|
|
|
2015-01-31 12:23:17 -05:00
|
|
|
// Create pid file path.
|
2015-02-17 04:31:59 -05:00
|
|
|
const char *path = g_get_user_runtime_dir ();
|
|
|
|
if ( path ) {
|
2016-11-12 05:36:39 -05:00
|
|
|
if ( g_mkdir_with_parents ( path, 0700 ) < 0 ) {
|
2017-04-15 05:58:49 -04:00
|
|
|
g_warning ( "Failed to create user runtime directory: %s with error: %s", path, g_strerror ( errno ) );
|
2017-03-25 16:52:51 -04:00
|
|
|
pidfile = g_build_filename ( g_get_home_dir (), ".rofi.pid", NULL );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pidfile = g_build_filename ( path, "rofi.pid", NULL );
|
2016-11-12 05:36:39 -05:00
|
|
|
}
|
2015-01-31 12:23:17 -05:00
|
|
|
}
|
2015-10-16 02:42:01 -04:00
|
|
|
config_parser_add_option ( xrm_String, "pid", (void * *) &pidfile, "Pidfile location" );
|
2015-01-31 12:23:17 -05:00
|
|
|
|
2021-07-09 18:25:20 -04:00
|
|
|
|
|
|
|
/** default configuration */
|
|
|
|
{
|
|
|
|
GBytes *theme_data = g_resource_lookup_data (
|
|
|
|
resources_get_resource (),
|
|
|
|
"/org/qtools/rofi/default_configuration.rasi",
|
|
|
|
G_RESOURCE_LOOKUP_FLAGS_NONE,
|
|
|
|
NULL );
|
|
|
|
if ( theme_data ) {
|
|
|
|
const char *theme = g_bytes_get_data ( theme_data, NULL );
|
|
|
|
if ( rofi_theme_parse_string ( (const char *) theme ) ) {
|
|
|
|
g_warning ( "Failed to parse default configuration. Giving up.." );
|
|
|
|
if ( list_of_error_msgs ) {
|
|
|
|
for ( GList *iter = g_list_first ( list_of_error_msgs );
|
|
|
|
iter != NULL; iter = g_list_next ( iter ) ) {
|
|
|
|
g_warning ( "Error: %s%s%s",
|
|
|
|
color_bold, ( (GString *) iter->data )->str, color_reset );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rofi_configuration = NULL;
|
|
|
|
cleanup ();
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
g_bytes_unref ( theme_data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-01 11:58:41 -04:00
|
|
|
if ( find_arg ( "-config" ) < 0 ) {
|
|
|
|
const char *cpath = g_get_user_config_dir ();
|
|
|
|
if ( cpath ) {
|
2021-06-01 04:44:23 -04:00
|
|
|
config_path = g_build_filename ( cpath, "rofi", "config.rasi", NULL );
|
2016-04-01 11:58:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
char *c = NULL;
|
|
|
|
find_arg_str ( "-config", &c );
|
2021-06-01 04:43:25 -04:00
|
|
|
config_path = rofi_expand_path ( c );
|
2016-04-01 11:58:41 -04:00
|
|
|
}
|
|
|
|
|
2015-11-24 16:53:40 -05:00
|
|
|
TICK ();
|
2015-11-22 15:10:39 -05:00
|
|
|
if ( setlocale ( LC_ALL, "" ) == NULL ) {
|
2017-04-15 05:58:49 -04:00
|
|
|
g_warning ( "Failed to set locale." );
|
2017-03-25 09:23:31 -04:00
|
|
|
cleanup ();
|
2015-11-22 07:57:51 -05:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2015-11-22 15:10:39 -05:00
|
|
|
|
2017-07-03 03:23:03 -04:00
|
|
|
TICK_N ( "Setup Locale" );
|
2017-03-04 06:00:59 -05:00
|
|
|
rofi_collect_modi ();
|
|
|
|
TICK_N ( "Collect MODI" );
|
2017-07-03 03:23:03 -04:00
|
|
|
rofi_collect_modi_setup ();
|
|
|
|
TICK_N ( "Setup MODI" );
|
2016-01-22 12:18:26 -05:00
|
|
|
|
2017-06-01 05:44:21 -04:00
|
|
|
main_loop = g_main_loop_new ( NULL, FALSE );
|
|
|
|
|
|
|
|
TICK_N ( "Setup mainloop" );
|
|
|
|
|
2017-12-25 17:41:14 -05:00
|
|
|
bindings = nk_bindings_new ( 0 );
|
2017-07-03 03:23:03 -04:00
|
|
|
TICK_N ( "NK Bindings" );
|
2017-06-01 08:55:17 -04:00
|
|
|
|
|
|
|
if ( !display_setup ( main_loop, bindings ) ) {
|
2017-04-15 05:58:49 -04:00
|
|
|
g_warning ( "Connection has error" );
|
2017-03-25 09:23:31 -04:00
|
|
|
cleanup ();
|
|
|
|
return EXIT_FAILURE;
|
2016-03-04 11:03:24 -05:00
|
|
|
}
|
2017-06-01 06:03:23 -04:00
|
|
|
TICK_N ( "Setup Display" );
|
2017-05-31 18:39:11 -04:00
|
|
|
|
2015-04-30 16:42:04 -04:00
|
|
|
// Setup keybinding
|
|
|
|
setup_abe ();
|
2015-11-24 16:53:40 -05:00
|
|
|
TICK_N ( "Setup abe" );
|
2015-04-30 16:42:04 -04:00
|
|
|
|
2016-04-01 11:58:41 -04:00
|
|
|
if ( find_arg ( "-no-config" ) < 0 ) {
|
2020-04-19 05:55:53 -04:00
|
|
|
// Load distro default settings
|
2020-08-28 10:41:59 -04:00
|
|
|
gboolean found_system = FALSE;
|
|
|
|
const char * const * dirs = g_get_system_config_dirs ();
|
|
|
|
if ( dirs ) {
|
|
|
|
for ( unsigned int i = 0; !found_system && dirs[i]; i++ ) {
|
2020-04-19 05:55:53 -04:00
|
|
|
/** New format. */
|
|
|
|
gchar *etc = g_build_filename ( dirs[i], "rofi.rasi", NULL );
|
|
|
|
g_debug ( "Look for default config file: %s", etc );
|
|
|
|
if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) {
|
|
|
|
g_debug ( "Parsing: %s", etc );
|
|
|
|
rofi_theme_parse_file ( etc );
|
2020-08-28 10:41:59 -04:00
|
|
|
found_system = TRUE;
|
|
|
|
}
|
2020-04-19 05:55:53 -04:00
|
|
|
g_free ( etc );
|
|
|
|
}
|
2020-02-02 07:56:37 -05:00
|
|
|
}
|
2020-08-28 10:41:59 -04:00
|
|
|
if ( !found_system ) {
|
2020-04-19 05:55:53 -04:00
|
|
|
/** New format. */
|
|
|
|
gchar *etc = g_build_filename ( SYSCONFDIR, "rofi.rasi", NULL );
|
|
|
|
g_debug ( "Look for default config file: %s", etc );
|
|
|
|
if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) {
|
|
|
|
g_debug ( "Look for default config file: %s", etc );
|
|
|
|
rofi_theme_parse_file ( etc );
|
2020-08-28 10:41:59 -04:00
|
|
|
}
|
2020-04-19 05:55:53 -04:00
|
|
|
g_free ( etc );
|
2017-03-28 11:03:46 -04:00
|
|
|
}
|
2020-04-19 10:24:13 -04:00
|
|
|
|
2021-06-01 04:43:25 -04:00
|
|
|
if ( config_path && g_file_test ( config_path, G_FILE_TEST_IS_REGULAR ) ) {
|
|
|
|
if ( rofi_theme_parse_file ( config_path ) ) {
|
2017-06-20 03:16:12 -04:00
|
|
|
rofi_theme_free ( rofi_theme );
|
|
|
|
rofi_theme = NULL;
|
|
|
|
}
|
2018-08-08 09:55:13 -04:00
|
|
|
}
|
2017-05-16 15:55:52 -04:00
|
|
|
}
|
|
|
|
find_arg_str ( "-theme", &( config.theme ) );
|
|
|
|
if ( config.theme ) {
|
|
|
|
TICK_N ( "Parse theme" );
|
|
|
|
if ( rofi_theme_parse_file ( config.theme ) ) {
|
|
|
|
// TODO: instantiate fallback theme.?
|
|
|
|
rofi_theme_free ( rofi_theme );
|
|
|
|
rofi_theme = NULL;
|
2017-03-28 11:03:46 -04:00
|
|
|
}
|
2017-05-16 15:55:52 -04:00
|
|
|
TICK_N ( "Parsed theme" );
|
2016-04-01 11:58:41 -04:00
|
|
|
}
|
2016-09-18 16:29:05 -04:00
|
|
|
// Parse command line for settings, independent of other -no-config.
|
|
|
|
config_parse_cmd_options ( );
|
2017-03-28 11:03:46 -04:00
|
|
|
TICK_N ( "Load cmd config " );
|
2016-09-18 16:29:05 -04:00
|
|
|
|
2017-06-03 10:06:32 -04:00
|
|
|
parse_keys_abe ( bindings );
|
2017-06-01 11:46:51 -04:00
|
|
|
|
2019-02-08 14:43:53 -05:00
|
|
|
// Get the path to the cache dir.
|
|
|
|
cache_dir = g_get_user_cache_dir ();
|
|
|
|
|
|
|
|
if ( config.cache_dir != NULL ) {
|
|
|
|
cache_dir = config.cache_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( g_mkdir_with_parents ( cache_dir, 0700 ) < 0 ) {
|
|
|
|
g_warning ( "Failed to create cache directory: %s", g_strerror ( errno ) );
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-07-13 02:21:15 -04:00
|
|
|
/** dirty hack for dmenu compatibility */
|
|
|
|
char *windowid = NULL;
|
2015-02-17 04:31:59 -05:00
|
|
|
if ( !dmenu_mode ) {
|
2015-11-25 03:26:38 -05:00
|
|
|
// setup_modi
|
2017-04-27 16:59:14 -04:00
|
|
|
if ( setup_modi () ) {
|
2017-04-20 03:24:09 -04:00
|
|
|
cleanup ();
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2017-03-06 03:56:02 -05:00
|
|
|
TICK_N ( "Setup Modi" );
|
2015-02-17 04:31:59 -05:00
|
|
|
}
|
2017-07-13 02:21:15 -04:00
|
|
|
else {
|
|
|
|
// Hack for dmenu compatibility.
|
|
|
|
if ( find_arg_str ( "-w", &windowid ) == TRUE ) {
|
|
|
|
config.monitor = g_strdup_printf ( "wid:%s", windowid );
|
|
|
|
windowid = config.monitor;
|
|
|
|
}
|
|
|
|
}
|
2017-03-11 11:06:06 -05:00
|
|
|
if ( rofi_theme_is_empty ( ) ) {
|
2017-10-31 13:00:24 -04:00
|
|
|
GBytes *theme_data = g_resource_lookup_data (
|
2017-11-07 14:04:07 -05:00
|
|
|
resources_get_resource (),
|
|
|
|
"/org/qtools/rofi/default_theme.rasi",
|
|
|
|
G_RESOURCE_LOOKUP_FLAGS_NONE,
|
|
|
|
NULL );
|
2017-10-31 13:00:24 -04:00
|
|
|
if ( theme_data ) {
|
|
|
|
const char *theme = g_bytes_get_data ( theme_data, NULL );
|
2017-11-07 14:04:07 -05:00
|
|
|
if ( rofi_theme_parse_string ( (const char *) theme ) ) {
|
2017-10-31 13:00:24 -04:00
|
|
|
g_warning ( "Failed to parse default theme. Giving up.." );
|
|
|
|
if ( list_of_error_msgs ) {
|
|
|
|
for ( GList *iter = g_list_first ( list_of_error_msgs );
|
2017-11-07 14:04:07 -05:00
|
|
|
iter != NULL; iter = g_list_next ( iter ) ) {
|
2017-10-31 13:00:24 -04:00
|
|
|
g_warning ( "Error: %s%s%s",
|
2017-11-07 14:04:07 -05:00
|
|
|
color_bold, ( (GString *) iter->data )->str, color_reset );
|
2017-10-31 13:00:24 -04:00
|
|
|
}
|
2017-04-02 06:32:11 -04:00
|
|
|
}
|
2017-10-31 13:00:24 -04:00
|
|
|
rofi_theme = NULL;
|
|
|
|
cleanup ();
|
|
|
|
return EXIT_FAILURE;
|
2017-04-02 06:32:11 -04:00
|
|
|
}
|
2017-10-31 13:00:24 -04:00
|
|
|
g_bytes_unref ( theme_data );
|
2017-03-29 14:18:41 -04:00
|
|
|
}
|
2017-06-07 01:53:33 -04:00
|
|
|
}
|
2017-06-07 14:41:43 -04:00
|
|
|
|
2017-06-07 01:53:33 -04:00
|
|
|
/**
|
|
|
|
* Make small commandline changes to the current theme.
|
|
|
|
*/
|
|
|
|
const char ** theme_str = find_arg_strv ( "-theme-str" );
|
|
|
|
if ( theme_str ) {
|
|
|
|
for ( int index = 0; theme_str && theme_str[index]; index++ ) {
|
|
|
|
if ( rofi_theme_parse_string ( theme_str[index] ) ) {
|
|
|
|
rofi_theme_free ( rofi_theme );
|
|
|
|
rofi_theme = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free ( theme_str );
|
2017-03-11 11:06:06 -05:00
|
|
|
}
|
2017-01-08 10:09:24 -05:00
|
|
|
|
2017-01-08 15:36:06 -05:00
|
|
|
if ( find_arg ( "-dump-theme" ) >= 0 ) {
|
2016-12-31 19:06:38 -05:00
|
|
|
rofi_theme_print ( rofi_theme );
|
2017-03-25 09:23:31 -04:00
|
|
|
cleanup ();
|
|
|
|
return EXIT_SUCCESS;
|
2016-12-31 19:06:38 -05:00
|
|
|
}
|
2017-06-21 02:19:47 -04:00
|
|
|
if ( find_arg ( "-dump-config" ) >= 0 ) {
|
2020-01-02 06:00:44 -05:00
|
|
|
config_parse_dump_config_rasi_format ( stdout, FALSE );
|
2017-06-21 02:19:47 -04:00
|
|
|
cleanup ();
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2015-01-12 13:14:46 -05:00
|
|
|
// Dump.
|
2015-10-15 16:33:44 -04:00
|
|
|
// catch help request
|
|
|
|
if ( find_arg ( "-h" ) >= 0 || find_arg ( "-help" ) >= 0 || find_arg ( "--help" ) >= 0 ) {
|
|
|
|
help ( argc, argv );
|
2017-03-25 09:23:31 -04:00
|
|
|
cleanup ();
|
|
|
|
return EXIT_SUCCESS;
|
2015-10-15 16:33:44 -04:00
|
|
|
}
|
2017-04-27 16:59:14 -04:00
|
|
|
|
|
|
|
unsigned int interval = 1;
|
|
|
|
if ( find_arg_uint ( "-record-screenshots", &interval ) ) {
|
|
|
|
g_timeout_add ( 1000 / (double) interval, record, NULL );
|
|
|
|
}
|
2020-05-12 04:34:04 -04:00
|
|
|
if ( find_arg ( "-benchmark-ui" ) >= 0 ) {
|
|
|
|
config.benchmark_ui = TRUE;
|
|
|
|
}
|
2016-02-19 13:50:48 -05:00
|
|
|
|
2016-02-10 13:40:19 -05:00
|
|
|
rofi_view_workers_initialize ();
|
2020-08-19 16:44:55 -04:00
|
|
|
TICK_N ( "Workers initialize" );
|
2018-06-09 13:13:57 -04:00
|
|
|
rofi_icon_fetcher_init ( );
|
2020-08-19 16:44:55 -04:00
|
|
|
TICK_N ( "Icon fetcher initialize" );
|
2015-02-01 14:15:21 -05:00
|
|
|
|
2017-06-01 05:50:44 -04:00
|
|
|
// Create pid file
|
|
|
|
int pfd = create_pid_file ( pidfile );
|
2020-08-19 16:44:55 -04:00
|
|
|
TICK_N ( "Pid file created" );
|
2017-06-01 05:50:44 -04:00
|
|
|
if ( pfd < 0 ) {
|
|
|
|
cleanup ();
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
textbox_setup ();
|
2020-08-19 16:44:55 -04:00
|
|
|
TICK_N ( "Text box setup" );
|
2017-06-01 05:50:44 -04:00
|
|
|
|
2017-06-01 08:55:17 -04:00
|
|
|
if ( !display_late_setup () ) {
|
2017-06-01 05:57:57 -04:00
|
|
|
g_warning ( "Failed to properly finish display setup" );
|
|
|
|
cleanup ();
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2017-06-01 06:03:23 -04:00
|
|
|
TICK_N ( "Setup late Display" );
|
2017-06-01 05:50:44 -04:00
|
|
|
|
2019-09-20 09:05:36 -04:00
|
|
|
rofi_theme_parse_process_conditionals ();
|
|
|
|
TICK_N ( "Theme setup" );
|
|
|
|
|
2016-01-22 12:18:26 -05:00
|
|
|
// Setup signal handling sources.
|
2016-01-26 02:36:44 -05:00
|
|
|
// SIGINT
|
2016-01-22 12:18:26 -05:00
|
|
|
g_unix_signal_add ( SIGINT, main_loop_signal_handler_int, NULL );
|
2014-11-05 04:52:10 -05:00
|
|
|
|
2016-02-19 13:29:06 -05:00
|
|
|
g_idle_add ( startup, NULL );
|
2014-01-23 14:33:13 -05:00
|
|
|
|
2016-01-22 12:18:26 -05:00
|
|
|
// Start mainloop.
|
|
|
|
g_main_loop_run ( main_loop );
|
2016-04-19 16:10:34 -04:00
|
|
|
teardown ( pfd );
|
2017-03-25 09:23:31 -04:00
|
|
|
cleanup ();
|
2017-07-13 02:21:15 -04:00
|
|
|
|
|
|
|
/* dirty hack */
|
|
|
|
g_free ( windowid );
|
2016-02-19 13:29:06 -05:00
|
|
|
return return_code;
|
2012-09-01 09:49:31 -04:00
|
|
|
}
|
2021-01-26 11:27:32 -05:00
|
|
|
|
|
|
|
/** List of error messages.*/
|
|
|
|
extern GList *list_of_error_msgs;
|
|
|
|
int rofi_theme_rasi_validate ( const char *filename )
|
|
|
|
{
|
|
|
|
rofi_theme_parse_file ( filename );
|
|
|
|
if ( list_of_error_msgs == NULL ) {
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( GList *iter = g_list_first ( list_of_error_msgs );
|
2021-06-01 04:44:23 -04:00
|
|
|
iter != NULL; iter = g_list_next ( iter ) ) {
|
|
|
|
fputs ( ( (GString *) iter->data )->str, stderr );
|
2021-01-26 11:27:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|