mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
Use XDG basedir for CACHE.
This commit is contained in:
parent
f24b5ef19a
commit
6e242c197e
5 changed files with 33 additions and 27 deletions
4
Makefile
4
Makefile
|
@ -47,8 +47,8 @@ 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
|
||||||
|
|
||||||
CFLAGS+=$(shell ${PKG_CONFIG} --cflags x11 xinerama xft)
|
CFLAGS+=$(shell ${PKG_CONFIG} --cflags x11 xinerama xft libxdg-basedir)
|
||||||
LDADD+=$(shell ${PKG_CONFIG} --libs x11 xinerama xft)
|
LDADD+=$(shell ${PKG_CONFIG} --libs x11 xinerama xft libxdg-basedir)
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
#ifndef __SIMPLESWITCHER_H__
|
#ifndef __SIMPLESWITCHER_H__
|
||||||
#define __SIMPLESWITCHER_H__
|
#define __SIMPLESWITCHER_H__
|
||||||
|
|
||||||
|
#include <basedir.h>
|
||||||
|
|
||||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
#define NEAR(a,o,b) ((b) > (a)-(o) && (b) < (a)+(o))
|
#define NEAR(a,o,b) ((b) > (a)-(o) && (b) < (a)+(o))
|
||||||
#define OVERLAP(a,b,c,d) (((a)==(c) && (b)==(d)) || MIN((a)+(b), (c)+(d)) - MAX((a), (c)) > 0)
|
#define OVERLAP(a,b,c,d) (((a)==(c) && (b)==(d)) || MIN((a)+(b), (c)+(d)) - MAX((a), (c)) > 0)
|
||||||
#define INTERSECT(x,y,w,h,x1,y1,w1,h1) (OVERLAP((x),(w),(x1),(w1)) && OVERLAP((y),(h),(y1),(h1)))
|
#define INTERSECT(x,y,w,h,x1,y1,w1,h1) (OVERLAP((x),(w),(x1),(w1)) && OVERLAP((y),(h),(y1),(h1)))
|
||||||
|
|
||||||
|
extern const char *cache_dir;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
WINDOW_SWITCHER,
|
WINDOW_SWITCHER,
|
||||||
|
|
|
@ -44,6 +44,8 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define RUN_CACHE_FILE "simpleswitcher.runcache"
|
||||||
|
|
||||||
static inline int execsh( const char *cmd ,int run_in_term )
|
static inline int execsh( const char *cmd ,int run_in_term )
|
||||||
{
|
{
|
||||||
// use sh for args parsing
|
// use sh for args parsing
|
||||||
|
@ -69,16 +71,13 @@ static pid_t exec_cmd( const char *cmd, int run_in_term )
|
||||||
int curr = -1;
|
int curr = -1;
|
||||||
unsigned int index = 0;
|
unsigned int index = 0;
|
||||||
char **retv = NULL;
|
char **retv = NULL;
|
||||||
const char *hd = getenv( "HOME" );
|
|
||||||
|
|
||||||
if ( hd == NULL ) return pid;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This happens in non-critical time (After launching app)
|
* This happens in non-critical time (After launching app)
|
||||||
* It is allowed to be a bit slower.
|
* It is allowed to be a bit slower.
|
||||||
*/
|
*/
|
||||||
char *path = allocate( strlen( hd ) + strlen( "/.simpleswitcher.cache" )+2 );
|
char *path = allocate( strlen( cache_dir ) + strlen( RUN_CACHE_FILE )+3 );
|
||||||
sprintf( path, "%s/%s", hd, ".simpleswitcher.cache" );
|
sprintf( path, "%s/%s", cache_dir, RUN_CACHE_FILE );
|
||||||
FILE *fd = fopen ( path, "r" );
|
FILE *fd = fopen ( path, "r" );
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
|
||||||
|
@ -148,12 +147,9 @@ static char ** get_apps ( )
|
||||||
|
|
||||||
if ( getenv( "PATH" ) == NULL ) return NULL;
|
if ( getenv( "PATH" ) == NULL ) return NULL;
|
||||||
|
|
||||||
const char *hd = getenv( "HOME" );
|
|
||||||
|
|
||||||
if ( hd == NULL ) return NULL;
|
path = allocate( strlen( cache_dir ) + strlen( RUN_CACHE_FILE )+3 );
|
||||||
|
sprintf( path, "%s/%s", cache_dir, RUN_CACHE_FILE );
|
||||||
path = allocate( strlen( hd ) + strlen( "/.simpleswitcher.cache" )+2 );
|
|
||||||
sprintf( path, "%s/%s", hd, ".simpleswitcher.cache" );
|
|
||||||
FILE *fd = fopen ( path, "r" );
|
FILE *fd = fopen ( path, "r" );
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
#include <X11/Xft/Xft.h>
|
#include <X11/Xft/Xft.h>
|
||||||
#include <X11/extensions/Xinerama.h>
|
#include <X11/extensions/Xinerama.h>
|
||||||
|
|
||||||
|
|
||||||
#ifdef I3
|
#ifdef I3
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <linux/un.h>
|
#include <linux/un.h>
|
||||||
|
@ -69,6 +70,9 @@
|
||||||
#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"
|
||||||
|
|
||||||
|
xdgHandle xdg_handle;
|
||||||
|
const char *cache_dir = NULL;
|
||||||
|
|
||||||
|
|
||||||
Settings config = {
|
Settings config = {
|
||||||
// Window settings
|
// Window settings
|
||||||
|
@ -1261,6 +1265,15 @@ int main( int argc, char *argv[] )
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(xdgInitHandle(&xdg_handle) == NULL) {
|
||||||
|
fprintf(stderr, "Failed to initialize XDG\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
cache_dir = xdgCacheHome(&xdg_handle);
|
||||||
|
printf("Cache directory: %s\n", cache_dir);
|
||||||
|
|
||||||
|
|
||||||
signal( SIGCHLD, catch_exit );
|
signal( SIGCHLD, catch_exit );
|
||||||
screen = DefaultScreenOfDisplay( display );
|
screen = DefaultScreenOfDisplay( display );
|
||||||
screen_id = DefaultScreen( display );
|
screen_id = DefaultScreen( display );
|
||||||
|
@ -1377,5 +1390,6 @@ int main( int argc, char *argv[] )
|
||||||
if ( i3_socket_path != NULL ) free( i3_socket_path );
|
if ( i3_socket_path != NULL ) free( i3_socket_path );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
xdgWipeHandle(&xdg_handle);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SSH_CACHE_FILE ".simpleswitcher.sshcache"
|
#define SSH_CACHE_FILE "simpleswitcher.sshcache"
|
||||||
|
|
||||||
static inline int execshssh( const char *host )
|
static inline int execshssh( const char *host )
|
||||||
{
|
{
|
||||||
|
@ -68,16 +68,13 @@ static pid_t exec_ssh( const char *cmd )
|
||||||
int curr = -1;
|
int curr = -1;
|
||||||
unsigned int index = 0;
|
unsigned int index = 0;
|
||||||
char **retv = NULL;
|
char **retv = NULL;
|
||||||
const char *hd = getenv( "HOME" );
|
|
||||||
|
|
||||||
if ( hd == NULL ) return pid;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This happens in non-critical time (After launching app)
|
* This happens in non-critical time (After launching app)
|
||||||
* It is allowed to be a bit slower.
|
* It is allowed to be a bit slower.
|
||||||
*/
|
*/
|
||||||
char *path = allocate( strlen( hd ) + strlen( "/"SSH_CACHE_FILE )+2 );
|
char *path = allocate( strlen( cache_dir ) + strlen( SSH_CACHE_FILE )+3 );
|
||||||
sprintf( path, "%s/%s", hd, SSH_CACHE_FILE );
|
sprintf( path, "%s/%s", cache_dir, SSH_CACHE_FILE );
|
||||||
FILE *fd = fopen ( path, "r" );
|
FILE *fd = fopen ( path, "r" );
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
|
||||||
|
@ -145,14 +142,10 @@ static char ** get_ssh ( )
|
||||||
clock_gettime( CLOCK_REALTIME, &start );
|
clock_gettime( CLOCK_REALTIME, &start );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( getenv( "PATH" ) == NULL ) return NULL;
|
if ( getenv( "HOME" ) == NULL ) return NULL;
|
||||||
|
|
||||||
const char *hd = getenv( "HOME" );
|
path = allocate( strlen( cache_dir ) + strlen( "/"SSH_CACHE_FILE )+2 );
|
||||||
|
sprintf( path, "%s/%s", cache_dir, SSH_CACHE_FILE );
|
||||||
if ( hd == NULL ) return NULL;
|
|
||||||
|
|
||||||
path = allocate( strlen( hd ) + strlen( "/"SSH_CACHE_FILE )+2 );
|
|
||||||
sprintf( path, "%s/%s", hd, SSH_CACHE_FILE );
|
|
||||||
FILE *fd = fopen ( path, "r" );
|
FILE *fd = fopen ( path, "r" );
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
|
||||||
|
@ -170,8 +163,8 @@ static char ** get_ssh ( )
|
||||||
}
|
}
|
||||||
|
|
||||||
free( path );
|
free( path );
|
||||||
|
const char *hd = getenv("HOME");
|
||||||
path = allocate( strlen( hd ) + strlen( "/.ssh/config" )+2 );
|
path = allocate( strlen( hd ) + strlen( ".ssh/config" )+3 );
|
||||||
sprintf( path, "%s/%s", hd, ".ssh/config" );
|
sprintf( path, "%s/%s", hd, ".ssh/config" );
|
||||||
fd = fopen ( path, "r" );
|
fd = fopen ( path, "r" );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue