can start programs now
This commit is contained in:
parent
16833ef297
commit
6f8d41fd9a
3 changed files with 128 additions and 55 deletions
|
|
@ -25,6 +25,8 @@ static void resize(MwWidget handle, void* user, void* client) {
|
||||||
int main() {
|
int main() {
|
||||||
MwRect rc;
|
MwRect rc;
|
||||||
|
|
||||||
|
signal(SIGCHLD, SIG_IGN);
|
||||||
|
|
||||||
MwLibraryInit();
|
MwLibraryInit();
|
||||||
|
|
||||||
window = MwVaCreateWidget(MwWindowClass, "window", NULL, MwDEFAULT, MwDEFAULT, 0, 0,
|
window = MwVaCreateWidget(MwWindowClass, "window", NULL, MwDEFAULT, MwDEFAULT, 0, 0,
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
/* Standard */
|
/* Standard */
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
/* main.c */
|
/* main.c */
|
||||||
extern MwWidget window, box;
|
extern MwWidget window, box;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#define TriW 5
|
#define TriW 5
|
||||||
|
|
||||||
|
|
@ -23,6 +24,7 @@ typedef struct opaque {
|
||||||
|
|
||||||
char* name;
|
char* name;
|
||||||
char* category;
|
char* category;
|
||||||
|
char* exec;
|
||||||
} opaque_t;
|
} opaque_t;
|
||||||
|
|
||||||
static int dumper(void* user, const char* section, const char* name, const char* value) {
|
static int dumper(void* user, const char* section, const char* name, const char* value) {
|
||||||
|
|
@ -33,6 +35,8 @@ static int dumper(void* user, const char* section, const char* name, const char*
|
||||||
opaque->name = MwStringDuplicate(value);
|
opaque->name = MwStringDuplicate(value);
|
||||||
} else if(strcmp(name, "Categories") == 0) {
|
} else if(strcmp(name, "Categories") == 0) {
|
||||||
opaque->category = MwStringDuplicate(value);
|
opaque->category = MwStringDuplicate(value);
|
||||||
|
} else if(strcmp(name, "Exec") == 0) {
|
||||||
|
opaque->exec = MwStringDuplicate(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -69,8 +73,7 @@ static const char* category_mapping[] = {
|
||||||
"Science",
|
"Science",
|
||||||
"Settings",
|
"Settings",
|
||||||
"System",
|
"System",
|
||||||
"Utility"
|
"Utility"};
|
||||||
};
|
|
||||||
|
|
||||||
static void call(const char* name, int dir, int symlink, void* user) {
|
static void call(const char* name, int dir, int symlink, void* user) {
|
||||||
opaque_t* opaque = user;
|
opaque_t* opaque = user;
|
||||||
|
|
@ -78,6 +81,7 @@ static void call(const char* name, int dir, int symlink, void* user){
|
||||||
|
|
||||||
opaque->name = NULL;
|
opaque->name = NULL;
|
||||||
opaque->category = NULL;
|
opaque->category = NULL;
|
||||||
|
opaque->exec = NULL;
|
||||||
ini_parse(name, dumper, user);
|
ini_parse(name, dumper, user);
|
||||||
|
|
||||||
if(opaque->category != NULL) {
|
if(opaque->category != NULL) {
|
||||||
|
|
@ -156,14 +160,77 @@ static void call(const char* name, int dir, int symlink, void* user){
|
||||||
m->keep = 0;
|
m->keep = 0;
|
||||||
m->sub = NULL;
|
m->sub = NULL;
|
||||||
m->wsub = NULL;
|
m->wsub = NULL;
|
||||||
|
m->opaque = opaque->exec;
|
||||||
|
|
||||||
arrput(mc->sub, m);
|
arrput(mc->sub, m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char** desktop_exec(const char* exec, const char* file) {
|
||||||
|
char** a = NULL;
|
||||||
|
int i;
|
||||||
|
char* buf = malloc(1);
|
||||||
|
|
||||||
|
buf[0] = 0;
|
||||||
|
|
||||||
|
for(i = 0;; i++) {
|
||||||
|
if(exec[i] == ' ' || exec[i] == 0) {
|
||||||
|
if(strlen(buf) > 0) arrput(a, buf);
|
||||||
|
|
||||||
|
buf = malloc(1);
|
||||||
|
buf[0] = 0;
|
||||||
|
|
||||||
|
if(exec[i] == 0) break;
|
||||||
|
} else if(exec[i] == '%') {
|
||||||
|
char c = exec[++i];
|
||||||
|
|
||||||
|
if(c == 'f' && file != NULL) {
|
||||||
|
char* old = buf;
|
||||||
|
|
||||||
|
buf = malloc(strlen(old) + strlen(file) + 1);
|
||||||
|
strcpy(buf, old);
|
||||||
|
strcpy(buf + strlen(old), file);
|
||||||
|
|
||||||
|
free(old);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
char* old = buf;
|
||||||
|
|
||||||
|
buf = malloc(strlen(old) + 2);
|
||||||
|
strcpy(buf, old);
|
||||||
|
buf[strlen(old)] = exec[i];
|
||||||
|
buf[strlen(old) + 1] = 0;
|
||||||
|
|
||||||
|
free(old);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
arrput(a, NULL);
|
||||||
|
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
static void menu(MwWidget handle, void* user, void* client) {
|
static void menu(MwWidget handle, void* user, void* client) {
|
||||||
opaque_t* opaque = handle->opaque;
|
opaque_t* opaque = handle->opaque;
|
||||||
|
char* s = NULL;
|
||||||
|
MwMenu m = client;
|
||||||
|
|
||||||
|
if(m->opaque != NULL) {
|
||||||
|
char** args = desktop_exec(m->opaque, NULL);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if(fork() == 0) {
|
||||||
|
execvp(args[0], args);
|
||||||
|
|
||||||
|
_exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < arrlen(args); i++) {
|
||||||
|
if(args[i] != NULL) free(args[i]);
|
||||||
|
}
|
||||||
|
arrfree(args);
|
||||||
|
}
|
||||||
|
|
||||||
if(opaque->is_opened) {
|
if(opaque->is_opened) {
|
||||||
opaque->is_opened = 0;
|
opaque->is_opened = 0;
|
||||||
|
|
@ -283,6 +350,9 @@ void module(MwWidget box, config_setting_t* setting) {
|
||||||
|
|
||||||
MDEDirectoryScan(DATAROOTDIR "/applications", call, opaque);
|
MDEDirectoryScan(DATAROOTDIR "/applications", call, opaque);
|
||||||
MDEDirectoryScan("/usr/share/applications", call, opaque);
|
MDEDirectoryScan("/usr/share/applications", call, opaque);
|
||||||
|
#if defined(__NetBSD__)
|
||||||
|
MDEDirectoryScan("/usr/pkg/share/applications", call, opaque);
|
||||||
|
#endif
|
||||||
qsort(opaque->menu->sub, arrlen(opaque->menu->sub), sizeof(MwMenu), sort_alphabet);
|
qsort(opaque->menu->sub, arrlen(opaque->menu->sub), sizeof(MwMenu), sort_alphabet);
|
||||||
|
|
||||||
for(i = 0; i < arrlen(opaque->menu->sub); i++) {
|
for(i = 0; i < arrlen(opaque->menu->sub); i++) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue