2013-07-19 10:55:01 -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
|
|
|
|
* Copyright (c) 2012 Sean Pringle <sean.pringle@gmail.com>
|
2017-01-03 11:59:28 -05:00
|
|
|
* Modified 2013-2017 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.
|
|
|
|
*/
|
2015-11-14 07:47:45 -05:00
|
|
|
|
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>
|
|
|
|
#include <xcb/xcb_aux.h>
|
2016-02-27 11:42:50 -05:00
|
|
|
#include <xcb/xcb_ewmh.h>
|
2016-02-21 07:10:32 -05:00
|
|
|
#include <xcb/xkb.h>
|
2016-02-19 16:43:53 -05:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
2016-02-21 09:31:13 -05:00
|
|
|
#include <xkbcommon/xkbcommon-compose.h>
|
2016-02-21 07:10:32 -05:00
|
|
|
#include <xkbcommon/xkbcommon-x11.h>
|
2015-02-01 04:03:16 -05:00
|
|
|
#include <sys/types.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>
|
|
|
|
|
2016-03-01 12:11:55 -05:00
|
|
|
#include "xcb-internal.h"
|
|
|
|
#include "xkb-internal.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-02-14 13:42:04 -05:00
|
|
|
#include "rofi.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 "x11-helper.h"
|
|
|
|
#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-03-12 08:00:19 -05:00
|
|
|
#include "gitconfig.h"
|
|
|
|
|
2016-12-09 13:49:49 -05:00
|
|
|
#include "theme.h"
|
|
|
|
|
2017-02-14 02:52:17 -05:00
|
|
|
#include "timings.h"
|
|
|
|
|
2017-03-29 14:18:41 -04:00
|
|
|
#include "default-theme.h"
|
|
|
|
|
2017-02-14 12:12:07 -05:00
|
|
|
// Plugin abi version.
|
|
|
|
// TODO: move this check to mode.c
|
|
|
|
#include "mode-private.h"
|
|
|
|
|
2017-03-25 09:23:31 -04:00
|
|
|
#define LOG_DOMAIN "Rofi"
|
2017-03-21 14:46:56 -04:00
|
|
|
|
2015-02-03 02:00:33 -05:00
|
|
|
// Pidfile.
|
2016-10-26 02:24:34 -04:00
|
|
|
char *pidfile = NULL;
|
|
|
|
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 );
|
|
|
|
}
|
2016-10-25 16:45:11 -04:00
|
|
|
/** global structure holding the keyboard status */
|
2016-10-26 02:24:34 -04:00
|
|
|
struct xkb_stuff xkb = {
|
2016-03-02 12:07:59 -05:00
|
|
|
.xcb_connection = NULL,
|
|
|
|
.context = NULL,
|
|
|
|
.keymap = NULL,
|
|
|
|
.state = NULL,
|
|
|
|
.compose = {
|
2016-10-15 14:00:26 -04:00
|
|
|
.table = NULL,
|
|
|
|
.state = NULL
|
|
|
|
}
|
2016-03-02 12:07:59 -05:00
|
|
|
};
|
2016-10-25 16:45:11 -04:00
|
|
|
|
|
|
|
/** Path to the configuration file */
|
2016-10-26 02:24:34 -04:00
|
|
|
char *config_path = NULL;
|
2016-10-25 16:45:11 -04:00
|
|
|
/** Array holding all activated modi. */
|
2016-10-26 02:24:34 -04:00
|
|
|
Mode **modi = NULL;
|
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
|
|
|
|
2016-10-25 16:45:11 -04:00
|
|
|
/** Glib main loop. */
|
2016-10-26 02:24:34 -04:00
|
|
|
GMainLoop *main_loop = NULL;
|
2016-10-25 16:45:11 -04:00
|
|
|
/** GWater xcb source, signalling events from the X server */
|
2016-10-26 02:24:34 -04:00
|
|
|
GWaterXcbSource *main_loop_source = NULL;
|
2016-01-20 14:57:26 -05:00
|
|
|
|
2016-10-25 16:45:11 -04:00
|
|
|
/** Flag indicating we are in dmenu mode. */
|
2016-10-26 02:24:34 -04:00
|
|
|
static int dmenu_mode = FALSE;
|
2016-10-25 16:45:11 -04:00
|
|
|
/** Rofi's return code */
|
2016-10-26 02:24:34 -04:00
|
|
|
int return_code = EXIT_SUCCESS;
|
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-01-08 07:16:44 -05:00
|
|
|
/**
|
2015-07-30 02:57:09 -04:00
|
|
|
* Do needed steps to start showing the gui
|
2015-01-08 07:16:44 -05:00
|
|
|
*/
|
2015-07-30 02:57:09 -04:00
|
|
|
static int setup ()
|
2014-08-05 03:07:41 -04:00
|
|
|
{
|
2015-02-01 09:17:43 -05:00
|
|
|
// Create pid file
|
2015-07-30 02:57:09 -04:00
|
|
|
int pfd = create_pid_file ( pidfile );
|
|
|
|
if ( pfd >= 0 ) {
|
|
|
|
// Request truecolor visual.
|
2016-03-01 12:11:55 -05:00
|
|
|
x11_create_visual_and_colormap ( );
|
2016-02-21 13:42:32 -05:00
|
|
|
textbox_setup ();
|
2015-07-30 02:57:09 -04:00
|
|
|
}
|
|
|
|
return pfd;
|
|
|
|
}
|
2016-02-06 08:27:36 -05:00
|
|
|
|
2015-07-30 02:57:09 -04:00
|
|
|
/**
|
|
|
|
* Teardown the gui.
|
|
|
|
*/
|
|
|
|
static void teardown ( int pfd )
|
|
|
|
{
|
2017-03-25 09:23:31 -04:00
|
|
|
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Teardown" );
|
2014-08-05 03:07:41 -04:00
|
|
|
// Cleanup font setup.
|
2015-01-21 04:04:15 -05:00
|
|
|
textbox_cleanup ( );
|
|
|
|
|
2015-07-28 16:22:18 -04:00
|
|
|
// Release the window.
|
2016-03-01 12:11:55 -05:00
|
|
|
release_keyboard ( );
|
2016-05-09 02:47:28 -04:00
|
|
|
release_pointer ( );
|
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] ) ) {
|
2016-02-08 03:03:11 -05:00
|
|
|
rofi_view_error_dialog ( ERROR_MSG ( "Failed to initialize all the modi." ), ERROR_MSG_MARKUP );
|
2016-01-08 03:16:59 -05:00
|
|
|
return;
|
|
|
|
}
|
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-03-01 03:57:54 -05:00
|
|
|
RofiViewState * state = rofi_view_create ( modi[mode], config.filter, MENU_PROMPT_COLON, process_result );
|
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;
|
2016-04-19 16:10:34 -04: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 );
|
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] );
|
|
|
|
rofi_view_set_active ( state );
|
|
|
|
curr_switcher = mode;
|
|
|
|
return;
|
2016-02-19 13:29:06 -05:00
|
|
|
}
|
2014-07-21 15:39:24 -04:00
|
|
|
}
|
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
|
|
|
*/
|
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 ( "-dump-xresources", "", "Dump the current configuration in Xresources format and exit.", NULL, is_term );
|
2015-12-10 12:20:04 -05:00
|
|
|
print_help_msg ( "-dump-xresources-theme", "", "Dump the current color scheme in Xresources format and exit.", NULL, is_term );
|
2015-11-15 07:12:43 -05:00
|
|
|
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 );
|
|
|
|
print_help_msg ( "-normal-window", "", "In dmenu mode, 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 );
|
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" );
|
2016-08-19 04:46:38 -04:00
|
|
|
x11_dump_monitor_layout ();
|
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 TIMINGS
|
2017-01-08 15:36:06 -05:00
|
|
|
printf ( "\t* timings %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* timings %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 : "" );
|
|
|
|
printf ( " %s#rofi @ freenode.net%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
|
2016-12-06 13:24:17 -05:00
|
|
|
if ( find_arg ( "-no-config" ) < 0 ) {
|
2017-01-08 15:36:06 -05:00
|
|
|
printf ( " Configuration file: %s%s%s\n", is_term ? color_bold : "", config_path, is_term ? color_reset : "" );
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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 ) {
|
2016-02-06 07:06:58 -05:00
|
|
|
if ( main_loop_source ) {
|
2016-05-30 12:25:40 -04:00
|
|
|
g_water_xcb_source_free ( main_loop_source );
|
2016-01-27 17:49:56 -05:00
|
|
|
}
|
2016-01-22 12:18:26 -05:00
|
|
|
g_main_loop_unref ( main_loop );
|
|
|
|
main_loop = NULL;
|
|
|
|
}
|
2016-08-22 02:39:22 -04:00
|
|
|
// XKB Cleanup
|
|
|
|
//
|
|
|
|
if ( xkb.compose.state != NULL ) {
|
|
|
|
xkb_compose_state_unref ( xkb.compose.state );
|
|
|
|
xkb.compose.state = NULL;
|
|
|
|
}
|
|
|
|
if ( xkb.compose.table != NULL ) {
|
|
|
|
xkb_compose_table_unref ( xkb.compose.table );
|
|
|
|
xkb.compose.table = NULL;
|
|
|
|
}
|
|
|
|
if ( xkb.state != NULL ) {
|
|
|
|
xkb_state_unref ( xkb.state );
|
|
|
|
xkb.state = NULL;
|
|
|
|
}
|
|
|
|
if ( xkb.keymap != NULL ) {
|
|
|
|
xkb_keymap_unref ( xkb.keymap );
|
|
|
|
xkb.keymap = NULL;
|
|
|
|
}
|
|
|
|
if ( xkb.context != NULL ) {
|
|
|
|
xkb_context_unref ( xkb.context );
|
|
|
|
xkb.context = NULL;
|
|
|
|
}
|
|
|
|
|
2014-05-19 15:02:05 -04:00
|
|
|
// Cleanup
|
2016-03-01 12:33:26 -05:00
|
|
|
xcb_stuff_wipe ( xcb );
|
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
|
|
|
for ( unsigned int i = 0; i < num_modi; i++ ) {
|
2016-02-06 07:40:25 -05:00
|
|
|
mode_free ( &( modi[i] ) );
|
2014-07-21 15:39:24 -04:00
|
|
|
}
|
2015-11-25 03:26:38 -05:00
|
|
|
g_free ( modi );
|
2015-04-30 16:42:04 -04:00
|
|
|
|
|
|
|
// Cleanup the custom keybinding
|
|
|
|
cleanup_abe ();
|
2015-11-14 07:47:45 -05:00
|
|
|
|
2016-04-01 11:58:41 -04:00
|
|
|
g_free ( config_path );
|
|
|
|
|
2017-01-09 12:32:26 -05:00
|
|
|
if ( list_of_error_msgs ) {
|
|
|
|
for ( GList *iter = g_list_first ( list_of_error_msgs );
|
2017-01-09 16:40:11 -05:00
|
|
|
iter != NULL; iter = g_list_next ( iter ) ) {
|
|
|
|
g_string_free ( (GString *) iter->data, TRUE );
|
2017-01-09 12:32:26 -05:00
|
|
|
}
|
|
|
|
g_list_free ( list_of_error_msgs );
|
|
|
|
}
|
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 ( );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Collected modi
|
|
|
|
*/
|
2017-03-11 07:20:46 -05:00
|
|
|
/** List of (possibly uninitialized) modi's */
|
2017-03-17 09:07:11 -04:00
|
|
|
Mode ** available_modi = NULL;
|
2017-03-11 07:20:46 -05:00
|
|
|
/** Length of #num_available_modi */
|
2017-03-04 06:00:59 -05:00
|
|
|
unsigned int num_available_modi = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param name Search for mode with this name.
|
|
|
|
*
|
|
|
|
* @return returns Mode * when found, NULL if not.
|
|
|
|
*/
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2017-03-04 13:41:06 -05:00
|
|
|
char *fn = g_build_filename ( PLUGIN_PATH, dn, NULL );
|
|
|
|
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-03-04 13:41:06 -05:00
|
|
|
fprintf ( stderr, "ABI version of plugin does not match: %08X expecting: %08X\n", 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 {
|
|
|
|
fprintf ( stderr, "Symbol 'mode' not found in module: %s\n", fn );
|
2017-03-04 06:00:59 -05:00
|
|
|
g_module_close ( mod );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 );
|
|
|
|
|
|
|
|
rofi_collect_modi_dir ( PLUGIN_PATH );
|
|
|
|
}
|
|
|
|
|
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 ) {
|
|
|
|
g_module_close ( available_modi[i]->module );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
else {
|
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 ) {
|
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
|
|
|
}
|
|
|
|
else {
|
2016-02-04 03:20:10 -05:00
|
|
|
// Report error, don't continue.
|
|
|
|
fprintf ( stderr, "Invalid script switcher: %s\n", token );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ( index == num_modi ) ? -1 : (int) index;
|
|
|
|
}
|
2015-11-25 03:26:38 -05:00
|
|
|
static void setup_modi ( void )
|
2014-07-21 15:39:24 -04:00
|
|
|
{
|
2016-03-20 05:16:55 -04:00
|
|
|
const char *const sep = ",";
|
|
|
|
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 ) ) {
|
2016-02-04 03:20:10 -05:00
|
|
|
add_mode ( 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 );
|
2014-11-05 04:52:10 -05:00
|
|
|
}
|
|
|
|
|
2015-08-01 10:10:52 -04:00
|
|
|
/**
|
|
|
|
* Process X11 events in the main-loop (gui-thread) of the application.
|
|
|
|
*/
|
2017-01-08 15:36:06 -05:00
|
|
|
static void main_loop_x11_event_handler_view ( xcb_generic_event_t *ev )
|
|
|
|
{
|
2016-11-30 11:30:10 -05:00
|
|
|
RofiViewState *state = rofi_view_get_active ();
|
|
|
|
if ( state != NULL ) {
|
|
|
|
rofi_view_itterrate ( state, ev, &xkb );
|
|
|
|
if ( rofi_view_get_completed ( state ) ) {
|
|
|
|
// This menu is done.
|
|
|
|
rofi_view_finalize ( state );
|
|
|
|
// cleanup
|
|
|
|
if ( rofi_view_get_active () == NULL ) {
|
|
|
|
g_main_loop_quit ( main_loop );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-19 16:43:53 -05:00
|
|
|
static gboolean main_loop_x11_event_handler ( xcb_generic_event_t *ev, G_GNUC_UNUSED gpointer data )
|
2015-08-01 10:10:52 -04:00
|
|
|
{
|
2016-03-04 11:03:24 -05:00
|
|
|
if ( ev == NULL ) {
|
|
|
|
int status = xcb_connection_has_error ( xcb->connection );
|
|
|
|
fprintf ( stderr, "The XCB connection to X server had a fatal error: %d\n", status );
|
|
|
|
g_main_loop_quit ( main_loop );
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
2016-03-04 02:15:12 -05:00
|
|
|
uint8_t type = ev->response_type & ~0x80;
|
|
|
|
if ( type == xkb.first_event ) {
|
|
|
|
switch ( ev->pad0 )
|
|
|
|
{
|
|
|
|
case XCB_XKB_MAP_NOTIFY:
|
|
|
|
xkb_state_unref ( xkb.state );
|
|
|
|
xkb_keymap_unref ( xkb.keymap );
|
|
|
|
xkb.keymap = xkb_x11_keymap_new_from_device ( xkb.context, xcb->connection, xkb.device_id, 0 );
|
|
|
|
xkb.state = xkb_x11_state_new_from_device ( xkb.keymap, xcb->connection, xkb.device_id );
|
|
|
|
break;
|
|
|
|
case XCB_XKB_STATE_NOTIFY:
|
2016-10-15 14:00:26 -04:00
|
|
|
{
|
|
|
|
xcb_xkb_state_notify_event_t *ksne = (xcb_xkb_state_notify_event_t *) ev;
|
|
|
|
guint modmask;
|
|
|
|
xkb_state_update_mask ( xkb.state,
|
|
|
|
ksne->baseMods,
|
|
|
|
ksne->latchedMods,
|
|
|
|
ksne->lockedMods,
|
|
|
|
ksne->baseGroup,
|
|
|
|
ksne->latchedGroup,
|
|
|
|
ksne->lockedGroup );
|
|
|
|
modmask = x11_get_current_mask ( &xkb );
|
|
|
|
if ( modmask == 0 ) {
|
|
|
|
abe_trigger_release ( );
|
2016-11-30 11:30:10 -05:00
|
|
|
|
2016-11-30 10:35:34 -05:00
|
|
|
// Because of abe_trigger, state of rofi can be changed. handle this!
|
2016-11-30 11:30:10 -05:00
|
|
|
// Run mainloop on dummy event.
|
2016-12-15 03:17:39 -05:00
|
|
|
xcb_generic_event_t dev;
|
2016-11-30 11:30:10 -05:00
|
|
|
dev.response_type = 0;
|
|
|
|
main_loop_x11_event_handler_view ( &dev );
|
2016-04-07 14:28:40 -04:00
|
|
|
}
|
2016-10-15 14:00:26 -04:00
|
|
|
break;
|
|
|
|
}
|
2016-03-04 02:15:12 -05:00
|
|
|
}
|
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
2016-03-01 12:11:55 -05:00
|
|
|
if ( xcb->sndisplay != NULL ) {
|
|
|
|
sn_xcb_display_process_event ( xcb->sndisplay, ev );
|
2016-02-19 16:43:53 -05:00
|
|
|
}
|
2016-11-30 11:30:10 -05:00
|
|
|
main_loop_x11_event_handler_view ( ev );
|
2016-01-18 15:43:33 -05:00
|
|
|
return G_SOURCE_CONTINUE;
|
2015-08-01 10:10:52 -04:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-10-25 16:45:11 -04:00
|
|
|
/** X server error depth. to handle nested errors. */
|
2016-01-18 14:51:35 -05:00
|
|
|
static int error_trap_depth = 0;
|
2016-02-27 18:15:42 -05:00
|
|
|
static void error_trap_push ( G_GNUC_UNUSED SnDisplay *display, G_GNUC_UNUSED xcb_connection_t *xdisplay )
|
2016-01-18 14:51:35 -05:00
|
|
|
{
|
|
|
|
++error_trap_depth;
|
|
|
|
}
|
|
|
|
|
2016-02-27 18:15:42 -05:00
|
|
|
static void error_trap_pop ( G_GNUC_UNUSED SnDisplay *display, xcb_connection_t *xdisplay )
|
2015-09-13 11:29:50 -04:00
|
|
|
{
|
|
|
|
if ( error_trap_depth == 0 ) {
|
|
|
|
fprintf ( stderr, "Error trap underflow!\n" );
|
2015-11-14 13:52:15 -05:00
|
|
|
exit ( EXIT_FAILURE );
|
2015-09-13 11:29:50 -04:00
|
|
|
}
|
|
|
|
|
2016-02-28 09:32:53 -05:00
|
|
|
xcb_flush ( xdisplay );
|
2015-09-13 11:29:50 -04:00
|
|
|
--error_trap_depth;
|
|
|
|
}
|
2017-01-08 10:23:17 -05:00
|
|
|
/** Retry count of grabbing keyboard. */
|
2017-01-06 05:00:27 -05:00
|
|
|
unsigned int lazy_grab_retry_count_kb = 0;
|
2017-01-08 10:23:17 -05:00
|
|
|
/** Retry count of grabbing pointer. */
|
2017-01-06 05:00:27 -05:00
|
|
|
unsigned int lazy_grab_retry_count_pt = 0;
|
|
|
|
static gboolean lazy_grab_pointer ( G_GNUC_UNUSED gpointer data )
|
|
|
|
{
|
|
|
|
// After 5 sec.
|
2017-01-09 02:17:16 -05:00
|
|
|
if ( lazy_grab_retry_count_pt > ( 5 * 1000 ) ) {
|
|
|
|
fprintf ( stderr, "Failed to grab pointer after %u times. Giving up.\n", lazy_grab_retry_count_pt );
|
2017-01-06 05:00:27 -05:00
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
2017-01-08 15:36:06 -05:00
|
|
|
if ( take_pointer ( xcb_stuff_get_root_window ( xcb ), 0 ) ) {
|
2017-01-06 05:00:27 -05:00
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
2017-01-09 02:17:16 -05:00
|
|
|
lazy_grab_retry_count_pt++;
|
2017-01-06 05:00:27 -05:00
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
|
|
|
static gboolean lazy_grab_keyboard ( G_GNUC_UNUSED gpointer data )
|
|
|
|
{
|
|
|
|
// After 5 sec.
|
2017-01-09 02:17:16 -05:00
|
|
|
if ( lazy_grab_retry_count_kb > ( 5 * 1000 ) ) {
|
|
|
|
fprintf ( stderr, "Failed to grab keyboard after %u times. Giving up.\n", lazy_grab_retry_count_kb );
|
|
|
|
g_main_loop_quit ( main_loop );
|
2017-01-06 05:00:27 -05:00
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
2017-01-08 15:36:06 -05:00
|
|
|
if ( take_keyboard ( xcb_stuff_get_root_window ( xcb ), 0 ) ) {
|
2017-01-06 05:00:27 -05:00
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
2017-01-09 02:32:16 -05:00
|
|
|
lazy_grab_retry_count_kb++;
|
2017-01-06 05:00:27 -05:00
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create window (without showing)
|
|
|
|
*/
|
2016-11-06 10:50:12 -05:00
|
|
|
// Try to grab the keyboard as early as possible.
|
|
|
|
// We grab this using the rootwindow (as dmenu does it).
|
|
|
|
// this seems to result in the smallest delay for most people.
|
|
|
|
if ( ( window_flags & MENU_NORMAL_WINDOW ) == 0 ) {
|
2017-02-02 13:00:45 -05:00
|
|
|
if ( find_arg ( "-no-lazy-grab" ) >= 0 ) {
|
2017-01-08 15:36:06 -05:00
|
|
|
if ( !take_keyboard ( xcb_stuff_get_root_window ( xcb ), 500 ) ) {
|
2017-01-07 04:35:36 -05:00
|
|
|
fprintf ( stderr, "Failed to grab keyboard, even after %d uS.", 500 * 1000 );
|
|
|
|
g_main_loop_quit ( main_loop );
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
2017-01-08 15:36:06 -05:00
|
|
|
if ( !take_pointer ( xcb_stuff_get_root_window ( xcb ), 100 ) ) {
|
|
|
|
fprintf ( stderr, "Failed to grab mouse pointer, even after %d uS.", 100 * 1000 );
|
2017-01-07 04:35:36 -05:00
|
|
|
}
|
2016-11-06 10:50:12 -05:00
|
|
|
}
|
2017-02-02 13:00:45 -05:00
|
|
|
else {
|
|
|
|
if ( !take_keyboard ( xcb_stuff_get_root_window ( xcb ), 0 ) ) {
|
|
|
|
g_timeout_add ( 1, lazy_grab_keyboard, NULL );
|
|
|
|
}
|
|
|
|
if ( !take_pointer ( xcb_stuff_get_root_window ( xcb ), 0 ) ) {
|
|
|
|
g_timeout_add ( 1, lazy_grab_pointer, NULL );
|
|
|
|
}
|
|
|
|
}
|
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.
|
2016-03-05 05:08:32 -05:00
|
|
|
if ( !parse_keys_abe () ) {
|
|
|
|
// Error dialog
|
2016-02-19 13:50:48 -05:00
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
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 ) {
|
2017-01-09 16:40:11 -05:00
|
|
|
GString *emesg = g_string_new ( "The following errors where 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" );
|
2017-01-09 12:32:26 -05:00
|
|
|
g_string_append ( emesg, msg->str );
|
2017-01-09 16:40:11 -05:00
|
|
|
index++;
|
2017-01-09 12:32:26 -05:00
|
|
|
}
|
2017-01-09 16:40:11 -05:00
|
|
|
if ( g_list_length ( iter ) > 1 ) {
|
|
|
|
g_string_append_printf ( emesg, "\nThere are <b>%d</b> more errors.", g_list_length ( iter ) - 1 );
|
2017-01-09 16:29:31 -05:00
|
|
|
}
|
2017-01-09 12:32:26 -05:00
|
|
|
rofi_view_error_dialog ( emesg->str, ERROR_MSG_MARKUP );
|
|
|
|
g_string_free ( emesg, TRUE );
|
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 ) {
|
|
|
|
fprintf ( stdout, "Mode %s not enabled. Please add it to the list of enabled modi: %s\n",
|
|
|
|
sname, config.modi );
|
|
|
|
fprintf ( stdout, "Adding mode: %s\n", sname );
|
|
|
|
}
|
|
|
|
// Run it anyway if found.
|
|
|
|
}
|
|
|
|
if ( index >= 0 ) {
|
|
|
|
run_switcher ( index );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf ( stderr, "The %s switcher has not been enabled\n", sname );
|
2016-06-07 03:58:48 -04:00
|
|
|
g_main_loop_quit ( main_loop );
|
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{
|
2016-02-21 16:03:13 -05:00
|
|
|
// Daemon mode
|
|
|
|
fprintf ( stderr, "Rofi daemon mode is now removed.\n" );
|
|
|
|
fprintf ( stderr, "Please use your window manager binding functionality or xbindkeys to replace it.\n" );
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
2016-04-05 10:56:06 -04:00
|
|
|
fprintf ( stdout, "Version: "GIT_VERSION "\n" );
|
|
|
|
#else
|
|
|
|
fprintf ( stdout, "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
|
|
|
}
|
|
|
|
|
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 ();
|
2014-05-20 05:41:39 -04:00
|
|
|
// Get the path to the cache dir.
|
2014-08-09 05:44:06 -04:00
|
|
|
cache_dir = g_get_user_cache_dir ();
|
2014-02-02 04:54:01 -05:00
|
|
|
|
2016-11-12 05:28:40 -05:00
|
|
|
if ( g_mkdir_with_parents ( cache_dir, 0700 ) < 0 ) {
|
|
|
|
fprintf ( stderr, "Failed to create cache directory: %s\n", strerror ( errno ) );
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
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-03-25 16:52:51 -04:00
|
|
|
g_log ( LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Failed to create user runtime directory: %s with error: %s\n", path, strerror ( errno ) );
|
|
|
|
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
|
|
|
|
2016-04-01 11:58:41 -04:00
|
|
|
if ( find_arg ( "-config" ) < 0 ) {
|
|
|
|
const char *cpath = g_get_user_config_dir ();
|
|
|
|
if ( cpath ) {
|
|
|
|
config_path = g_build_filename ( cpath, "rofi", "config", NULL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
char *c = NULL;
|
|
|
|
find_arg_str ( "-config", &c );
|
|
|
|
config_path = rofi_expand_path ( c );
|
|
|
|
}
|
|
|
|
|
2015-11-24 16:53:40 -05:00
|
|
|
TICK ();
|
2015-11-22 15:10:39 -05:00
|
|
|
if ( setlocale ( LC_ALL, "" ) == NULL ) {
|
|
|
|
fprintf ( stderr, "Failed to set locale.\n" );
|
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-02-09 02:45:15 -05:00
|
|
|
// Get DISPLAY, first env, then argument.
|
|
|
|
// We never modify display_str content.
|
2017-03-04 13:41:06 -05:00
|
|
|
char *display_str = ( char *) g_getenv ( "DISPLAY" );
|
2017-02-09 02:45:15 -05:00
|
|
|
find_arg_str ( "-display", &display_str );
|
|
|
|
|
2016-03-01 12:11:55 -05:00
|
|
|
xcb->connection = xcb_connect ( display_str, &xcb->screen_nbr );
|
2016-03-03 09:59:31 -05:00
|
|
|
if ( xcb_connection_has_error ( xcb->connection ) ) {
|
|
|
|
fprintf ( stderr, "Failed to open display: %s", display_str );
|
2017-03-25 09:23:31 -04:00
|
|
|
cleanup ();
|
2016-03-03 09:59:31 -05:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2017-03-04 06:00:59 -05:00
|
|
|
|
2015-11-24 16:53:40 -05:00
|
|
|
TICK_N ( "Open Display" );
|
2017-03-04 06:00:59 -05:00
|
|
|
rofi_collect_modi ();
|
2017-03-28 11:03:46 -04:00
|
|
|
rofi_collect_modi_setup ();
|
2017-03-04 06:00:59 -05:00
|
|
|
TICK_N ( "Collect MODI" );
|
2016-01-22 12:18:26 -05:00
|
|
|
|
2016-03-01 12:11:55 -05:00
|
|
|
xcb->screen = xcb_aux_get_screen ( xcb->connection, xcb->screen_nbr );
|
2016-02-19 16:43:53 -05:00
|
|
|
|
2016-08-19 04:46:38 -04:00
|
|
|
x11_build_monitor_layout ();
|
|
|
|
|
2016-03-04 02:02:54 -05:00
|
|
|
xcb_intern_atom_cookie_t *ac = xcb_ewmh_init_atoms ( xcb->connection, &xcb->ewmh );
|
2016-03-03 10:02:14 -05:00
|
|
|
xcb_generic_error_t *errors = NULL;
|
|
|
|
xcb_ewmh_init_atoms_replies ( &xcb->ewmh, ac, &errors );
|
2016-02-28 09:32:53 -05:00
|
|
|
if ( errors ) {
|
|
|
|
fprintf ( stderr, "Failed to create EWMH atoms\n" );
|
2016-03-04 02:02:54 -05:00
|
|
|
free ( errors );
|
2016-02-27 11:42:50 -05:00
|
|
|
}
|
2017-02-11 10:53:37 -05:00
|
|
|
// Discover the current active window manager.
|
2017-03-04 13:41:06 -05:00
|
|
|
x11_helper_discover_window_manager ();
|
2017-02-01 02:47:43 -05:00
|
|
|
TICK_N ( "Setup XCB" );
|
2016-02-27 11:42:50 -05:00
|
|
|
|
2016-03-01 12:11:55 -05:00
|
|
|
if ( xkb_x11_setup_xkb_extension ( xcb->connection, XKB_X11_MIN_MAJOR_XKB_VERSION, XKB_X11_MIN_MINOR_XKB_VERSION,
|
2016-02-21 07:10:32 -05:00
|
|
|
XKB_X11_SETUP_XKB_EXTENSION_NO_FLAGS, NULL, NULL, &xkb.first_event, NULL ) < 0 ) {
|
|
|
|
fprintf ( stderr, "cannot setup XKB extension!\n" );
|
2017-03-25 09:23:31 -04:00
|
|
|
cleanup ();
|
2016-02-21 07:10:32 -05:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
xkb.context = xkb_context_new ( XKB_CONTEXT_NO_FLAGS );
|
|
|
|
if ( xkb.context == NULL ) {
|
|
|
|
fprintf ( stderr, "cannot create XKB context!\n" );
|
2017-03-25 09:23:31 -04:00
|
|
|
cleanup ();
|
2016-02-21 07:10:32 -05:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2016-03-01 12:11:55 -05:00
|
|
|
xkb.xcb_connection = xcb->connection;
|
2016-02-21 07:10:32 -05:00
|
|
|
|
2016-03-01 12:11:55 -05:00
|
|
|
xkb.device_id = xkb_x11_get_core_keyboard_device_id ( xcb->connection );
|
2016-02-21 07:10:32 -05:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
required_events =
|
|
|
|
( XCB_XKB_EVENT_TYPE_NEW_KEYBOARD_NOTIFY |
|
|
|
|
XCB_XKB_EVENT_TYPE_MAP_NOTIFY |
|
|
|
|
XCB_XKB_EVENT_TYPE_STATE_NOTIFY ),
|
|
|
|
|
|
|
|
required_nkn_details =
|
|
|
|
( XCB_XKB_NKN_DETAIL_KEYCODES ),
|
|
|
|
|
|
|
|
required_map_parts =
|
|
|
|
( XCB_XKB_MAP_PART_KEY_TYPES |
|
|
|
|
XCB_XKB_MAP_PART_KEY_SYMS |
|
|
|
|
XCB_XKB_MAP_PART_MODIFIER_MAP |
|
|
|
|
XCB_XKB_MAP_PART_EXPLICIT_COMPONENTS |
|
|
|
|
XCB_XKB_MAP_PART_KEY_ACTIONS |
|
|
|
|
XCB_XKB_MAP_PART_VIRTUAL_MODS |
|
|
|
|
XCB_XKB_MAP_PART_VIRTUAL_MOD_MAP ),
|
|
|
|
|
|
|
|
required_state_details =
|
|
|
|
( XCB_XKB_STATE_PART_MODIFIER_BASE |
|
|
|
|
XCB_XKB_STATE_PART_MODIFIER_LATCH |
|
|
|
|
XCB_XKB_STATE_PART_MODIFIER_LOCK |
|
|
|
|
XCB_XKB_STATE_PART_GROUP_BASE |
|
|
|
|
XCB_XKB_STATE_PART_GROUP_LATCH |
|
|
|
|
XCB_XKB_STATE_PART_GROUP_LOCK ),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const xcb_xkb_select_events_details_t details = {
|
|
|
|
.affectNewKeyboard = required_nkn_details,
|
|
|
|
.newKeyboardDetails = required_nkn_details,
|
|
|
|
.affectState = required_state_details,
|
|
|
|
.stateDetails = required_state_details,
|
|
|
|
};
|
2016-03-01 12:11:55 -05:00
|
|
|
xcb_xkb_select_events ( xcb->connection, xkb.device_id, required_events, /* affectWhich */
|
2016-03-01 13:48:18 -05:00
|
|
|
0, /* clear */
|
2016-03-04 02:02:54 -05:00
|
|
|
required_events, /* selectAll */
|
2016-03-01 13:48:18 -05:00
|
|
|
required_map_parts, /* affectMap */
|
|
|
|
required_map_parts, /* map */
|
2016-02-21 07:10:32 -05:00
|
|
|
&details );
|
|
|
|
|
2016-03-01 12:11:55 -05:00
|
|
|
xkb.keymap = xkb_x11_keymap_new_from_device ( xkb.context, xcb->connection, xkb.device_id, XKB_KEYMAP_COMPILE_NO_FLAGS );
|
2016-03-04 02:15:12 -05:00
|
|
|
if ( xkb.keymap == NULL ) {
|
|
|
|
fprintf ( stderr, "Failed to get Keymap for current keyboard device.\n" );
|
2017-03-25 09:23:31 -04:00
|
|
|
cleanup ();
|
2016-03-04 02:15:12 -05:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
xkb.state = xkb_x11_state_new_from_device ( xkb.keymap, xcb->connection, xkb.device_id );
|
|
|
|
if ( xkb.state == NULL ) {
|
|
|
|
fprintf ( stderr, "Failed to get state object for current keyboard device.\n" );
|
2017-03-25 09:23:31 -04:00
|
|
|
cleanup ();
|
2016-03-04 02:15:12 -05:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2016-02-21 07:10:32 -05:00
|
|
|
|
2016-02-21 09:31:13 -05:00
|
|
|
xkb.compose.table = xkb_compose_table_new_from_locale ( xkb.context, setlocale ( LC_CTYPE, NULL ), 0 );
|
2016-03-04 02:02:54 -05:00
|
|
|
if ( xkb.compose.table != NULL ) {
|
|
|
|
xkb.compose.state = xkb_compose_state_new ( xkb.compose.table, 0 );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf ( stderr, "Failed to get keyboard compose table. Trying to limp on.\n" );
|
2016-03-03 18:22:04 -05:00
|
|
|
}
|
2016-02-21 09:31:13 -05:00
|
|
|
|
2016-03-04 11:03:24 -05:00
|
|
|
if ( xcb_connection_has_error ( xcb->connection ) ) {
|
|
|
|
fprintf ( stderr, "Connection has error\n" );
|
2017-03-25 09:23:31 -04:00
|
|
|
cleanup ();
|
|
|
|
return EXIT_FAILURE;
|
2016-03-04 11:03:24 -05:00
|
|
|
}
|
2016-03-01 12:11:55 -05:00
|
|
|
x11_setup ( &xkb );
|
2017-02-01 02:47:43 -05:00
|
|
|
TICK_N ( "Setup xkb" );
|
2016-03-04 11:03:24 -05:00
|
|
|
if ( xcb_connection_has_error ( xcb->connection ) ) {
|
|
|
|
fprintf ( stderr, "Connection has error\n" );
|
2017-03-25 09:23:31 -04:00
|
|
|
cleanup ();
|
|
|
|
return EXIT_FAILURE;
|
2016-03-04 11:03:24 -05:00
|
|
|
}
|
2016-01-22 12:18:26 -05:00
|
|
|
main_loop = g_main_loop_new ( NULL, FALSE );
|
|
|
|
|
|
|
|
TICK_N ( "Setup mainloop" );
|
2015-09-13 11:29:50 -04:00
|
|
|
// startup not.
|
2016-03-01 12:11:55 -05:00
|
|
|
xcb->sndisplay = sn_xcb_display_new ( xcb->connection, error_trap_push, error_trap_pop );
|
2016-03-04 11:03:24 -05:00
|
|
|
if ( xcb_connection_has_error ( xcb->connection ) ) {
|
|
|
|
fprintf ( stderr, "Connection has error\n" );
|
2017-03-25 09:23:31 -04:00
|
|
|
cleanup ();
|
|
|
|
return EXIT_FAILURE;
|
2016-03-04 11:03:24 -05:00
|
|
|
}
|
2015-09-13 11:29:50 -04:00
|
|
|
|
2016-03-01 12:11:55 -05:00
|
|
|
if ( xcb->sndisplay != NULL ) {
|
|
|
|
xcb->sncontext = sn_launchee_context_new_from_environment ( xcb->sndisplay, xcb->screen_nbr );
|
2015-09-13 11:29:50 -04:00
|
|
|
}
|
2016-03-04 11:03:24 -05:00
|
|
|
if ( xcb_connection_has_error ( xcb->connection ) ) {
|
|
|
|
fprintf ( stderr, "Connection has error\n" );
|
2017-03-25 09:23:31 -04:00
|
|
|
cleanup ();
|
|
|
|
return EXIT_FAILURE;
|
2016-03-04 11:03:24 -05:00
|
|
|
}
|
2015-11-24 16:53:40 -05:00
|
|
|
TICK_N ( "Startup Notification" );
|
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 ) {
|
2017-03-28 11:03:46 -04:00
|
|
|
// Load distro default settings
|
|
|
|
gchar *etc = g_build_filename ( SYSCONFDIR, "rofi.conf", NULL );
|
|
|
|
if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) {
|
|
|
|
config_parse_xresource_options_file ( etc );
|
|
|
|
}
|
|
|
|
g_free ( etc );
|
|
|
|
// Load in config from X resources.
|
|
|
|
config_parse_xresource_options ( xcb );
|
|
|
|
config_parse_xresource_options_file ( config_path );
|
|
|
|
|
2017-03-28 14:04:02 -04:00
|
|
|
find_arg_str ( "-theme", &( config.theme ) );
|
2017-03-28 11:03:46 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2015-02-17 04:31:59 -05:00
|
|
|
if ( !dmenu_mode ) {
|
2015-11-25 03:26:38 -05:00
|
|
|
// setup_modi
|
|
|
|
setup_modi ();
|
2017-03-06 03:56:02 -05:00
|
|
|
TICK_N ( "Setup Modi" );
|
2015-02-17 04:31:59 -05:00
|
|
|
}
|
2016-04-02 04:39:02 -04:00
|
|
|
|
2017-01-08 10:09:24 -05:00
|
|
|
const char ** theme_str = find_arg_strv ( "-theme-str" );
|
|
|
|
if ( theme_str ) {
|
2017-01-08 15:36:06 -05:00
|
|
|
for ( int index = 0; theme_str && theme_str[index]; index++ ) {
|
2017-01-09 17:01:09 -05:00
|
|
|
if ( rofi_theme_parse_string ( theme_str[index] ) ) {
|
|
|
|
rofi_theme_free ( rofi_theme );
|
|
|
|
rofi_theme = NULL;
|
2017-01-08 10:09:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free ( theme_str );
|
|
|
|
}
|
2017-03-11 11:06:06 -05:00
|
|
|
if ( rofi_theme_is_empty ( ) ) {
|
2017-03-29 14:18:41 -04:00
|
|
|
if ( rofi_theme_parse_string ( default_theme ) ){
|
|
|
|
fprintf(stderr, "Failed to parse default theme. Giving up..\n");
|
|
|
|
rofi_theme = NULL;
|
|
|
|
cleanup ();
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
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
|
|
|
}
|
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
|
|
|
}
|
2015-03-11 13:32:37 -04:00
|
|
|
if ( find_arg ( "-dump-xresources" ) >= 0 ) {
|
2016-01-07 07:32:33 -05:00
|
|
|
config_parse_xresource_dump ();
|
2017-03-25 09:23:31 -04:00
|
|
|
cleanup ();
|
|
|
|
return EXIT_SUCCESS;
|
2015-01-12 13:14:46 -05:00
|
|
|
}
|
2015-12-10 12:20:04 -05:00
|
|
|
if ( find_arg ( "-dump-xresources-theme" ) >= 0 ) {
|
2016-01-07 07:32:33 -05:00
|
|
|
config_parse_xresources_theme_dump ();
|
2017-03-25 09:23:31 -04:00
|
|
|
cleanup ();
|
|
|
|
return EXIT_SUCCESS;
|
2015-12-10 12:20:04 -05:00
|
|
|
}
|
2016-02-19 13:50:48 -05:00
|
|
|
|
2016-03-01 12:11:55 -05:00
|
|
|
main_loop_source = g_water_xcb_source_new_for_connection ( NULL, xcb->connection, main_loop_x11_event_handler, NULL, NULL );
|
2016-02-19 13:50:48 -05:00
|
|
|
|
|
|
|
TICK_N ( "X11 Setup " );
|
2014-08-27 13:44:15 -04:00
|
|
|
|
2016-02-10 13:40:19 -05:00
|
|
|
rofi_view_workers_initialize ();
|
2015-02-01 14:15:21 -05:00
|
|
|
|
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-04-19 16:10:34 -04:00
|
|
|
// Pidfile + visuals
|
|
|
|
int pfd = setup ();
|
|
|
|
if ( pfd < 0 ) {
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
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 ();
|
2016-02-19 13:29:06 -05:00
|
|
|
return return_code;
|
2012-09-01 09:49:31 -04:00
|
|
|
}
|