mirror of
https://github.com/davatorium/rofi.git
synced 2025-07-31 21:59:25 -04:00
[Cleanup] clang-tidy rofi.c
This commit is contained in:
parent
1a1dc7282f
commit
24ce72c98a
1 changed files with 832 additions and 855 deletions
393
source/rofi.c
393
source/rofi.c
|
@ -30,18 +30,17 @@
|
||||||
#define G_LOG_DOMAIN "Rofi"
|
#define G_LOG_DOMAIN "Rofi"
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <stdio.h>
|
#include <errno.h>
|
||||||
|
#include <gmodule.h>
|
||||||
|
#include <locale.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.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 <sys/types.h>
|
||||||
#include <sysexits.h>
|
#include <sysexits.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <xcb/xcb.h>
|
||||||
|
|
||||||
#include <glib-unix.h>
|
#include <glib-unix.h>
|
||||||
|
|
||||||
|
@ -56,21 +55,21 @@
|
||||||
|
|
||||||
#include "resources.h"
|
#include "resources.h"
|
||||||
|
|
||||||
#include "rofi.h"
|
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
#include "rofi.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "mode.h"
|
|
||||||
|
#include "dialogs/dialogs.h"
|
||||||
#include "helper.h"
|
#include "helper.h"
|
||||||
|
#include "mode.h"
|
||||||
#include "widgets/textbox.h"
|
#include "widgets/textbox.h"
|
||||||
#include "xrmoptions.h"
|
#include "xrmoptions.h"
|
||||||
#include "dialogs/dialogs.h"
|
|
||||||
|
|
||||||
#include "view.h"
|
|
||||||
#include "view-internal.h"
|
#include "view-internal.h"
|
||||||
|
#include "view.h"
|
||||||
|
|
||||||
#include "theme.h"
|
|
||||||
#include "rofi-icon-fetcher.h"
|
#include "rofi-icon-fetcher.h"
|
||||||
|
#include "theme.h"
|
||||||
|
|
||||||
#include "timings.h"
|
#include "timings.h"
|
||||||
|
|
||||||
|
@ -87,15 +86,13 @@ const char *cache_dir = NULL;
|
||||||
GList *list_of_error_msgs = NULL;
|
GList *list_of_error_msgs = NULL;
|
||||||
|
|
||||||
static void rofi_collect_modi_destroy(void);
|
static void rofi_collect_modi_destroy(void);
|
||||||
void rofi_add_error_message ( GString *str )
|
void rofi_add_error_message(GString *str) {
|
||||||
{
|
|
||||||
list_of_error_msgs = g_list_append(list_of_error_msgs, str);
|
list_of_error_msgs = g_list_append(list_of_error_msgs, str);
|
||||||
}
|
}
|
||||||
void rofi_clear_error_messages ( void )
|
void rofi_clear_error_messages(void) {
|
||||||
{
|
|
||||||
if (list_of_error_msgs) {
|
if (list_of_error_msgs) {
|
||||||
for ( GList *iter = g_list_first ( list_of_error_msgs );
|
for (GList *iter = g_list_first(list_of_error_msgs); iter != NULL;
|
||||||
iter != NULL; iter = g_list_next ( iter ) ) {
|
iter = g_list_next(iter)) {
|
||||||
g_string_free((GString *)iter->data, TRUE);
|
g_string_free((GString *)iter->data, TRUE);
|
||||||
}
|
}
|
||||||
g_list_free(list_of_error_msgs);
|
g_list_free(list_of_error_msgs);
|
||||||
|
@ -131,20 +128,11 @@ int return_code = EXIT_SUCCESS;
|
||||||
|
|
||||||
void process_result(RofiViewState *state);
|
void process_result(RofiViewState *state);
|
||||||
|
|
||||||
void rofi_set_return_code ( int code )
|
void rofi_set_return_code(int code) { return_code = code; }
|
||||||
{
|
|
||||||
return_code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int rofi_get_num_enabled_modi ( void )
|
unsigned int rofi_get_num_enabled_modi(void) { return num_modi; }
|
||||||
{
|
|
||||||
return num_modi;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Mode * rofi_get_mode ( unsigned int index )
|
const Mode *rofi_get_mode(unsigned int index) { return modi[index]; }
|
||||||
{
|
|
||||||
return modi[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name Name of the switcher to lookup.
|
* @param name Name of the switcher to lookup.
|
||||||
|
@ -153,8 +141,7 @@ const Mode * rofi_get_mode ( unsigned int index )
|
||||||
*
|
*
|
||||||
* @returns index of the switcher in modi, -1 if not found.
|
* @returns index of the switcher in modi, -1 if not found.
|
||||||
*/
|
*/
|
||||||
static int switcher_get ( const char *name )
|
static int switcher_get(const char *name) {
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < num_modi; i++) {
|
for (unsigned int i = 0; i < num_modi; i++) {
|
||||||
if (strcmp(mode_get_name(modi[i]), name) == 0) {
|
if (strcmp(mode_get_name(modi[i]), name) == 0) {
|
||||||
return i;
|
return i;
|
||||||
|
@ -166,8 +153,7 @@ static int switcher_get ( const char *name )
|
||||||
/**
|
/**
|
||||||
* Teardown the gui.
|
* Teardown the gui.
|
||||||
*/
|
*/
|
||||||
static void teardown ( int pfd )
|
static void teardown(int pfd) {
|
||||||
{
|
|
||||||
g_debug("Teardown");
|
g_debug("Teardown");
|
||||||
// Cleanup font setup.
|
// Cleanup font setup.
|
||||||
textbox_cleanup();
|
textbox_cleanup();
|
||||||
|
@ -179,8 +165,7 @@ static void teardown ( int pfd )
|
||||||
// Cleanup pid file.
|
// Cleanup pid file.
|
||||||
remove_pid_file(pfd);
|
remove_pid_file(pfd);
|
||||||
}
|
}
|
||||||
static void run_switcher ( ModeMode mode )
|
static void run_switcher(ModeMode mode) {
|
||||||
{
|
|
||||||
// Otherwise check if requested mode is enabled.
|
// Otherwise check if requested mode is enabled.
|
||||||
for (unsigned int i = 0; i < num_modi; i++) {
|
for (unsigned int i = 0; i < num_modi; i++) {
|
||||||
if (!mode_init(modi[i])) {
|
if (!mode_init(modi[i])) {
|
||||||
|
@ -198,7 +183,8 @@ static void run_switcher ( ModeMode mode )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
curr_switcher = mode;
|
curr_switcher = mode;
|
||||||
RofiViewState * state = rofi_view_create ( modi[mode], config.filter, 0, process_result );
|
RofiViewState *state =
|
||||||
|
rofi_view_create(modi[mode], config.filter, 0, process_result);
|
||||||
|
|
||||||
// User can pre-select a row.
|
// User can pre-select a row.
|
||||||
if (find_arg("-selected-row") >= 0) {
|
if (find_arg("-selected-row") >= 0) {
|
||||||
|
@ -213,12 +199,12 @@ static void run_switcher ( ModeMode mode )
|
||||||
g_main_loop_quit(main_loop);
|
g_main_loop_quit(main_loop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void process_result ( RofiViewState *state )
|
void process_result(RofiViewState *state) {
|
||||||
{
|
|
||||||
Mode *sw = state->sw;
|
Mode *sw = state->sw;
|
||||||
// rofi_view_set_active ( NULL );
|
// rofi_view_set_active ( NULL );
|
||||||
if (sw != NULL) {
|
if (sw != NULL) {
|
||||||
unsigned int selected_line = rofi_view_get_selected_line ( state );;
|
unsigned int selected_line = rofi_view_get_selected_line(state);
|
||||||
|
;
|
||||||
MenuReturn mretv = rofi_view_get_return_value(state);
|
MenuReturn mretv = rofi_view_get_return_value(state);
|
||||||
char *input = g_strdup(rofi_view_get_user_input(state));
|
char *input = g_strdup(rofi_view_get_user_input(state));
|
||||||
ModeMode retv = mode_result(sw, mretv, &input, selected_line);
|
ModeMode retv = mode_result(sw, mretv, &input, selected_line);
|
||||||
|
@ -238,25 +224,19 @@ void process_result ( RofiViewState *state )
|
||||||
// Find next enabled
|
// Find next enabled
|
||||||
if (retv == NEXT_DIALOG) {
|
if (retv == NEXT_DIALOG) {
|
||||||
mode = (mode + 1) % num_modi;
|
mode = (mode + 1) % num_modi;
|
||||||
}
|
} else if (retv == PREVIOUS_DIALOG) {
|
||||||
else if ( retv == PREVIOUS_DIALOG ) {
|
|
||||||
if (mode == 0) {
|
if (mode == 0) {
|
||||||
mode = num_modi - 1;
|
mode = num_modi - 1;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
mode = (mode - 1) % num_modi;
|
mode = (mode - 1) % num_modi;
|
||||||
}
|
}
|
||||||
}
|
} else if (retv == RELOAD_DIALOG) {
|
||||||
else if ( retv == RELOAD_DIALOG ) {
|
|
||||||
// do nothing.
|
// do nothing.
|
||||||
}
|
} else if (retv == RESET_DIALOG) {
|
||||||
else if ( retv == RESET_DIALOG ) {
|
|
||||||
rofi_view_clear_input(state);
|
rofi_view_clear_input(state);
|
||||||
}
|
} else if (retv < MODE_EXIT) {
|
||||||
else if ( retv < MODE_EXIT ) {
|
|
||||||
mode = (retv) % num_modi;
|
mode = (retv) % num_modi;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
mode = retv;
|
mode = retv;
|
||||||
}
|
}
|
||||||
if (mode != MODE_EXIT) {
|
if (mode != MODE_EXIT) {
|
||||||
|
@ -267,13 +247,11 @@ void process_result ( RofiViewState *state )
|
||||||
curr_switcher = mode;
|
curr_switcher = mode;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// On exit, free current view, and pop to one above.
|
// On exit, free current view, and pop to one above.
|
||||||
rofi_view_remove_active(state);
|
rofi_view_remove_active(state);
|
||||||
rofi_view_free(state);
|
rofi_view_free(state);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// rofi_view_set_active ( NULL );
|
// rofi_view_set_active ( NULL );
|
||||||
rofi_view_remove_active(state);
|
rofi_view_remove_active(state);
|
||||||
rofi_view_free(state);
|
rofi_view_free(state);
|
||||||
|
@ -282,8 +260,7 @@ void process_result ( RofiViewState *state )
|
||||||
/**
|
/**
|
||||||
* Help function.
|
* Help function.
|
||||||
*/
|
*/
|
||||||
static void print_list_of_modi ( int is_term )
|
static void print_list_of_modi(int is_term) {
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < num_available_modi; i++) {
|
for (unsigned int i = 0; i < num_available_modi; i++) {
|
||||||
gboolean active = FALSE;
|
gboolean active = FALSE;
|
||||||
for (unsigned int j = 0; j < num_modi; j++) {
|
for (unsigned int j = 0; j < num_modi; j++) {
|
||||||
|
@ -292,33 +269,48 @@ static void print_list_of_modi ( int is_term )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf ( " * %s%s%s%s\n",
|
printf(" * %s%s%s%s\n", active ? "+" : "",
|
||||||
active ? "+" : "",
|
|
||||||
is_term ? (active ? color_green : color_red) : "",
|
is_term ? (active ? color_green : color_red) : "",
|
||||||
available_modi[i]->name,
|
available_modi[i]->name, is_term ? color_reset : "");
|
||||||
is_term ? color_reset : ""
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void print_main_application_options ( int is_term )
|
static void print_main_application_options(int is_term) {
|
||||||
{
|
print_help_msg("-no-config", "",
|
||||||
print_help_msg ( "-no-config", "", "Do not load configuration, use default values.", NULL, is_term );
|
"Do not load configuration, use default values.", NULL,
|
||||||
print_help_msg ( "-v,-version", "", "Print the version number and exit.", NULL, is_term );
|
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("-dmenu", "", "Start in dmenu mode.", NULL, is_term);
|
||||||
print_help_msg ( "-display", "[string]", "X server to contact.", "${DISPLAY}", 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("-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("-e", "[string]",
|
||||||
print_help_msg ( "-markup", "", "Enable pango markup where possible.", NULL, is_term );
|
"Show a dialog displaying the passed message and exit.", NULL,
|
||||||
print_help_msg ( "-normal-window", "", "Behave as a normal window. (experimental)", NULL, is_term );
|
is_term);
|
||||||
print_help_msg ( "-show", "[mode]", "Show the mode 'mode' and exit. The mode has to be enabled.", NULL, is_term );
|
print_help_msg("-markup", "", "Enable pango markup where possible.", NULL,
|
||||||
print_help_msg ( "-no-lazy-grab", "", "Disable lazy grab that, when fail to grab keyboard, does not block but retry later.", NULL, is_term );
|
is_term);
|
||||||
print_help_msg ( "-no-plugins", "", "Disable loading of external plugins.", NULL, is_term );
|
print_help_msg("-normal-window", "",
|
||||||
print_help_msg ( "-plugin-path", "", "Directory used to search for rofi plugins. *DEPRECATED*", NULL, is_term );
|
"Behave as a normal window. (experimental)", NULL, is_term);
|
||||||
print_help_msg ( "-dump-config", "", "Dump the current configuration in rasi format and exit.", NULL, is_term );
|
print_help_msg("-show", "[mode]",
|
||||||
print_help_msg ( "-dump-theme", "", "Dump the current theme in rasi format and exit.", NULL, is_term );
|
"Show the mode 'mode' and exit. The mode has to be enabled.",
|
||||||
|
NULL, is_term);
|
||||||
|
print_help_msg("-no-lazy-grab", "",
|
||||||
|
"Disable lazy grab that, when fail to grab keyboard, does not "
|
||||||
|
"block but retry later.",
|
||||||
|
NULL, is_term);
|
||||||
|
print_help_msg("-no-plugins", "", "Disable loading of external plugins.",
|
||||||
|
NULL, is_term);
|
||||||
|
print_help_msg("-plugin-path", "",
|
||||||
|
"Directory used to search for rofi plugins. *DEPRECATED*",
|
||||||
|
NULL, is_term);
|
||||||
|
print_help_msg("-dump-config", "",
|
||||||
|
"Dump the current configuration in rasi format and exit.",
|
||||||
|
NULL, is_term);
|
||||||
|
print_help_msg("-dump-theme", "",
|
||||||
|
"Dump the current theme in rasi format and exit.", NULL,
|
||||||
|
is_term);
|
||||||
}
|
}
|
||||||
static void help ( G_GNUC_UNUSED int argc, char **argv )
|
static void help(G_GNUC_UNUSED int argc, char **argv) {
|
||||||
{
|
|
||||||
int is_term = isatty(fileno(stdout));
|
int is_term = isatty(fileno(stdout));
|
||||||
printf("%s usage:\n", argv[0]);
|
printf("%s usage:\n", argv[0]);
|
||||||
printf("\t%s [-options ...]\n\n", argv[0]);
|
printf("\t%s [-options ...]\n\n", argv[0]);
|
||||||
|
@ -336,63 +328,77 @@ static void help ( G_GNUC_UNUSED int argc, char **argv )
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Compile time options:\n");
|
printf("Compile time options:\n");
|
||||||
#ifdef WINDOW_MODE
|
#ifdef WINDOW_MODE
|
||||||
printf ( "\t* window %senabled%s\n", is_term ? color_green : "", is_term ? color_reset : "" );
|
printf("\t* window %senabled%s\n", is_term ? color_green : "",
|
||||||
|
is_term ? color_reset : "");
|
||||||
#else
|
#else
|
||||||
printf ( "\t* window %sdisabled%s\n", is_term ? color_red : "", is_term ? color_reset : "" );
|
printf("\t* window %sdisabled%s\n", is_term ? color_red : "",
|
||||||
|
is_term ? color_reset : "");
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_DRUN
|
#ifdef ENABLE_DRUN
|
||||||
printf ( "\t* drun %senabled%s\n", is_term ? color_green : "", is_term ? color_reset : "" );
|
printf("\t* drun %senabled%s\n", is_term ? color_green : "",
|
||||||
|
is_term ? color_reset : "");
|
||||||
#else
|
#else
|
||||||
printf ( "\t* drun %sdisabled%s\n", is_term ? color_red : "", is_term ? color_reset : "" );
|
printf("\t* drun %sdisabled%s\n", is_term ? color_red : "",
|
||||||
|
is_term ? color_reset : "");
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_GCOV
|
#ifdef ENABLE_GCOV
|
||||||
printf ( "\t* gcov %senabled%s\n", is_term ? color_green : "", is_term ? color_reset : "" );
|
printf("\t* gcov %senabled%s\n", is_term ? color_green : "",
|
||||||
|
is_term ? color_reset : "");
|
||||||
#else
|
#else
|
||||||
printf ( "\t* gcov %sdisabled%s\n", is_term ? color_red : "", is_term ? color_reset : "" );
|
printf("\t* gcov %sdisabled%s\n", is_term ? color_red : "",
|
||||||
|
is_term ? color_reset : "");
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_ASAN
|
#ifdef ENABLE_ASAN
|
||||||
printf ( "\t* asan %senabled%s\n", is_term ? color_green : "", is_term ? color_reset : "" );
|
printf("\t* asan %senabled%s\n", is_term ? color_green : "",
|
||||||
|
is_term ? color_reset : "");
|
||||||
#else
|
#else
|
||||||
printf ( "\t* asan %sdisabled%s\n", is_term ? color_red : "", is_term ? color_reset : "" );
|
printf("\t* asan %sdisabled%s\n", is_term ? color_red : "",
|
||||||
|
is_term ? color_reset : "");
|
||||||
#endif
|
#endif
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf ( "For more information see: %sman rofi%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
|
printf("For more information see: %sman rofi%s\n", is_term ? color_bold : "",
|
||||||
|
is_term ? color_reset : "");
|
||||||
#ifdef GIT_VERSION
|
#ifdef GIT_VERSION
|
||||||
printf ( " Version: %s"GIT_VERSION "%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
|
printf(" Version: %s" GIT_VERSION "%s\n",
|
||||||
|
is_term ? color_bold : "", is_term ? color_reset : "");
|
||||||
#else
|
#else
|
||||||
printf ( " Version: %s"VERSION "%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
|
printf(" Version: %s" VERSION "%s\n",
|
||||||
|
is_term ? color_bold : "", is_term ? color_reset : "");
|
||||||
#endif
|
#endif
|
||||||
printf ( " Bugreports: %s"PACKAGE_BUGREPORT "%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
|
printf(" Bugreports: %s" PACKAGE_BUGREPORT "%s\n",
|
||||||
printf ( " Support: %s"PACKAGE_URL "%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
|
is_term ? color_bold : "", is_term ? color_reset : "");
|
||||||
printf ( " %s#rofi @ libera.chat%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 @ libera.chat%s\n",
|
||||||
|
is_term ? color_bold : "", is_term ? color_reset : "");
|
||||||
if (find_arg("-no-config") < 0) {
|
if (find_arg("-no-config") < 0) {
|
||||||
if (config_path) {
|
if (config_path) {
|
||||||
printf ( " Configuration file: %s%s%s\n", is_term ? color_bold : "", config_path, is_term ? color_reset : "" );
|
printf(" Configuration file: %s%s%s\n", is_term ? color_bold : "",
|
||||||
|
config_path, is_term ? color_reset : "");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
printf(" Configuration file: %sDisabled%s\n",
|
||||||
printf ( " Configuration file: %sDisabled%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
|
is_term ? color_bold : "", is_term ? color_reset : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void help_print_disabled_mode ( const char *mode )
|
static void help_print_disabled_mode(const char *mode) {
|
||||||
{
|
|
||||||
int is_term = isatty(fileno(stdout));
|
int is_term = isatty(fileno(stdout));
|
||||||
// Only output to terminal
|
// Only output to terminal
|
||||||
if (is_term) {
|
if (is_term) {
|
||||||
fprintf(stderr, "Mode %s%s%s is not enabled. I have enabled it for now.\n",
|
fprintf(stderr, "Mode %s%s%s is not enabled. I have enabled it for now.\n",
|
||||||
color_red, mode, color_reset);
|
color_red, mode, color_reset);
|
||||||
fprintf ( stderr, "Please consider adding %s%s%s to the list of enabled modi: %smodi: %s%s%s,%s%s.\n",
|
fprintf(stderr,
|
||||||
color_red, mode, color_reset,
|
"Please consider adding %s%s%s to the list of enabled modi: "
|
||||||
color_green, config.modi, color_reset,
|
"%smodi: %s%s%s,%s%s.\n",
|
||||||
color_red, mode, color_reset
|
color_red, mode, color_reset, color_green, config.modi, color_reset,
|
||||||
);
|
color_red, mode, color_reset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void help_print_mode_not_found ( const char *mode )
|
static void help_print_mode_not_found(const char *mode) {
|
||||||
{
|
|
||||||
GString *str = g_string_new("");
|
GString *str = g_string_new("");
|
||||||
g_string_printf ( str, "Mode %s is not found.\nThe following modi are known:\n", mode );
|
g_string_printf(str, "Mode %s is not found.\nThe following modi are known:\n",
|
||||||
|
mode);
|
||||||
for (unsigned int i = 0; i < num_available_modi; i++) {
|
for (unsigned int i = 0; i < num_available_modi; i++) {
|
||||||
gboolean active = FALSE;
|
gboolean active = FALSE;
|
||||||
for (unsigned int j = 0; j < num_modi; j++) {
|
for (unsigned int j = 0; j < num_modi; j++) {
|
||||||
|
@ -401,15 +407,12 @@ static void help_print_mode_not_found ( const char *mode )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_string_append_printf ( str, " * %s%s\n",
|
g_string_append_printf(str, " * %s%s\n", active ? "+" : "",
|
||||||
active ? "+" : "",
|
available_modi[i]->name);
|
||||||
available_modi[i]->name
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
rofi_add_error_message(str);
|
rofi_add_error_message(str);
|
||||||
}
|
}
|
||||||
static void help_print_no_arguments ( void )
|
static void help_print_no_arguments(void) {
|
||||||
{
|
|
||||||
int is_term = isatty(fileno(stdout));
|
int is_term = isatty(fileno(stdout));
|
||||||
// Daemon mode
|
// Daemon mode
|
||||||
fprintf(stderr, "Rofi is unsure what to show.\n");
|
fprintf(stderr, "Rofi is unsure what to show.\n");
|
||||||
|
@ -419,9 +422,7 @@ static void help_print_no_arguments ( void )
|
||||||
is_term ? color_green : "", is_term ? color_reset : "");
|
is_term ? color_green : "", is_term ? color_reset : "");
|
||||||
fprintf(stderr, "The following modi are enabled:\n");
|
fprintf(stderr, "The following modi are enabled:\n");
|
||||||
for (unsigned int j = 0; j < num_modi; j++) {
|
for (unsigned int j = 0; j < num_modi; j++) {
|
||||||
fprintf ( stderr, " * %s%s%s\n",
|
fprintf(stderr, " * %s%s%s\n", is_term ? color_green : "", modi[j]->name,
|
||||||
is_term ? color_green : "",
|
|
||||||
modi[j]->name,
|
|
||||||
is_term ? color_reset : "");
|
is_term ? color_reset : "");
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\nThe following can be enabled:\n");
|
fprintf(stderr, "\nThe following can be enabled:\n");
|
||||||
|
@ -434,21 +435,20 @@ static void help_print_no_arguments ( void )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!active) {
|
if (!active) {
|
||||||
fprintf ( stderr, " * %s%s%s\n",
|
fprintf(stderr, " * %s%s%s\n", is_term ? color_red : "",
|
||||||
is_term ? color_red : "",
|
available_modi[i]->name, is_term ? color_reset : "");
|
||||||
available_modi[i]->name,
|
|
||||||
is_term ? color_reset : "" );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf ( stderr, "\nTo activate a mode, add it to the list of modi in the %smodi%s setting.\n",
|
fprintf(stderr,
|
||||||
|
"\nTo activate a mode, add it to the list of modi in the %smodi%s "
|
||||||
|
"setting.\n",
|
||||||
is_term ? color_green : "", is_term ? color_reset : "");
|
is_term ? color_green : "", is_term ? color_reset : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleanup globally allocated memory.
|
* Cleanup globally allocated memory.
|
||||||
*/
|
*/
|
||||||
static void cleanup ()
|
static void cleanup() {
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < num_modi; i++) {
|
for (unsigned int i = 0; i < num_modi; i++) {
|
||||||
mode_destroy(modi[i]);
|
mode_destroy(modi[i]);
|
||||||
}
|
}
|
||||||
|
@ -488,8 +488,7 @@ static void cleanup ()
|
||||||
* Collected modi
|
* Collected modi
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Mode * rofi_collect_modi_search ( const char *name )
|
Mode *rofi_collect_modi_search(const char *name) {
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < num_available_modi; i++) {
|
for (unsigned int i = 0; i < num_available_modi; i++) {
|
||||||
if (g_strcmp0(name, available_modi[i]->name) == 0) {
|
if (g_strcmp0(name, available_modi[i]->name) == 0) {
|
||||||
return available_modi[i];
|
return available_modi[i];
|
||||||
|
@ -502,11 +501,11 @@ Mode * rofi_collect_modi_search ( const char *name )
|
||||||
*
|
*
|
||||||
* @returns TRUE when success.
|
* @returns TRUE when success.
|
||||||
*/
|
*/
|
||||||
static gboolean rofi_collect_modi_add ( Mode *mode )
|
static gboolean rofi_collect_modi_add(Mode *mode) {
|
||||||
{
|
|
||||||
Mode *m = rofi_collect_modi_search(mode->name);
|
Mode *m = rofi_collect_modi_search(mode->name);
|
||||||
if (m == NULL) {
|
if (m == NULL) {
|
||||||
available_modi = g_realloc ( available_modi, sizeof ( Mode * ) * ( num_available_modi + 1 ) );
|
available_modi =
|
||||||
|
g_realloc(available_modi, sizeof(Mode *) * (num_available_modi + 1));
|
||||||
// Set mode.
|
// Set mode.
|
||||||
available_modi[num_available_modi] = mode;
|
available_modi[num_available_modi] = mode;
|
||||||
num_available_modi++;
|
num_available_modi++;
|
||||||
|
@ -515,8 +514,7 @@ static gboolean rofi_collect_modi_add ( Mode *mode )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rofi_collect_modi_dir ( const char *base_dir )
|
static void rofi_collect_modi_dir(const char *base_dir) {
|
||||||
{
|
|
||||||
g_debug("Looking into: %s for plugins", base_dir);
|
g_debug("Looking into: %s for plugins", base_dir);
|
||||||
GDir *dir = g_dir_open(base_dir, 0, NULL);
|
GDir *dir = g_dir_open(base_dir, 0, NULL);
|
||||||
if (dir) {
|
if (dir) {
|
||||||
|
@ -527,28 +525,29 @@ static void rofi_collect_modi_dir ( const char *base_dir )
|
||||||
}
|
}
|
||||||
char *fn = g_build_filename(base_dir, dn, NULL);
|
char *fn = g_build_filename(base_dir, dn, NULL);
|
||||||
g_debug("Trying to open: %s plugin", fn);
|
g_debug("Trying to open: %s plugin", fn);
|
||||||
GModule *mod = g_module_open ( fn, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL );
|
GModule *mod =
|
||||||
|
g_module_open(fn, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
|
||||||
if (mod) {
|
if (mod) {
|
||||||
Mode *m = NULL;
|
Mode *m = NULL;
|
||||||
if (g_module_symbol(mod, "mode", (gpointer *)&m)) {
|
if (g_module_symbol(mod, "mode", (gpointer *)&m)) {
|
||||||
if (m->abi_version != ABI_VERSION) {
|
if (m->abi_version != ABI_VERSION) {
|
||||||
g_warning ( "ABI version of plugin: '%s' does not match: %08X expecting: %08X", dn, m->abi_version, ABI_VERSION );
|
g_warning("ABI version of plugin: '%s' does not match: %08X "
|
||||||
|
"expecting: %08X",
|
||||||
|
dn, m->abi_version, ABI_VERSION);
|
||||||
g_module_close(mod);
|
g_module_close(mod);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
m->module = mod;
|
m->module = mod;
|
||||||
if (!rofi_collect_modi_add(m)) {
|
if (!rofi_collect_modi_add(m)) {
|
||||||
g_module_close(mod);
|
g_module_close(mod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
g_warning("Symbol 'mode' not found in module: %s", dn);
|
g_warning("Symbol 'mode' not found in module: %s", dn);
|
||||||
g_module_close(mod);
|
g_module_close(mod);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
g_warning("Failed to open 'mode' plugin: '%s', error: %s", dn,
|
||||||
g_warning ( "Failed to open 'mode' plugin: '%s', error: %s", dn, g_module_error () );
|
g_module_error());
|
||||||
}
|
}
|
||||||
g_free(fn);
|
g_free(fn);
|
||||||
}
|
}
|
||||||
|
@ -559,8 +558,7 @@ static void rofi_collect_modi_dir ( const char *base_dir )
|
||||||
/**
|
/**
|
||||||
* Find all available modi.
|
* Find all available modi.
|
||||||
*/
|
*/
|
||||||
static void rofi_collect_modi ( void )
|
static void rofi_collect_modi(void) {
|
||||||
{
|
|
||||||
#ifdef WINDOW_MODE
|
#ifdef WINDOW_MODE
|
||||||
rofi_collect_modi_add(&window_mode);
|
rofi_collect_modi_add(&window_mode);
|
||||||
rofi_collect_modi_add(&window_mode_cd);
|
rofi_collect_modi_add(&window_mode_cd);
|
||||||
|
@ -593,14 +591,12 @@ static void rofi_collect_modi ( void )
|
||||||
/**
|
/**
|
||||||
* Setup configuration for config.
|
* Setup configuration for config.
|
||||||
*/
|
*/
|
||||||
static void rofi_collect_modi_setup ( void )
|
static void rofi_collect_modi_setup(void) {
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < num_available_modi; i++) {
|
for (unsigned int i = 0; i < num_available_modi; i++) {
|
||||||
mode_set_config(available_modi[i]);
|
mode_set_config(available_modi[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void rofi_collect_modi_destroy ( void )
|
static void rofi_collect_modi_destroy(void) {
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < num_available_modi; i++) {
|
for (unsigned int i = 0; i < num_available_modi; i++) {
|
||||||
if (available_modi[i]->module) {
|
if (available_modi[i]->module) {
|
||||||
GModule *mod = available_modi[i]->module;
|
GModule *mod = available_modi[i]->module;
|
||||||
|
@ -623,8 +619,7 @@ static void rofi_collect_modi_destroy ( void )
|
||||||
* First the three build-in modi are checked: window, run, ssh
|
* First the three build-in modi are checked: window, run, ssh
|
||||||
* if that fails, a script-switcher is created.
|
* if that fails, a script-switcher is created.
|
||||||
*/
|
*/
|
||||||
static int add_mode ( const char * token )
|
static int add_mode(const char *token) {
|
||||||
{
|
|
||||||
unsigned int index = num_modi;
|
unsigned int index = num_modi;
|
||||||
// Resize and add entry.
|
// Resize and add entry.
|
||||||
modi = (Mode **)g_realloc(modi, sizeof(Mode *) * (num_modi + 1));
|
modi = (Mode **)g_realloc(modi, sizeof(Mode *) * (num_modi + 1));
|
||||||
|
@ -633,8 +628,7 @@ static int add_mode ( const char * token )
|
||||||
if (mode) {
|
if (mode) {
|
||||||
modi[num_modi] = mode;
|
modi[num_modi] = mode;
|
||||||
num_modi++;
|
num_modi++;
|
||||||
}
|
} else if (script_switcher_is_valid(token)) {
|
||||||
else if ( script_switcher_is_valid ( token ) ) {
|
|
||||||
// If not build in, use custom modi.
|
// If not build in, use custom modi.
|
||||||
Mode *sw = script_switcher_parse_setup(token);
|
Mode *sw = script_switcher_parse_setup(token);
|
||||||
if (sw != NULL) {
|
if (sw != NULL) {
|
||||||
|
@ -647,14 +641,14 @@ static int add_mode ( const char * token )
|
||||||
}
|
}
|
||||||
return (index == num_modi) ? -1 : (int)index;
|
return (index == num_modi) ? -1 : (int)index;
|
||||||
}
|
}
|
||||||
static gboolean setup_modi ( void )
|
static gboolean setup_modi(void) {
|
||||||
{
|
|
||||||
const char *const sep = ",#";
|
const char *const sep = ",#";
|
||||||
char *savept = NULL;
|
char *savept = NULL;
|
||||||
// Make a copy, as strtok will modify it.
|
// Make a copy, as strtok will modify it.
|
||||||
char *switcher_str = g_strdup(config.modi);
|
char *switcher_str = g_strdup(config.modi);
|
||||||
// Split token on ','. This modifies switcher_str.
|
// Split token on ','. This modifies switcher_str.
|
||||||
for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) {
|
for (char *token = strtok_r(switcher_str, sep, &savept); token != NULL;
|
||||||
|
token = strtok_r(NULL, sep, &savept)) {
|
||||||
if (add_mode(token) == -1) {
|
if (add_mode(token) == -1) {
|
||||||
help_print_mode_not_found(token);
|
help_print_mode_not_found(token);
|
||||||
}
|
}
|
||||||
|
@ -668,20 +662,16 @@ static gboolean setup_modi ( void )
|
||||||
* Quit rofi mainloop.
|
* Quit rofi mainloop.
|
||||||
* This will exit program.
|
* This will exit program.
|
||||||
**/
|
**/
|
||||||
void rofi_quit_main_loop ( void )
|
void rofi_quit_main_loop(void) { g_main_loop_quit(main_loop); }
|
||||||
{
|
|
||||||
g_main_loop_quit ( main_loop );
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean main_loop_signal_handler_int ( G_GNUC_UNUSED gpointer data )
|
static gboolean main_loop_signal_handler_int(G_GNUC_UNUSED gpointer data) {
|
||||||
{
|
|
||||||
// Break out of loop.
|
// Break out of loop.
|
||||||
g_main_loop_quit(main_loop);
|
g_main_loop_quit(main_loop);
|
||||||
return G_SOURCE_CONTINUE;
|
return G_SOURCE_CONTINUE;
|
||||||
}
|
}
|
||||||
static void show_error_dialog ()
|
static void show_error_dialog() {
|
||||||
{
|
GString *emesg =
|
||||||
GString *emesg = g_string_new ( "The following errors were detected when starting rofi:\n" );
|
g_string_new("The following errors were detected when starting rofi:\n");
|
||||||
GList *iter = g_list_first(list_of_error_msgs);
|
GList *iter = g_list_first(list_of_error_msgs);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (; iter != NULL && index < 2; iter = g_list_next(iter)) {
|
for (; iter != NULL && index < 2; iter = g_list_next(iter)) {
|
||||||
|
@ -691,15 +681,15 @@ static void show_error_dialog ()
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
if (g_list_length(iter) > 1) {
|
if (g_list_length(iter) > 1) {
|
||||||
g_string_append_printf ( emesg, "\nThere are <b>%d</b> more errors.", 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);
|
rofi_view_error_dialog(emesg->str, ERROR_MSG_MARKUP);
|
||||||
g_string_free(emesg, TRUE);
|
g_string_free(emesg, TRUE);
|
||||||
rofi_set_return_code(EX_DATAERR);
|
rofi_set_return_code(EX_DATAERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean startup ( G_GNUC_UNUSED gpointer data )
|
static gboolean startup(G_GNUC_UNUSED gpointer data) {
|
||||||
{
|
|
||||||
TICK_N("Startup");
|
TICK_N("Startup");
|
||||||
// flags to run immediately and exit
|
// flags to run immediately and exit
|
||||||
char *sname = NULL;
|
char *sname = NULL;
|
||||||
|
@ -732,8 +722,7 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data )
|
||||||
// Directly exit.
|
// Directly exit.
|
||||||
g_main_loop_quit(main_loop);
|
g_main_loop_quit(main_loop);
|
||||||
}
|
}
|
||||||
}
|
} else if (find_arg_str("-e", &(msg))) {
|
||||||
else if ( find_arg_str ( "-e", &( msg ) ) ) {
|
|
||||||
int markup = FALSE;
|
int markup = FALSE;
|
||||||
if (find_arg("-markup") >= 0) {
|
if (find_arg("-markup") >= 0) {
|
||||||
markup = TRUE;
|
markup = TRUE;
|
||||||
|
@ -741,8 +730,7 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data )
|
||||||
if (!rofi_view_error_dialog(msg, markup)) {
|
if (!rofi_view_error_dialog(msg, markup)) {
|
||||||
g_main_loop_quit(main_loop);
|
g_main_loop_quit(main_loop);
|
||||||
}
|
}
|
||||||
}
|
} else if (find_arg_str("-show", &sname) == TRUE) {
|
||||||
else if ( find_arg_str ( "-show", &sname ) == TRUE ) {
|
|
||||||
int index = switcher_get(sname);
|
int index = switcher_get(sname);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
// Add it to the list
|
// Add it to the list
|
||||||
|
@ -755,17 +743,14 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data )
|
||||||
}
|
}
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
run_switcher(index);
|
run_switcher(index);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
help_print_mode_not_found(sname);
|
help_print_mode_not_found(sname);
|
||||||
show_error_dialog();
|
show_error_dialog();
|
||||||
return G_SOURCE_REMOVE;
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
}
|
} else if (find_arg("-show") >= 0 && num_modi > 0) {
|
||||||
else if ( find_arg ( "-show" ) >= 0 && num_modi > 0 ) {
|
|
||||||
run_switcher(0);
|
run_switcher(0);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
help_print_no_arguments();
|
help_print_no_arguments();
|
||||||
|
|
||||||
g_main_loop_quit(main_loop);
|
g_main_loop_quit(main_loop);
|
||||||
|
@ -774,8 +759,7 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data )
|
||||||
return G_SOURCE_REMOVE;
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean record ( G_GNUC_UNUSED void *data )
|
static gboolean record(G_GNUC_UNUSED void *data) {
|
||||||
{
|
|
||||||
rofi_capture_screenshot();
|
rofi_capture_screenshot();
|
||||||
return G_SOURCE_CONTINUE;
|
return G_SOURCE_CONTINUE;
|
||||||
}
|
}
|
||||||
|
@ -787,8 +771,7 @@ static gboolean record ( G_GNUC_UNUSED void *data )
|
||||||
*
|
*
|
||||||
* @returns return code of rofi.
|
* @returns return code of rofi.
|
||||||
*/
|
*/
|
||||||
int main ( int argc, char *argv[] )
|
int main(int argc, char *argv[]) {
|
||||||
{
|
|
||||||
TIMINGS_START();
|
TIMINGS_START();
|
||||||
|
|
||||||
cmd_set_arguments(argc, argv);
|
cmd_set_arguments(argc, argv);
|
||||||
|
@ -847,32 +830,30 @@ int main ( int argc, char *argv[] )
|
||||||
const char *path = g_get_user_runtime_dir();
|
const char *path = g_get_user_runtime_dir();
|
||||||
if (path) {
|
if (path) {
|
||||||
if (g_mkdir_with_parents(path, 0700) < 0) {
|
if (g_mkdir_with_parents(path, 0700) < 0) {
|
||||||
g_warning ( "Failed to create user runtime directory: %s with error: %s", path, g_strerror ( errno ) );
|
g_warning("Failed to create user runtime directory: %s with error: %s",
|
||||||
|
path, g_strerror(errno));
|
||||||
pidfile = g_build_filename(g_get_home_dir(), ".rofi.pid", NULL);
|
pidfile = g_build_filename(g_get_home_dir(), ".rofi.pid", NULL);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
pidfile = g_build_filename(path, "rofi.pid", NULL);
|
pidfile = g_build_filename(path, "rofi.pid", NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config_parser_add_option ( xrm_String, "pid", (void * *) &pidfile, "Pidfile location" );
|
config_parser_add_option(xrm_String, "pid", (void **)&pidfile,
|
||||||
|
"Pidfile location");
|
||||||
|
|
||||||
/** default configuration */
|
/** default configuration */
|
||||||
{
|
{
|
||||||
GBytes *theme_data = g_resource_lookup_data(
|
GBytes *theme_data = g_resource_lookup_data(
|
||||||
resources_get_resource (),
|
resources_get_resource(), "/org/qtools/rofi/default_configuration.rasi",
|
||||||
"/org/qtools/rofi/default_configuration.rasi",
|
G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
|
||||||
G_RESOURCE_LOOKUP_FLAGS_NONE,
|
|
||||||
NULL );
|
|
||||||
if (theme_data) {
|
if (theme_data) {
|
||||||
const char *theme = g_bytes_get_data(theme_data, NULL);
|
const char *theme = g_bytes_get_data(theme_data, NULL);
|
||||||
if (rofi_theme_parse_string((const char *)theme)) {
|
if (rofi_theme_parse_string((const char *)theme)) {
|
||||||
g_warning("Failed to parse default configuration. Giving up..");
|
g_warning("Failed to parse default configuration. Giving up..");
|
||||||
if (list_of_error_msgs) {
|
if (list_of_error_msgs) {
|
||||||
for ( GList *iter = g_list_first ( list_of_error_msgs );
|
for (GList *iter = g_list_first(list_of_error_msgs); iter != NULL;
|
||||||
iter != NULL; iter = g_list_next ( iter ) ) {
|
iter = g_list_next(iter)) {
|
||||||
g_warning ( "Error: %s%s%s",
|
g_warning("Error: %s%s%s", color_bold, ((GString *)iter->data)->str,
|
||||||
color_bold, ( (GString *) iter->data )->str, color_reset );
|
color_reset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rofi_configuration = NULL;
|
rofi_configuration = NULL;
|
||||||
|
@ -888,8 +869,7 @@ int main ( int argc, char *argv[] )
|
||||||
if (cpath) {
|
if (cpath) {
|
||||||
config_path = g_build_filename(cpath, "rofi", "config.rasi", NULL);
|
config_path = g_build_filename(cpath, "rofi", "config.rasi", NULL);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
char *c = NULL;
|
char *c = NULL;
|
||||||
find_arg_str("-config", &c);
|
find_arg_str("-config", &c);
|
||||||
config_path = rofi_expand_path(c);
|
config_path = rofi_expand_path(c);
|
||||||
|
@ -999,8 +979,7 @@ int main ( int argc, char *argv[] )
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
TICK_N("Setup Modi");
|
TICK_N("Setup Modi");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Hack for dmenu compatibility.
|
// Hack for dmenu compatibility.
|
||||||
if (find_arg_str("-w", &windowid) == TRUE) {
|
if (find_arg_str("-w", &windowid) == TRUE) {
|
||||||
config.monitor = g_strdup_printf("wid:%s", windowid);
|
config.monitor = g_strdup_printf("wid:%s", windowid);
|
||||||
|
@ -1009,19 +988,17 @@ int main ( int argc, char *argv[] )
|
||||||
}
|
}
|
||||||
if (rofi_theme_is_empty()) {
|
if (rofi_theme_is_empty()) {
|
||||||
GBytes *theme_data = g_resource_lookup_data(
|
GBytes *theme_data = g_resource_lookup_data(
|
||||||
resources_get_resource (),
|
resources_get_resource(), "/org/qtools/rofi/default_theme.rasi",
|
||||||
"/org/qtools/rofi/default_theme.rasi",
|
G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
|
||||||
G_RESOURCE_LOOKUP_FLAGS_NONE,
|
|
||||||
NULL );
|
|
||||||
if (theme_data) {
|
if (theme_data) {
|
||||||
const char *theme = g_bytes_get_data(theme_data, NULL);
|
const char *theme = g_bytes_get_data(theme_data, NULL);
|
||||||
if (rofi_theme_parse_string((const char *)theme)) {
|
if (rofi_theme_parse_string((const char *)theme)) {
|
||||||
g_warning("Failed to parse default theme. Giving up..");
|
g_warning("Failed to parse default theme. Giving up..");
|
||||||
if (list_of_error_msgs) {
|
if (list_of_error_msgs) {
|
||||||
for ( GList *iter = g_list_first ( list_of_error_msgs );
|
for (GList *iter = g_list_first(list_of_error_msgs); iter != NULL;
|
||||||
iter != NULL; iter = g_list_next ( iter ) ) {
|
iter = g_list_next(iter)) {
|
||||||
g_warning ( "Error: %s%s%s",
|
g_warning("Error: %s%s%s", color_bold, ((GString *)iter->data)->str,
|
||||||
color_bold, ( (GString *) iter->data )->str, color_reset );
|
color_reset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rofi_theme = NULL;
|
rofi_theme = NULL;
|
||||||
|
@ -1058,7 +1035,8 @@ int main ( int argc, char *argv[] )
|
||||||
}
|
}
|
||||||
// Dump.
|
// Dump.
|
||||||
// catch help request
|
// catch help request
|
||||||
if ( find_arg ( "-h" ) >= 0 || find_arg ( "-help" ) >= 0 || find_arg ( "--help" ) >= 0 ) {
|
if (find_arg("-h") >= 0 || find_arg("-help") >= 0 ||
|
||||||
|
find_arg("--help") >= 0) {
|
||||||
help(argc, argv);
|
help(argc, argv);
|
||||||
cleanup();
|
cleanup();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
@ -1115,15 +1093,14 @@ int main ( int argc, char *argv[] )
|
||||||
|
|
||||||
/** List of error messages.*/
|
/** List of error messages.*/
|
||||||
extern GList *list_of_error_msgs;
|
extern GList *list_of_error_msgs;
|
||||||
int rofi_theme_rasi_validate ( const char *filename )
|
int rofi_theme_rasi_validate(const char *filename) {
|
||||||
{
|
|
||||||
rofi_theme_parse_file(filename);
|
rofi_theme_parse_file(filename);
|
||||||
if (list_of_error_msgs == NULL) {
|
if (list_of_error_msgs == NULL) {
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( GList *iter = g_list_first ( list_of_error_msgs );
|
for (GList *iter = g_list_first(list_of_error_msgs); iter != NULL;
|
||||||
iter != NULL; iter = g_list_next ( iter ) ) {
|
iter = g_list_next(iter)) {
|
||||||
fputs(((GString *)iter->data)->str, stderr);
|
fputs(((GString *)iter->data)->str, stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue