78 lines
1.7 KiB
C
78 lines
1.7 KiB
C
#define _XOPEN_SOURCE 700
|
|
#include <Xm/Xm.h>
|
|
#include <Xm/RowColumn.h>
|
|
#include <Xm/PushB.h>
|
|
#include <Xmd/Dir.h>
|
|
#include <Xmd/Icon.h>
|
|
#include <Xmd/Replicant.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <dirent.h>
|
|
|
|
#include "icons/icon.xbm"
|
|
|
|
XtAppContext application;
|
|
|
|
static void loadReplicants (Widget parent);
|
|
|
|
int main (int argc, char *argv[]) {
|
|
Widget window = XtVaAppInitialize (
|
|
&application, "Panel",
|
|
NULL, 0,
|
|
&argc, argv,
|
|
NULL,
|
|
XmNtitle, "Panel",
|
|
XmNiconName, "Panel",
|
|
NULL);
|
|
Pixmap iconPixmap = XmdLoadBitmapIcon(window, icon);
|
|
XtVaSetValues (
|
|
window,
|
|
XmNiconPixmap, iconPixmap,
|
|
NULL);
|
|
|
|
Widget layout = XtVaCreateWidget (
|
|
"layout", xmRowColumnWidgetClass, window,
|
|
XmNorientation, XmHORIZONTAL,
|
|
NULL);
|
|
loadReplicants(layout);
|
|
|
|
XtManageChild(layout);
|
|
XtRealizeWidget(window);
|
|
XtAppMainLoop(application);
|
|
}
|
|
|
|
static void loadReplicants (Widget parent) {
|
|
String userDir = XmdDirGetUser();
|
|
String replicantsDir = NULL;
|
|
XtAsprintf(&replicantsDir, "%s/panel", userDir);
|
|
XtFree(userDir);
|
|
|
|
struct dirent **entries = NULL;
|
|
int entriesCount = scandir(replicantsDir, &entries, NULL, alphasort);
|
|
if (entriesCount < 0) {
|
|
XtFree(replicantsDir);
|
|
/* TODO error message */
|
|
return;
|
|
}
|
|
|
|
for (int index = 0; index < entriesCount; index ++) {
|
|
struct dirent *entry = entries[index];
|
|
String point = NULL;
|
|
if ((point = strrchr(entry->d_name,'.')) != NULL) {
|
|
if (strcmp(point, ".replicant") == 0) {
|
|
String fullName = NULL;
|
|
XtAsprintf (
|
|
&fullName, "%s/%s",
|
|
replicantsDir, entry->d_name);
|
|
XmdReplicantOpen (
|
|
application, parent, fullName);
|
|
XtFree(fullName);
|
|
}
|
|
}
|
|
XtFree((char *)(entry));
|
|
}
|
|
XtFree((char *)(entries));
|
|
XtFree(replicantsDir);
|
|
}
|