/*
* rofi
*
* MIT/X11 License
* Copyright © 2012 Sean Pringle <sean.pringle@gmail.com>
* Copyright © 2013-2017 Qball Cow <qball@gmpclient.org>
*
* 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:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* 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.
*
*/
#define G_LOG_DOMAIN "Rofi"
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <errno.h>
#include <time.h>
#include <locale.h>
#include <gmodule.h>
#include <xcb/xcb.h>
#include <sys/types.h>
#include <glib-unix.h>
#include <libgwater-xcb.h>
#include "display.h"
#include "settings.h"
#include "mode.h"
#include "rofi.h"
#include "helper.h"
#include "widgets/textbox.h"
#include "xrmoptions.h"
#include "dialogs/dialogs.h"
#include "view.h"
#include "view-internal.h"
#include "theme.h"
#include "timings.h"
#include "default-theme.h"
// Plugin abi version.
// TODO: move this check to mode.c
#include "mode-private.h"
// Pidfile.
char *pidfile = NULL;
const char *cache_dir = NULL;
/** List of error messages.*/
GList *list_of_error_msgs = NULL;
static void rofi_collect_modi_destroy ( void );
void rofi_add_error_message ( GString *str )
{
list_of_error_msgs = g_list_append ( list_of_error_msgs, str );
}
/** Path to the configuration file */
G_MODULE_EXPORT char *config_path = NULL;
G_MODULE_EXPORT char *config_path_new = NULL;
/** Array holding all activated modi. */
Mode **modi = NULL;
/** List of (possibly uninitialized) modi's */
Mode ** available_modi = NULL;
/** Length of #num_available_modi */
unsigned int num_available_modi = 0;
/** Number of activated modi in #modi array */
unsigned int num_modi = 0;
/** Current selected mode */
unsigned int curr_switcher = 0;
NkBindings *bindings = NULL;
/** Glib main loop. */
GMainLoop *main_loop = NULL;
/** Flag indicating we are in dmenu mode. */
static int dmenu_mode = FALSE;
/** Rofi's return code */
int return_code = EXIT_SUCCESS;
void process_result ( RofiViewState *state );
void rofi_set_return_code ( int code )
{
return_code = code;
}
unsigned int rofi_get_num_enabled_modi ( void )
{
return num_modi;
}
const Mode * rofi_get_mode ( unsigned int index )
{
return modi[index];
}
/**
* @param name Name of the switcher to lookup.
*
* Find the index of the switcher with name.
*
* @returns index of the switcher in modi, -1 if not found.
*/
static int switcher_get ( const char *name )
{
for ( unsigned int i = 0; i < num_modi; i++ ) {
if ( strcmp ( mode_get_name ( modi[i] ), name ) == 0 ) {
return i;
}
}
return -1;
}
/**
* Teardown the gui.
*/
static void teardown ( int pfd )
{
g_debug ( "Teardown" );
// Cleanup font setup.
textbox_cleanup ( );
display_early_cleanup ();
// Cleanup view
rofi_view_cleanup ();
// Cleanup pid file.
remove_pid_file ( pfd );
}
static void run_switcher ( ModeMode mode )
{
// Otherwise check if requested mode is enabled.
for ( unsigned int i = 0; i < num_modi; i++ ) {
if ( !mode_init ( modi[i] ) ) {
GString *str = g_string_new ( "Failed to initialize the mode: " );
g_string_append ( str, modi[i]->name );
g_string_append ( str, "\n" );
rofi_view_error_dialog ( str->str, ERROR_MSG_MARKUP );
g_string_free ( str, FALSE );
break;
}
}
// Error dialog must have been created.
if ( rofi_view_get_active () != NULL ) {
return;
}
curr_switcher = mode;
RofiViewState * state = rofi_view_create ( modi[mode], config.filter, MENU_PROMPT_COLON, process_result );
if ( state ) {
rofi_view_set_active ( state );
}
if ( rofi_view_get