mirror of
https://github.com/davatorium/rofi.git
synced 2025-01-27 15:25:24 -05:00
Do not include c files.
* Build separate objects.
This commit is contained in:
parent
51d3e38ac0
commit
9068ddc3b2
4 changed files with 122 additions and 49 deletions
29
Makefile
29
Makefile
|
@ -3,23 +3,40 @@ PREFIX?=$(DESTDIR)/usr
|
||||||
BINDIR?=$(PREFIX)/bin
|
BINDIR?=$(PREFIX)/bin
|
||||||
MANDIR?=$(PREFIX)/share/man/man1
|
MANDIR?=$(PREFIX)/share/man/man1
|
||||||
|
|
||||||
|
SOURCES=$(wildcard *.c)
|
||||||
|
OBJECTS=$(SOURCES:%.c=%.o)
|
||||||
|
|
||||||
|
MANPAGE_PATH=$(MANDIR)/simpleswitcher.1.gz
|
||||||
|
|
||||||
|
CFLAGS+=-DMANPAGE_PATH="\"$(MANPAGE_PATH)\""
|
||||||
|
CFLAGS+=-std=c99
|
||||||
|
|
||||||
# Check deps.
|
# Check deps.
|
||||||
ifeq (${DEBUG},1)
|
ifeq (${DEBUG},1)
|
||||||
CFLAGS+=-DTIMING=1
|
CFLAGS+=-DTIMING=1 -g3
|
||||||
LDADD+=-lrt
|
LDADD+=-lrt
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# Check dependencies
|
||||||
|
##
|
||||||
PKG_CONFIG?=$(shell which pkg-config)
|
PKG_CONFIG?=$(shell which pkg-config)
|
||||||
ifeq (${PKG_CONFIG},${EMPTY})
|
ifeq (${PKG_CONFIG},${EMPTY})
|
||||||
$(error Failed to find pkg-config. Please install pkg-config)
|
$(error Failed to find pkg-config. Please install pkg-config)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LDADD+=$(shell ${PKG_CONFIG} --cflags --libs x11 xinerama xft)
|
CFLAGS+=$(shell ${PKG_CONFIG} --cflags x11 xinerama xft)
|
||||||
|
LDADD+=$(shell ${PKG_CONFIG} --libs x11 xinerama xft)
|
||||||
|
|
||||||
ifeq (${LDADD},${EMPTY})
|
ifeq (${LDADD},${EMPTY})
|
||||||
$(error Failed to find the required dependencies: x11, xinerama, xft)
|
$(error Failed to find the required dependencies: x11, xinerama, xft)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# Check for i3.
|
||||||
|
##
|
||||||
I3?=$(shell which i3)
|
I3?=$(shell which i3)
|
||||||
ifneq (${I3},${EMPTY})
|
ifneq (${I3},${EMPTY})
|
||||||
$(info I3 mode is enabled)
|
$(info I3 mode is enabled)
|
||||||
|
@ -28,11 +45,9 @@ endif
|
||||||
|
|
||||||
all: normal
|
all: normal
|
||||||
|
|
||||||
normal:
|
|
||||||
$(CC) -o simpleswitcher simpleswitcher.c -std=c99 $(CFLAGS) $(LDADD) $(LDFLAGS)
|
|
||||||
|
|
||||||
debug:
|
normal: $(OBJECTS) | Makefile
|
||||||
$(CC) -o simpleswitcher-debug simpleswitcher.c -std=c99 $(CFLAGS) -Wunused-parameter -g -DDEBUG $(LDADD)
|
$(CC) -o simpleswitcher $^ $(LDADD) $(LDFLAGS)
|
||||||
|
|
||||||
install: normal install-man
|
install: normal install-man
|
||||||
install -Dm 755 simpleswitcher $(BINDIR)/simpleswitcher
|
install -Dm 755 simpleswitcher $(BINDIR)/simpleswitcher
|
||||||
|
@ -42,7 +57,7 @@ install-man:
|
||||||
gzip -f $(MANDIR)/simpleswitcher.1
|
gzip -f $(MANDIR)/simpleswitcher.1
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f simpleswitcher simpleswitcher-debug
|
rm -f simpleswitcher $(OBJECTS)
|
||||||
|
|
||||||
|
|
||||||
indent:
|
indent:
|
||||||
|
|
|
@ -67,8 +67,8 @@
|
||||||
|
|
||||||
#define INNER_MARGIN 5
|
#define INNER_MARGIN 5
|
||||||
|
|
||||||
#define OPAQUE 0xffffffff
|
#define OPAQUE 0xffffffff
|
||||||
#define OPACITY "_NET_WM_WINDOW_OPACITY"
|
#define OPACITY "_NET_WM_WINDOW_OPACITY"
|
||||||
#define I3_SOCKET_PATH_PROP "I3_SOCKET_PATH"
|
#define I3_SOCKET_PATH_PROP "I3_SOCKET_PATH"
|
||||||
|
|
||||||
#ifdef TIMING
|
#ifdef TIMING
|
||||||
|
@ -104,7 +104,7 @@ static void* reallocate( void *ptr, unsigned long bytes )
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline char **tokenize( const char *input )
|
static char **tokenize( const char *input )
|
||||||
{
|
{
|
||||||
if ( input == NULL ) return NULL;
|
if ( input == NULL ) return NULL;
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ static inline char **tokenize( const char *input )
|
||||||
int num_tokens = 1;
|
int num_tokens = 1;
|
||||||
|
|
||||||
//First entry is string that is modified.
|
//First entry is string that is modified.
|
||||||
retv = malloc( 2*sizeof( char* ) );
|
retv = allocate ( 2*sizeof( char* ) );
|
||||||
retv[0] = strdup( input );
|
retv[0] = strdup( input );
|
||||||
retv[1] = NULL;
|
retv[1] = NULL;
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ static inline char **tokenize( const char *input )
|
||||||
token = strtok_r( retv[0], " ", &saveptr );
|
token = strtok_r( retv[0], " ", &saveptr );
|
||||||
token != NULL;
|
token != NULL;
|
||||||
token = strtok_r( NULL, " ", &saveptr ) ) {
|
token = strtok_r( NULL, " ", &saveptr ) ) {
|
||||||
retv = realloc( retv, sizeof( char* )*( num_tokens+2 ) );
|
retv = reallocate( retv, sizeof( char* )*( num_tokens+2 ) );
|
||||||
retv[num_tokens+1] = NULL;
|
retv[num_tokens+1] = NULL;
|
||||||
retv[num_tokens] = token;
|
retv[num_tokens] = token;
|
||||||
num_tokens++;
|
num_tokens++;
|
||||||
|
@ -492,8 +492,6 @@ typedef struct {
|
||||||
#define MENUBGALT "#e9e8e7"
|
#define MENUBGALT "#e9e8e7"
|
||||||
#define MENUHLFG "#ffffff"
|
#define MENUHLFG "#ffffff"
|
||||||
#define MENUHLBG "#005577"
|
#define MENUHLBG "#005577"
|
||||||
#define MENURETURN 1
|
|
||||||
#define MENUMODUP 2
|
|
||||||
#define MENUBC "black"
|
#define MENUBC "black"
|
||||||
|
|
||||||
char *config_menu_font;
|
char *config_menu_font;
|
||||||
|
@ -508,7 +506,6 @@ int config_menu_lines;
|
||||||
unsigned int config_focus_mode;
|
unsigned int config_focus_mode;
|
||||||
unsigned int config_raise_mode;
|
unsigned int config_raise_mode;
|
||||||
unsigned int config_window_placement;
|
unsigned int config_window_placement;
|
||||||
unsigned int config_menu_bw;
|
|
||||||
unsigned int config_window_opacity;
|
unsigned int config_window_opacity;
|
||||||
unsigned int config_zeltak_mode;
|
unsigned int config_zeltak_mode;
|
||||||
#ifdef I3
|
#ifdef I3
|
||||||
|
@ -742,7 +739,8 @@ client* window_client( Window win )
|
||||||
if ( win == None ) return NULL;
|
if ( win == None ) return NULL;
|
||||||
|
|
||||||
int idx = winlist_find( cache_client, win );
|
int idx = winlist_find( cache_client, win );
|
||||||
if ( idx >= 0 ){
|
|
||||||
|
if ( idx >= 0 ) {
|
||||||
return cache_client->data[idx];
|
return cache_client->data[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -797,9 +795,6 @@ client* window_client( Window win )
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ALLWINDOWS 1
|
|
||||||
#define DESKTOPWINDOWS 2
|
|
||||||
|
|
||||||
unsigned int windows_modmask;
|
unsigned int windows_modmask;
|
||||||
KeySym windows_keysym;
|
KeySym windows_keysym;
|
||||||
unsigned int rundialog_modmask;
|
unsigned int rundialog_modmask;
|
||||||
|
@ -807,7 +802,7 @@ KeySym rundialog_keysym;
|
||||||
// flags to set if we switch modes on the fly
|
// flags to set if we switch modes on the fly
|
||||||
Window main_window = None;
|
Window main_window = None;
|
||||||
|
|
||||||
#include "textbox.c"
|
#include "textbox.h"
|
||||||
|
|
||||||
void menu_draw( textbox *text, textbox **boxes, int max_lines, int selected, char **filtered )
|
void menu_draw( textbox *text, textbox **boxes, int max_lines, int selected, char **filtered )
|
||||||
{
|
{
|
||||||
|
@ -1012,9 +1007,10 @@ int menu( char **lines, char **input, char *prompt, int selected, Time *time, in
|
||||||
// input changed
|
// input changed
|
||||||
for ( i = 0, j = 0; i < num_lines && j < max_lines; i++ ) {
|
for ( i = 0, j = 0; i < num_lines && j < max_lines; i++ ) {
|
||||||
int match = 1;
|
int match = 1;
|
||||||
|
|
||||||
// If ids provided match on that.
|
// If ids provided match on that.
|
||||||
if ( ids != NULL ) {
|
if ( ids != NULL ) {
|
||||||
client *c = window_client(ids->array[i]);
|
client *c = window_client( ids->array[i] );
|
||||||
|
|
||||||
if ( tokens ) for ( int j = 1; match && tokens[j]; j++ ) {
|
if ( tokens ) for ( int j = 1; match && tokens[j]; j++ ) {
|
||||||
int test = 0;
|
int test = 0;
|
||||||
|
@ -1294,7 +1290,7 @@ void run_switcher( int fmode )
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
winlist_append( ids, c->window, NULL);
|
winlist_append( ids, c->window, NULL );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1312,7 +1308,7 @@ void run_switcher( int fmode )
|
||||||
// final line format
|
// final line format
|
||||||
char *line = allocate( strlen( c->title ) + strlen( c->class ) + classfield + 50 );
|
char *line = allocate( strlen( c->title ) + strlen( c->class ) + classfield + 50 );
|
||||||
|
|
||||||
sprintf( line, pattern, c->class, c->title);
|
sprintf( line, pattern, c->class, c->title );
|
||||||
|
|
||||||
list[lines++] = line;
|
list[lines++] = line;
|
||||||
}
|
}
|
||||||
|
@ -1465,6 +1461,23 @@ void grab_key( unsigned int modmask, KeySym key )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Help function. This calls man.
|
||||||
|
*/
|
||||||
|
void help()
|
||||||
|
{
|
||||||
|
int code = execlp( "man","man", MANPAGE_PATH,NULL );
|
||||||
|
|
||||||
|
if ( code == -1 ) {
|
||||||
|
fprintf( stderr, "Failed to execute man: %s\n", strerror( errno ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
@ -1473,9 +1486,8 @@ int main( int argc, char *argv[] )
|
||||||
if ( find_arg( argc, argv, "-help" ) >= 0
|
if ( find_arg( argc, argv, "-help" ) >= 0
|
||||||
|| find_arg( argc, argv, "--help" ) >= 0
|
|| find_arg( argc, argv, "--help" ) >= 0
|
||||||
|| find_arg( argc, argv, "-h" ) >= 0 ) {
|
|| find_arg( argc, argv, "-h" ) >= 0 ) {
|
||||||
fprintf( stderr, "See the man (man 1 simpleswitcher) page or visit http://github.com/DaveDavenport/simpleswitcher\n" );
|
help();
|
||||||
fprintf( stderr, "Original code can be found: http://github.com/seanpringle/simpleswitcher\n" );
|
return EXIT_SUCCESS;
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *display_str= find_arg_str( argc, argv, "-display", getenv( "DISPLAY" ) );
|
const char *display_str= find_arg_str( argc, argv, "-display", getenv( "DISPLAY" ) );
|
||||||
|
@ -1520,7 +1532,6 @@ int main( int argc, char *argv[] )
|
||||||
config_menu_hlfg = find_arg_str( ac, av, "-hlfg", MENUHLFG );
|
config_menu_hlfg = find_arg_str( ac, av, "-hlfg", MENUHLFG );
|
||||||
config_menu_hlbg = find_arg_str( ac, av, "-hlbg", MENUHLBG );
|
config_menu_hlbg = find_arg_str( ac, av, "-hlbg", MENUHLBG );
|
||||||
config_menu_bc = find_arg_str( ac, av, "-bc", MENUBC );
|
config_menu_bc = find_arg_str( ac, av, "-bc", MENUBC );
|
||||||
config_menu_bw = find_arg_int( ac, av, "-bw", 1 );
|
|
||||||
config_window_opacity = find_arg_int( ac, av, "-o", 100 );
|
config_window_opacity = find_arg_int( ac, av, "-o", 100 );
|
||||||
|
|
||||||
config_zeltak_mode = ( find_arg( ac, av, "-zeltak" ) >= 0 );
|
config_zeltak_mode = ( find_arg( ac, av, "-zeltak" ) >= 0 );
|
||||||
|
|
44
textbox.c
44
textbox.c
|
@ -25,34 +25,34 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <X11/X.h>
|
||||||
|
#include <X11/Xatom.h>
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#include <X11/Xmd.h>
|
||||||
|
#include <X11/Xutil.h>
|
||||||
|
#include <X11/Xproto.h>
|
||||||
|
#include <X11/keysym.h>
|
||||||
|
#include <X11/XKBlib.h>
|
||||||
|
#include <X11/Xft/Xft.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "textbox.h"
|
||||||
#define SIDE_MARGIN 3
|
#define SIDE_MARGIN 3
|
||||||
#define TB_AUTOHEIGHT 1<<0
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
#define TB_AUTOWIDTH 1<<1
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
#define TB_LEFT 1<<16
|
|
||||||
#define TB_RIGHT 1<<17
|
|
||||||
#define TB_CENTER 1<<18
|
|
||||||
#define TB_EDITABLE 1<<19
|
|
||||||
|
|
||||||
typedef struct {
|
extern Display *display;
|
||||||
unsigned long flags;
|
|
||||||
Window window, parent;
|
|
||||||
short x, y, w, h;
|
|
||||||
short cursor;
|
|
||||||
XftFont *font;
|
|
||||||
XftColor color_fg, color_bg;
|
|
||||||
char *text, *prompt;
|
|
||||||
XIM xim;
|
|
||||||
XIC xic;
|
|
||||||
XGlyphInfo extents;
|
|
||||||
} textbox;
|
|
||||||
|
|
||||||
void textbox_font( textbox *tb, char *font, char *fg, char *bg );
|
|
||||||
void textbox_text( textbox *tb, char *text );
|
|
||||||
void textbox_moveresize( textbox *tb, int x, int y, int w, int h );
|
void textbox_moveresize( textbox *tb, int x, int y, int w, int h );
|
||||||
void textbox_cursor_end( textbox *tb );
|
|
||||||
|
|
||||||
// Xft text box, optionally editable
|
// Xft text box, optionally editable
|
||||||
textbox* textbox_create( Window parent, unsigned long flags, short x, short y, short w, short h, char *font, char *fg, char *bg, char *text, char *prompt )
|
textbox* textbox_create( Window parent,
|
||||||
|
TextboxFlags flags,
|
||||||
|
short x, short y, short w, short h,
|
||||||
|
char *font, char *fg, char *bg,
|
||||||
|
char *text, char *prompt )
|
||||||
{
|
{
|
||||||
textbox *tb = calloc( 1, sizeof( textbox ) );
|
textbox *tb = calloc( 1, sizeof( textbox ) );
|
||||||
|
|
||||||
|
|
47
textbox.h
Normal file
47
textbox.h
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#ifndef __TEXTBOX_H__
|
||||||
|
#define __TEXTBOX_H__
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned long flags;
|
||||||
|
Window window, parent;
|
||||||
|
short x, y, w, h;
|
||||||
|
short cursor;
|
||||||
|
XftFont *font;
|
||||||
|
XftColor color_fg, color_bg;
|
||||||
|
char *text, *prompt;
|
||||||
|
XIM xim;
|
||||||
|
XIC xic;
|
||||||
|
XGlyphInfo extents;
|
||||||
|
} textbox;
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TB_AUTOHEIGHT = 1<<0,
|
||||||
|
TB_AUTOWIDTH = 1<<1,
|
||||||
|
TB_LEFT = 1<<16,
|
||||||
|
TB_RIGHT = 1<<17,
|
||||||
|
TB_CENTER = 1<<18,
|
||||||
|
TB_EDITABLE = 1<<19,
|
||||||
|
} TextboxFlags;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
textbox* textbox_create( Window parent,
|
||||||
|
TextboxFlags flags,
|
||||||
|
short x, short y, short w, short h,
|
||||||
|
char *font, char *fg, char *bg,
|
||||||
|
char *text, char *prompt );
|
||||||
|
|
||||||
|
void textbox_free( textbox *tb );
|
||||||
|
|
||||||
|
void textbox_font( textbox *tb, char *font, char *fg, char *bg );
|
||||||
|
|
||||||
|
void textbox_text( textbox *tb, char *text );
|
||||||
|
void textbox_show( textbox *tb );
|
||||||
|
void textbox_draw( textbox *tb );
|
||||||
|
|
||||||
|
int textbox_keypress( textbox *tb, XEvent *ev );
|
||||||
|
|
||||||
|
void textbox_cursor_end( textbox *tb );
|
||||||
|
#endif //__TEXTBOX_H__
|
Loading…
Add table
Reference in a new issue