add time widget
This commit is contained in:
parent
95d3b90053
commit
b44037442a
5 changed files with 96 additions and 2 deletions
|
|
@ -14,6 +14,7 @@ endif()
|
|||
|
||||
add_subdirectory(separator)
|
||||
add_subdirectory(startbutton)
|
||||
add_subdirectory(time)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
configure_file(mpanelrc.in mpanelrc)
|
||||
|
|
|
|||
|
|
@ -40,8 +40,6 @@ void load_modules(void) {
|
|||
void (*call)(MwWidget box, config_setting_t* setting) = dlsym(lib, "module");
|
||||
|
||||
call(box, c);
|
||||
|
||||
dlclose(lib);
|
||||
}
|
||||
|
||||
free(p);
|
||||
|
|
|
|||
|
|
@ -4,5 +4,11 @@ Modules: (
|
|||
},
|
||||
{
|
||||
Type = "Separator";
|
||||
},
|
||||
{
|
||||
Type = "Separator";
|
||||
},
|
||||
{
|
||||
Type = "Time";
|
||||
}
|
||||
);
|
||||
|
|
|
|||
6
mpanel/time/CMakeLists.txt
Normal file
6
mpanel/time/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
include(MDEBase)
|
||||
include(MDEPkgConfig)
|
||||
mde_setup_library(TimeModule ${CMAKE_INSTALL_LIBDIR}/mpanel)
|
||||
|
||||
mde_pkg_config_add(TimeModule libconfig)
|
||||
|
||||
83
mpanel/time/module.c
Normal file
83
mpanel/time/module.c
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
#include <Mw/Milsko.h>
|
||||
#include <libconfig.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
static time_t last;
|
||||
|
||||
static void tick(MwWidget handle, void* user, void* client) {
|
||||
MwWidget* children = MwGetChildren(handle);
|
||||
int i;
|
||||
time_t t = time(NULL);
|
||||
struct tm* tm;
|
||||
|
||||
if(t == last) return;
|
||||
last = t;
|
||||
|
||||
tm = localtime(&t);
|
||||
|
||||
for(i = 0; children[i] != NULL; i++) {
|
||||
const char* n = MwGetName(children[i]);
|
||||
if(strcmp(n, "seg") == 0) {
|
||||
char buf[16];
|
||||
|
||||
sprintf(buf, "%02d:%02d", tm->tm_hour, tm->tm_min);
|
||||
|
||||
MwVaApply(children[i],
|
||||
MwNtext, buf,
|
||||
NULL);
|
||||
} else if(strcmp(n, "date") == 0) {
|
||||
char buf[16];
|
||||
const char* mon[] = {
|
||||
"Jan",
|
||||
"Feb",
|
||||
"Mar",
|
||||
"Apr",
|
||||
"May",
|
||||
"Jun",
|
||||
"Jul",
|
||||
"Aug",
|
||||
"Sep",
|
||||
"Oct",
|
||||
"Nov",
|
||||
"Dec"};
|
||||
|
||||
sprintf(buf, "%s %.2d", mon[tm->tm_mon], tm->tm_mday);
|
||||
|
||||
MwVaApply(children[i],
|
||||
MwNtext, buf,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
|
||||
free(children);
|
||||
}
|
||||
|
||||
void module(MwWidget box, config_setting_t* setting) {
|
||||
MwWidget b = MwVaCreateWidget(MwBoxClass, "time", box, 0, 0, 0, 0,
|
||||
MwNfixedSize, 64,
|
||||
MwNbackground, "#bebdb2",
|
||||
MwNforeground, "#484841",
|
||||
MwNorientation, MwVERTICAL,
|
||||
MwNhasBorder, 1,
|
||||
MwNinverted, 1,
|
||||
MwNborderWidth, 1,
|
||||
NULL);
|
||||
MwWidget seg = MwVaCreateWidget(MwLabelClass, "seg", b, 0, 0, 0, 0,
|
||||
MwNsevenSegment, 1,
|
||||
MwNtext, "00:00",
|
||||
MwNratio, 5,
|
||||
NULL);
|
||||
MwWidget date = MwVaCreateWidget(MwLabelClass, "date", b, 0, 0, 0, 0,
|
||||
MwNtext, "??? ??",
|
||||
MwNratio, 3,
|
||||
NULL);
|
||||
|
||||
last = 0;
|
||||
tick(b, NULL, NULL);
|
||||
|
||||
MwAddUserHandler(b, MwNtickHandler, tick, NULL);
|
||||
|
||||
MwAddTickList(b);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue