Commit 2cacadff authored by Dave Davenport's avatar Dave Davenport

Test version of drun plugin using GAppInfo.

parents
build/
*.m4
configure
config.*
Makefile.in
ar-lib
autom4te.cache/
compile
depcomp
install-sh
ltmain.sh
missing
ACLOCAL_AMFLAGS=-I m4
plugindir=${libdir}/rofi/
plugin_LTLIBRARIES = grun.la
grun_la_SOURCES=\
src/grun.c
grun_la_CFLAGS= @glib_CFLAGS@ @rofi_CFLAGS@
grun_la_LIBADD= @glib_LIBS@ @rofi_LIBS@
grun_la_LDFLAGS= -module -avoid-version
# grun plugin
To run this you need an up to date checkout of rofi git installed.
Run rofi like:
```bash
rofi -show grun -modi grun
```
## Compilation
### Dependencies
| Dependency | Version |
|------------|-----------------|
| rofi | 1.4 (or git) |
### Installation
**grun** uses autotools as build system. If installing from git, the following steps should install it:
```bash
$ autoreconf -i
$ mkdir build
$ cd build/
$ ../configure
$ make
$ make install
```
AC_INIT([rofi-grun], [0.0.1], [https://my-neat-plugin.org//],[],[https://support.my-neat-plugin.org/])
AC_CONFIG_HEADER([config.h])
AC_CONFIG_MACRO_DIRS([m4])
dnl ---------------------------------------------------------------------
dnl Setup automake to be silent and in foreign mode.
dnl We want xz distribution
dnl ---------------------------------------------------------------------
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects dist-xz])
AM_SILENT_RULES([yes])
dnl ---------------------------------------------------------------------
dnl Check for compiler
dnl ---------------------------------------------------------------------
AC_PROG_CC([clang gcc cc])
dnl ---------------------------------------------------------------------
dnl C99 standard
dnl ---------------------------------------------------------------------
AC_PROG_CC_C99
dnl ---------------------------------------------------------------------
dnl C to Object rules.
dnl ---------------------------------------------------------------------
AM_PROG_CC_C_O
dnl ---------------------------------------------------------------------
dnl System extensions
dnl ---------------------------------------------------------------------
AC_USE_SYSTEM_EXTENSIONS
dnl ---------------------------------------------------------------------
dnl Static libraries programs
dnl ---------------------------------------------------------------------
AM_PROG_AR
dnl ---------------------------------------------------------------------
dnl Base CFLAGS
dnl ---------------------------------------------------------------------
AM_CFLAGS="-Wall -Wextra -Wparentheses -Winline -pedantic -Wunreachable-code"
dnl ---------------------------------------------------------------------
dnl Check dependencies
dnl ---------------------------------------------------------------------
PKG_PROG_PKG_CONFIG
dnl ---------------------------------------------------------------------
dnl PKG_CONFIG based dependencies
dnl ---------------------------------------------------------------------
PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.40 gio-unix-2.0 gmodule-2.0 ])
PKG_CHECK_MODULES([rofi], [rofi])
LT_INIT([disable-static])
dnl ---------------------------------------------------------------------
dnl Add extra compiler flags
dnl ---------------------------------------------------------------------
AC_SUBST([AM_CFLAGS])
AC_CONFIG_FILES([Makefile ])
AC_OUTPUT
/**
* rofi-grun
* MIT/X11 License
* Copyright (c) 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.
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <gmodule.h>
#include <rofi/mode.h>
#include <rofi/helper.h>
#include <rofi/mode-private.h>
#include <stdint.h>
#include <gio/gdesktopappinfo.h>
#define MARKUP 8
G_MODULE_EXPORT Mode mode;
/**
* The internal data structure holding the private data of the TEST Mode.
*/
typedef struct
{
GList *array;
unsigned int array_length;
} GRUNModePrivateData;
static void get_grun ( Mode *sw )
{
/**
* Get the entries to display.
* this gets called on plugin initialization.
*/
GRUNModePrivateData *pd = (GRUNModePrivateData *) mode_get_private_data ( sw );
GTimer *t = g_timer_new();
pd->array = g_app_info_get_all ();
pd->array_length = g_list_length(pd->array);
printf("elapsed calling g_app_info_get_all: %f\n" , g_timer_elapsed(t,NULL));
g_timer_destroy(t);
}
static int grun_mode_init ( Mode *sw )
{
/**
* Called on startup when enabled (in modi list)
*/
if ( mode_get_private_data ( sw ) == NULL ) {
GRUNModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
mode_set_private_data ( sw, (void *) pd );
// Load content.
get_grun ( sw );
}
return TRUE;
}
static unsigned int grun_mode_get_num_entries ( const Mode *sw )
{
const GRUNModePrivateData *pd = (const GRUNModePrivateData *) mode_get_private_data ( sw );
return pd->array_length;
}
static ModeMode grun_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
{
ModeMode retv = MODE_EXIT;
GRUNModePrivateData *pd = (GRUNModePrivateData *) mode_get_private_data ( sw );
if ( mretv & MENU_NEXT ) {
retv = NEXT_DIALOG;
} else if ( mretv & MENU_PREVIOUS ) {
retv = PREVIOUS_DIALOG;
} else if ( mretv & MENU_QUICK_SWITCH ) {
retv = ( mretv & MENU_LOWER_MASK );
} else if ( ( mretv & MENU_OK ) ) {
GAppInfo *app = g_list_nth_data(pd->array, selected_line);
if ( app ) {
g_app_info_launch ( app, NULL, NULL, NULL );
}
retv = MODE_EXIT;
} else if ( ( mretv & MENU_ENTRY_DELETE ) == MENU_ENTRY_DELETE ) {
retv = RELOAD_DIALOG;
}
return retv;
}
static void grun_mode_destroy ( Mode *sw )
{
GRUNModePrivateData *pd = (GRUNModePrivateData *) mode_get_private_data ( sw );
if ( pd != NULL ) {
g_list_free_full (pd->array, g_object_unref);
g_free ( pd );
mode_set_private_data ( sw, NULL );
}
}
static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **attr_list, int get_entry )
{
GRUNModePrivateData *pd = (GRUNModePrivateData *) mode_get_private_data ( sw );
if ( get_entry )
{
GAppInfo *app = g_list_nth_data(pd->array, selected_line);
if ( app ) {
*state |= MARKUP;
return g_markup_printf_escaped("%s <span weight='light' size='small'><i>(%s)</i></span>", g_app_info_get_name(app), g_app_info_get_description(app));
} else {
return g_strdup ( "Not found." );
}
}
// Only return the string if requested, otherwise only set state.
return NULL;
}
/**
* @param sw The mode object.
* @param tokens The tokens to match against.
* @param index The index in this plugin to match against.
*
* Match the entry.
*
* @param returns try when a match.
*/
static int grun_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index )
{
GRUNModePrivateData *pd = (GRUNModePrivateData *) mode_get_private_data ( sw );
GAppInfo *app = g_list_nth_data(pd->array, index);
int match = 1;
if ( app && tokens ) {
const char *name = g_app_info_get_name ( app );
const char *description = g_app_info_get_description ( app );
const char *exec = g_app_info_get_executable ( app );
for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) {
int test = 0;
rofi_int_matcher *ftokens[2] = { tokens[j], NULL };
if ( name ) {
test = helper_token_match ( ftokens, name );
}
if ( test == tokens[j]->invert && description ) {
test = helper_token_match ( ftokens, description );
}
if ( test == tokens[j]->invert && exec ) {
test = helper_token_match ( ftokens, exec );
}
if ( test == 0 ) {
match = 0;
}
}
}
// Call default matching function.
return match;//helper_token_match ( tokens, pd->array[index]);
}
Mode mode =
{
.abi_version = ABI_VERSION,
.name = "grun",
.cfg_name_key = "display-grun",
._init = grun_mode_init,
._get_num_entries = grun_mode_get_num_entries,
._result = grun_mode_result,
._destroy = grun_mode_destroy,
._token_match = grun_token_match,
._get_display_value = _get_display_value,
._get_message = NULL,
._get_completion = NULL,
._preprocess_input = NULL,
.private_data = NULL,
.free = NULL,
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment