2018-04-17 14:03:19 +03:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
|
|
|
* This file is part of ToaruOS and is released under the terms
|
|
|
|
* of the NCSA / University of Illinois License - see LICENSE.md
|
2018-05-01 11:12:56 +03:00
|
|
|
* Copyright (C) 2013-2018 K. Lange
|
2018-04-17 14:03:19 +03:00
|
|
|
*
|
|
|
|
* Yutani Panel
|
|
|
|
*
|
2018-08-15 09:47:03 +03:00
|
|
|
* Provides an applications menu, a window list, status widgets,
|
|
|
|
* and a clock, manages the user session, and provides alt-tab
|
|
|
|
* window switching and alt-f2 app runner.
|
2018-04-17 14:03:19 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
2021-06-06 12:34:24 +03:00
|
|
|
#include <dirent.h>
|
2021-06-23 16:44:44 +03:00
|
|
|
#include <pthread.h>
|
2018-04-17 14:03:19 +03:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
2018-08-02 07:13:27 +03:00
|
|
|
#include <sys/fswait.h>
|
2021-06-06 12:34:24 +03:00
|
|
|
#include <sys/socket.h>
|
2021-06-10 14:20:55 +03:00
|
|
|
#include <net/if.h>
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
#include <toaru/yutani.h>
|
|
|
|
#include <toaru/graphics.h>
|
|
|
|
#include <toaru/hashmap.h>
|
|
|
|
#include <toaru/spinlock.h>
|
2018-04-24 14:25:42 +03:00
|
|
|
#include <toaru/icon_cache.h>
|
2018-04-24 15:32:39 +03:00
|
|
|
#include <toaru/menu.h>
|
2021-07-06 03:39:52 +03:00
|
|
|
#include <toaru/text.h>
|
2018-04-17 14:03:19 +03:00
|
|
|
#include <kernel/mod/sound.h>
|
|
|
|
|
2021-06-23 15:19:16 +03:00
|
|
|
#define PANEL_HEIGHT 36
|
|
|
|
#define DROPDOWN_OFFSET 34
|
2018-04-17 14:03:19 +03:00
|
|
|
#define FONT_SIZE 14
|
2021-06-23 15:19:16 +03:00
|
|
|
#define TIME_LEFT 116
|
|
|
|
#define DATE_WIDTH 78
|
|
|
|
#define X_PAD 4
|
|
|
|
#define Y_PAD 4
|
|
|
|
#define ICON_Y_PAD 5
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
#define GRADIENT_HEIGHT 24
|
|
|
|
#define APP_OFFSET 140
|
2021-06-23 15:19:16 +03:00
|
|
|
#define TEXT_Y_OFFSET 6
|
2018-04-17 14:03:19 +03:00
|
|
|
#define ICON_PADDING 2
|
2018-04-25 16:04:24 +03:00
|
|
|
#define MAX_TEXT_WIDTH 180
|
2018-04-17 14:03:19 +03:00
|
|
|
#define MIN_TEXT_WIDTH 50
|
|
|
|
|
|
|
|
#define HILIGHT_COLOR rgb(142,216,255)
|
|
|
|
#define FOCUS_COLOR rgb(255,255,255)
|
|
|
|
#define TEXT_COLOR rgb(230,230,230)
|
|
|
|
#define ICON_COLOR rgb(230,230,230)
|
|
|
|
|
|
|
|
#define GRADIENT_AT(y) premultiply(rgba(72, 167, 255, ((24-(y))*160)/24))
|
|
|
|
|
|
|
|
#define ALTTAB_WIDTH 250
|
2018-04-20 14:47:50 +03:00
|
|
|
#define ALTTAB_HEIGHT 100
|
2018-04-17 14:03:19 +03:00
|
|
|
#define ALTTAB_BACKGROUND premultiply(rgba(0,0,0,150))
|
|
|
|
#define ALTTAB_OFFSET 10
|
|
|
|
|
2018-07-20 15:54:24 +03:00
|
|
|
#define ALTF2_WIDTH 400
|
|
|
|
#define ALTF2_HEIGHT 200
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
#define MAX_WINDOW_COUNT 100
|
|
|
|
|
2018-04-25 16:04:24 +03:00
|
|
|
#define TOTAL_CELL_WIDTH (title_width)
|
2018-04-17 14:03:19 +03:00
|
|
|
#define LEFT_BOUND (width - TIME_LEFT - DATE_WIDTH - ICON_PADDING - widgets_width)
|
|
|
|
|
|
|
|
#define WIDGET_WIDTH 24
|
|
|
|
#define WIDGET_RIGHT (width - TIME_LEFT - DATE_WIDTH)
|
|
|
|
#define WIDGET_POSITION(i) (WIDGET_RIGHT - WIDGET_WIDTH * (i+1))
|
|
|
|
|
2021-06-23 15:19:16 +03:00
|
|
|
#define LOGOUT_WIDTH 36
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
static yutani_t * yctx;
|
|
|
|
|
|
|
|
static gfx_context_t * ctx = NULL;
|
|
|
|
static yutani_window_t * panel = NULL;
|
|
|
|
|
|
|
|
static gfx_context_t * actx = NULL;
|
|
|
|
static yutani_window_t * alttab = NULL;
|
|
|
|
|
2018-07-20 15:54:24 +03:00
|
|
|
static gfx_context_t * a2ctx = NULL;
|
|
|
|
static yutani_window_t * alt_f2 = NULL;
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
static list_t * window_list = NULL;
|
|
|
|
static volatile int lock = 0;
|
|
|
|
static volatile int drawlock = 0;
|
|
|
|
|
|
|
|
static size_t bg_size;
|
|
|
|
static char * bg_blob;
|
|
|
|
|
|
|
|
static int width;
|
|
|
|
static int height;
|
|
|
|
|
2021-07-06 03:39:52 +03:00
|
|
|
static struct TT_Font * font = NULL;
|
|
|
|
static struct TT_Font * font_bold = NULL;
|
|
|
|
static struct TT_Font * font_mono = NULL;
|
|
|
|
static struct TT_Font * font_mono_bold = NULL;
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
static int widgets_width = 0;
|
|
|
|
static int widgets_volume_enabled = 0;
|
2018-04-18 13:24:53 +03:00
|
|
|
static int widgets_network_enabled = 0;
|
2020-03-28 17:21:38 +03:00
|
|
|
static int widgets_weather_enabled = 0;
|
2018-04-18 13:24:53 +03:00
|
|
|
|
|
|
|
static int network_status = 0;
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
static sprite_t * sprite_panel;
|
|
|
|
static sprite_t * sprite_logout;
|
|
|
|
|
|
|
|
static sprite_t * sprite_volume_mute;
|
|
|
|
static sprite_t * sprite_volume_low;
|
|
|
|
static sprite_t * sprite_volume_med;
|
|
|
|
static sprite_t * sprite_volume_high;
|
|
|
|
|
2018-04-18 13:24:53 +03:00
|
|
|
static sprite_t * sprite_net_active;
|
|
|
|
static sprite_t * sprite_net_disabled;
|
|
|
|
|
2018-04-24 15:32:39 +03:00
|
|
|
struct MenuList * appmenu;
|
2018-04-28 05:33:31 +03:00
|
|
|
struct MenuList * window_menu;
|
2018-05-19 13:58:39 +03:00
|
|
|
struct MenuList * logout_menu;
|
2018-07-20 17:08:20 +03:00
|
|
|
struct MenuList * netstat;
|
2020-03-28 13:51:52 +03:00
|
|
|
struct MenuList * calmenu;
|
2020-03-29 07:23:42 +03:00
|
|
|
struct MenuList * clockmenu;
|
2020-03-28 17:21:38 +03:00
|
|
|
struct MenuList * weather;
|
2021-06-23 15:19:16 +03:00
|
|
|
struct MenuList * volume_menu;
|
2018-04-28 05:33:31 +03:00
|
|
|
static yutani_wid_t _window_menu_wid = 0;
|
2018-04-24 15:32:39 +03:00
|
|
|
|
2018-07-21 12:36:50 +03:00
|
|
|
static int _close_enough(struct yutani_msg_window_mouse_event * me) {
|
|
|
|
if (me->command == YUTANI_MOUSE_EVENT_RAISE && sqrt(pow(me->new_x - me->old_x, 2) + pow(me->new_y - me->old_y, 2)) < 10) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
static int center_x(int x) {
|
|
|
|
return (width - x) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int center_y(int y) {
|
|
|
|
return (height - y) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int center_x_a(int x) {
|
|
|
|
return (ALTTAB_WIDTH - x) / 2;
|
|
|
|
}
|
|
|
|
|
2018-07-20 15:54:24 +03:00
|
|
|
static int center_x_a2(int x) {
|
|
|
|
return (ALTF2_WIDTH - x) / 2;
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
static void redraw(void);
|
|
|
|
|
|
|
|
static volatile int _continue = 1;
|
|
|
|
|
|
|
|
struct window_ad {
|
|
|
|
yutani_wid_t wid;
|
|
|
|
uint32_t flags;
|
|
|
|
char * name;
|
|
|
|
char * icon;
|
|
|
|
char * strings;
|
|
|
|
int left;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char * icon;
|
|
|
|
char * appname;
|
|
|
|
char * title;
|
|
|
|
} application_t;
|
|
|
|
|
|
|
|
/* Windows, indexed by list order */
|
|
|
|
static struct window_ad * ads_by_l[MAX_WINDOW_COUNT+1] = {NULL};
|
|
|
|
/* Windows, indexed by z-order */
|
|
|
|
static struct window_ad * ads_by_z[MAX_WINDOW_COUNT+1] = {NULL};
|
|
|
|
|
|
|
|
static int focused_app = -1;
|
|
|
|
static int active_window = -1;
|
|
|
|
static int was_tabbing = 0;
|
|
|
|
static int new_focused = -1;
|
|
|
|
|
|
|
|
static int title_width = 0;
|
|
|
|
|
|
|
|
static void toggle_hide_panel(void) {
|
|
|
|
static int panel_hidden = 0;
|
|
|
|
|
|
|
|
if (panel_hidden) {
|
|
|
|
/* Unhide the panel */
|
|
|
|
for (int i = PANEL_HEIGHT-1; i >= 0; i--) {
|
|
|
|
yutani_window_move(yctx, panel, 0, -i);
|
|
|
|
usleep(10000);
|
|
|
|
}
|
|
|
|
panel_hidden = 0;
|
|
|
|
} else {
|
|
|
|
/* Hide the panel */
|
|
|
|
for (int i = 1; i <= PANEL_HEIGHT-1; i++) {
|
|
|
|
yutani_window_move(yctx, panel, 0, -i);
|
|
|
|
usleep(10000);
|
|
|
|
}
|
|
|
|
panel_hidden = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle SIGINT by telling other threads (clock) to shut down */
|
|
|
|
static void sig_int(int sig) {
|
|
|
|
printf("Received shutdown signal in panel!\n");
|
|
|
|
_continue = 0;
|
2018-10-31 12:58:10 +03:00
|
|
|
signal(SIGINT, sig_int);
|
2018-04-17 14:03:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void launch_application(char * app) {
|
|
|
|
if (!fork()) {
|
|
|
|
printf("Starting %s\n", app);
|
|
|
|
char * args[] = {"/bin/sh", "-c", app, NULL};
|
|
|
|
execvp(args[0], args);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the hover-focus window */
|
|
|
|
static void set_focused(int i) {
|
|
|
|
if (focused_app != i) {
|
|
|
|
focused_app = i;
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-28 05:33:31 +03:00
|
|
|
static void _window_menu_start_move(struct MenuEntry * self) {
|
|
|
|
if (!_window_menu_wid)
|
|
|
|
return;
|
|
|
|
yutani_focus_window(yctx, _window_menu_wid);
|
|
|
|
yutani_window_drag_start_wid(yctx, _window_menu_wid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _window_menu_start_maximize(struct MenuEntry * self) {
|
|
|
|
if (!_window_menu_wid)
|
|
|
|
return;
|
|
|
|
yutani_special_request_wid(yctx, _window_menu_wid, YUTANI_SPECIAL_REQUEST_MAXIMIZE);
|
|
|
|
yutani_focus_window(yctx, _window_menu_wid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _window_menu_close(struct MenuEntry * self) {
|
|
|
|
if (!_window_menu_wid)
|
|
|
|
return;
|
|
|
|
yutani_focus_window(yctx, _window_menu_wid);
|
|
|
|
yutani_special_request_wid(yctx, _window_menu_wid, YUTANI_SPECIAL_REQUEST_PLEASE_CLOSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void window_show_menu(yutani_wid_t wid, int y, int x) {
|
|
|
|
if (window_menu->window) return;
|
|
|
|
_window_menu_wid = wid;
|
|
|
|
menu_show(window_menu, yctx);
|
|
|
|
yutani_window_move(yctx, window_menu->window, y, x);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
#define VOLUME_DEVICE_ID 0
|
|
|
|
#define VOLUME_KNOB_ID 0
|
2021-06-23 15:19:16 +03:00
|
|
|
static long volume_level = 0;
|
2018-04-17 14:03:19 +03:00
|
|
|
static int mixer = -1;
|
|
|
|
static void update_volume_level(void) {
|
|
|
|
if (mixer == -1) {
|
|
|
|
mixer = open("/dev/mixer", O_RDONLY);
|
|
|
|
}
|
|
|
|
|
|
|
|
snd_knob_value_t value = {0};
|
|
|
|
value.device = VOLUME_DEVICE_ID; /* TODO configure this somewhere */
|
|
|
|
value.id = VOLUME_KNOB_ID; /* TODO this too */
|
|
|
|
|
|
|
|
ioctl(mixer, SND_MIXER_READ_KNOB, &value);
|
|
|
|
volume_level = value.val;
|
|
|
|
}
|
|
|
|
static void volume_raise(void) {
|
2021-06-23 15:19:16 +03:00
|
|
|
volume_level += 0x10000000;
|
|
|
|
if (volume_level > 0xF0000000) volume_level = 0xFC000000;
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
snd_knob_value_t value = {0};
|
|
|
|
value.device = VOLUME_DEVICE_ID; /* TODO configure this somewhere */
|
|
|
|
value.id = VOLUME_KNOB_ID; /* TODO this too */
|
|
|
|
value.val = volume_level;
|
|
|
|
|
|
|
|
ioctl(mixer, SND_MIXER_WRITE_KNOB, &value);
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
static void volume_lower(void) {
|
2021-06-23 15:19:16 +03:00
|
|
|
volume_level -= 0x10000000;
|
|
|
|
if (volume_level < 0x0) volume_level = 0x0;
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
snd_knob_value_t value = {0};
|
|
|
|
value.device = VOLUME_DEVICE_ID; /* TODO configure this somewhere */
|
|
|
|
value.id = VOLUME_KNOB_ID; /* TODO this too */
|
|
|
|
value.val = volume_level;
|
|
|
|
|
|
|
|
ioctl(mixer, SND_MIXER_WRITE_KNOB, &value);
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2021-06-23 15:19:16 +03:00
|
|
|
static int volume_left = 0;
|
|
|
|
static void show_volume_status(void) {
|
|
|
|
if (!volume_menu) {
|
|
|
|
volume_menu = menu_create();
|
|
|
|
volume_menu->flags |= MENU_FLAG_BUBBLE_LEFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear the menu */
|
|
|
|
while (volume_menu->entries->length) {
|
|
|
|
node_t * node = list_pop(volume_menu->entries);
|
|
|
|
menu_free_entry((struct MenuEntry *)node->value);
|
|
|
|
free(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the current volume status */
|
|
|
|
char volume_level_label[100];
|
|
|
|
if (volume_level < 10) {
|
|
|
|
snprintf(volume_level_label, 99, "Volume: Muted");
|
|
|
|
} else {
|
|
|
|
snprintf(volume_level_label, 99, "Volume: %d%%", (int)(100 * ((float)volume_level / (float)0xFc000000)));
|
|
|
|
}
|
|
|
|
menu_insert(volume_menu, menu_create_normal(NULL, NULL, volume_level_label, NULL));
|
|
|
|
|
|
|
|
/* TODO Our mixer supports multiple knobs and we could show all of them. */
|
|
|
|
/* TODO We could also show a nice slider... if we had one... */
|
|
|
|
|
|
|
|
if (!volume_menu->window) {
|
|
|
|
menu_show(volume_menu, yctx);
|
|
|
|
if (volume_menu->window) {
|
|
|
|
if (volume_left + volume_menu->window->width > (unsigned int)width) {
|
|
|
|
yutani_window_move(yctx, volume_menu->window, width - volume_menu->window->width, DROPDOWN_OFFSET);
|
|
|
|
} else {
|
|
|
|
yutani_window_move(yctx, volume_menu->window, volume_left, DROPDOWN_OFFSET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-28 17:21:38 +03:00
|
|
|
static int weather_left = 0;
|
|
|
|
static struct MenuEntry_Normal * weather_title_entry;
|
|
|
|
static struct MenuEntry_Normal * weather_updated_entry;
|
|
|
|
static struct MenuEntry_Normal * weather_conditions_entry;
|
|
|
|
static struct MenuEntry_Normal * weather_humidity_entry;
|
|
|
|
static struct MenuEntry_Normal * weather_clouds_entry;
|
|
|
|
static char * weather_title_str;
|
|
|
|
static char * weather_updated_str;
|
|
|
|
static char * weather_conditions_str;
|
|
|
|
static char * weather_humidity_str;
|
|
|
|
static char * weather_clouds_str;
|
|
|
|
static char * weather_temp_str;
|
|
|
|
static int weather_status_valid = 0;
|
|
|
|
static hashmap_t * weather_icons = NULL;
|
|
|
|
static sprite_t * weather_icon = NULL;
|
|
|
|
|
|
|
|
static void update_weather_status(void) {
|
|
|
|
FILE * f = fopen("/tmp/weather-parsed.conf","r");
|
|
|
|
if (!f) {
|
|
|
|
weather_status_valid = 0;
|
|
|
|
if (widgets_weather_enabled) {
|
|
|
|
widgets_weather_enabled = 0;
|
|
|
|
/* Unshow */
|
2020-04-16 14:08:29 +03:00
|
|
|
widgets_width -= 2*WIDGET_WIDTH;
|
2020-03-28 17:21:38 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
weather_status_valid = 1;
|
|
|
|
if (!widgets_weather_enabled) {
|
|
|
|
widgets_weather_enabled = 1;
|
2020-04-16 14:08:29 +03:00
|
|
|
widgets_width += 2*WIDGET_WIDTH;
|
2020-03-28 17:21:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (weather_title_str) free(weather_title_str);
|
|
|
|
if (weather_updated_str) free(weather_updated_str);
|
|
|
|
if (weather_conditions_str) free(weather_conditions_str);
|
|
|
|
if (weather_humidity_str) free(weather_humidity_str);
|
|
|
|
if (weather_clouds_str) free(weather_clouds_str);
|
|
|
|
if (weather_temp_str) free(weather_temp_str);
|
|
|
|
|
|
|
|
/* read the entire status file */
|
|
|
|
fseek(f, 0, SEEK_END);
|
|
|
|
size_t size = ftell(f);
|
|
|
|
fseek(f, 0, SEEK_SET);
|
|
|
|
char * data = malloc(size + 1);
|
|
|
|
fread(data, size, 1, f);
|
|
|
|
data[size] = 0;
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
/* Find relevant pieces */
|
|
|
|
char * t = data;
|
|
|
|
char * temp = t;
|
|
|
|
t = strstr(t, "\n"); *t = '\0'; t++;
|
|
|
|
char * temp_r = t;
|
|
|
|
t = strstr(t, "\n"); *t = '\0'; t++;
|
|
|
|
char * conditions = t;
|
|
|
|
t = strstr(t, "\n"); *t = '\0'; t++;
|
|
|
|
char * icon = t;
|
|
|
|
t = strstr(t, "\n"); *t = '\0'; t++;
|
|
|
|
char * humidity = t;
|
|
|
|
t = strstr(t, "\n"); *t = '\0'; t++;
|
|
|
|
char * clouds = t;
|
|
|
|
t = strstr(t, "\n"); *t = '\0'; t++;
|
|
|
|
char * city = t;
|
|
|
|
t = strstr(t, "\n"); *t = '\0'; t++;
|
|
|
|
char * updated = t;
|
|
|
|
|
|
|
|
if (!weather_icons) {
|
|
|
|
weather_icons = hashmap_create(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hashmap_has(weather_icons, icon)) {
|
|
|
|
sprite_t * tmp = malloc(sizeof(sprite_t));
|
|
|
|
char path[512];
|
2020-04-24 08:30:12 +03:00
|
|
|
sprintf(path,"/usr/share/icons/weather/%s.png", icon);
|
2020-03-28 17:21:38 +03:00
|
|
|
load_sprite(tmp, path);
|
|
|
|
hashmap_set(weather_icons, icon, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
weather_icon = hashmap_get(weather_icons, icon);
|
|
|
|
|
|
|
|
char tmp[300];
|
|
|
|
sprintf(tmp, "Weather for %s", city);
|
|
|
|
weather_title_str = strdup(tmp);
|
|
|
|
sprintf(tmp, "%s", updated);
|
|
|
|
weather_updated_str = strdup(tmp);
|
|
|
|
sprintf(tmp, "%s° - %s", temp, conditions);
|
|
|
|
weather_conditions_str = strdup(tmp);
|
|
|
|
sprintf(tmp, "Humidity: %s%%", humidity);
|
|
|
|
weather_humidity_str = strdup(tmp);
|
|
|
|
sprintf(tmp, "Clouds: %s%%", clouds);
|
|
|
|
weather_clouds_str = strdup(tmp);
|
|
|
|
|
|
|
|
sprintf(tmp, "%s°", temp_r);
|
|
|
|
weather_temp_str = strdup(tmp);
|
|
|
|
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
|
2018-07-20 17:08:20 +03:00
|
|
|
static int netstat_left = 0;
|
2021-06-06 12:34:24 +03:00
|
|
|
static int netstat_count = 0;
|
|
|
|
static char netstat_data[32][1024];
|
2018-07-22 06:33:13 +03:00
|
|
|
|
2021-06-06 12:34:24 +03:00
|
|
|
static void ip_ntoa(const uint32_t src_addr, char * out) {
|
|
|
|
snprintf(out, 16, "%d.%d.%d.%d",
|
|
|
|
(src_addr & 0xFF000000) >> 24,
|
|
|
|
(src_addr & 0xFF0000) >> 16,
|
|
|
|
(src_addr & 0xFF00) >> 8,
|
|
|
|
(src_addr & 0xFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_network(const char * if_name) {
|
|
|
|
if (netstat_count >= 32) return;
|
|
|
|
|
|
|
|
char if_path[512];
|
|
|
|
snprintf(if_path, 511, "/dev/net/%s", if_name);
|
|
|
|
int netdev = open(if_path, O_RDWR);
|
|
|
|
|
|
|
|
if (netdev < 0) return;
|
|
|
|
|
|
|
|
/* Get IPv4 address */
|
|
|
|
uint32_t ip_addr;
|
2021-06-10 14:20:55 +03:00
|
|
|
if (!ioctl(netdev, SIOCGIFADDR, &ip_addr)) {
|
2021-06-06 12:34:24 +03:00
|
|
|
char ip_str[16];
|
|
|
|
ip_ntoa(ntohl(ip_addr), ip_str);
|
|
|
|
snprintf(netstat_data[netstat_count], 1023, "%s: %s", if_name, ip_str);
|
|
|
|
network_status |= 2;
|
|
|
|
} else {
|
|
|
|
snprintf(netstat_data[netstat_count], 1023, "%s: disconnected", if_name);
|
|
|
|
network_status |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(netdev);
|
|
|
|
netstat_count++;
|
|
|
|
}
|
2018-07-22 06:33:13 +03:00
|
|
|
|
2018-04-18 13:24:53 +03:00
|
|
|
static void update_network_status(void) {
|
2021-06-06 12:34:24 +03:00
|
|
|
network_status = 0;
|
|
|
|
netstat_count = 0;
|
2018-04-18 13:24:53 +03:00
|
|
|
|
2021-06-06 12:34:24 +03:00
|
|
|
DIR * d = opendir("/dev/net");
|
|
|
|
if (!d) return;
|
|
|
|
|
|
|
|
struct dirent * ent;
|
|
|
|
while ((ent = readdir(d))) {
|
|
|
|
if (ent->d_name[0] == '.') continue;
|
|
|
|
check_network(ent->d_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(d);
|
2018-04-18 13:24:53 +03:00
|
|
|
}
|
|
|
|
|
2018-07-20 15:54:24 +03:00
|
|
|
static void show_logout_menu(void) {
|
|
|
|
if (!logout_menu->window) {
|
|
|
|
menu_show(logout_menu, yctx);
|
|
|
|
if (logout_menu->window) {
|
2021-06-23 15:19:16 +03:00
|
|
|
yutani_window_move(yctx, logout_menu->window, width - logout_menu->window->width - X_PAD, DROPDOWN_OFFSET);
|
2018-07-20 15:54:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void show_app_menu(void) {
|
|
|
|
if (!appmenu->window) {
|
|
|
|
menu_show(appmenu, yctx);
|
|
|
|
if (appmenu->window) {
|
2021-06-23 15:19:16 +03:00
|
|
|
yutani_window_move(yctx, appmenu->window, X_PAD, DROPDOWN_OFFSET);
|
2018-07-20 15:54:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-28 13:51:52 +03:00
|
|
|
static void show_cal_menu(void) {
|
|
|
|
if (!calmenu->window) {
|
|
|
|
menu_show(calmenu, yctx);
|
|
|
|
if (calmenu->window) {
|
2021-06-23 15:19:16 +03:00
|
|
|
yutani_window_move(yctx, calmenu->window, width - TIME_LEFT - DATE_WIDTH / 2 - calmenu->window->width / 2, DROPDOWN_OFFSET);
|
2020-03-28 13:51:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-29 07:23:42 +03:00
|
|
|
static void show_clock_menu(void) {
|
|
|
|
if (!clockmenu->window) {
|
|
|
|
menu_show(clockmenu, yctx);
|
|
|
|
if (clockmenu->window) {
|
2021-06-23 15:19:16 +03:00
|
|
|
yutani_window_move(yctx, clockmenu->window, width - LOGOUT_WIDTH - clockmenu->window->width, DROPDOWN_OFFSET);
|
2020-03-29 07:23:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-28 17:21:38 +03:00
|
|
|
static void weather_refresh(struct MenuEntry * self) {
|
|
|
|
(void)self;
|
2020-03-28 17:55:58 +03:00
|
|
|
system("weather-tool &");
|
2020-03-28 17:21:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void weather_configure(struct MenuEntry * self) {
|
|
|
|
(void)self;
|
2020-03-28 17:27:06 +03:00
|
|
|
system("terminal sh -c \"sudo weather-configurator; weather-tool\" &");
|
2020-03-28 17:21:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void show_weather_status(void) {
|
|
|
|
if (!weather) {
|
|
|
|
weather = menu_create();
|
2021-06-23 15:19:16 +03:00
|
|
|
weather->flags |= MENU_FLAG_BUBBLE_LEFT;
|
2020-03-28 17:21:38 +03:00
|
|
|
weather_title_entry = (struct MenuEntry_Normal *)menu_create_normal(NULL, NULL, "", NULL);
|
|
|
|
menu_insert(weather, weather_title_entry);
|
|
|
|
weather_updated_entry = (struct MenuEntry_Normal *)menu_create_normal(NULL, NULL, "", NULL);
|
|
|
|
menu_insert(weather, weather_updated_entry);
|
|
|
|
menu_insert(weather, menu_create_separator());
|
|
|
|
weather_conditions_entry = (struct MenuEntry_Normal *)menu_create_normal(NULL, NULL, "", NULL);
|
|
|
|
menu_insert(weather, weather_conditions_entry);
|
|
|
|
weather_humidity_entry = (struct MenuEntry_Normal *)menu_create_normal(NULL, NULL, "", NULL);
|
|
|
|
menu_insert(weather, weather_humidity_entry);
|
|
|
|
weather_clouds_entry = (struct MenuEntry_Normal *)menu_create_normal(NULL, NULL, "", NULL);
|
|
|
|
menu_insert(weather, weather_clouds_entry);
|
|
|
|
menu_insert(weather, menu_create_separator());
|
|
|
|
menu_insert(weather, menu_create_normal("refresh", NULL, "Refresh...", weather_refresh));
|
|
|
|
menu_insert(weather, menu_create_normal("config", NULL, "Configure...", weather_configure));
|
|
|
|
menu_insert(weather, menu_create_separator());
|
|
|
|
menu_insert(weather, menu_create_normal(NULL, NULL, "Weather data provided by", NULL));
|
|
|
|
menu_insert(weather, menu_create_normal(NULL, NULL, "OpenWeatherMap.org", NULL));
|
|
|
|
}
|
|
|
|
if (weather_status_valid) {
|
|
|
|
menu_update_title(weather_title_entry, weather_title_str);
|
|
|
|
menu_update_title(weather_updated_entry, weather_updated_str);
|
|
|
|
menu_update_title(weather_conditions_entry, weather_conditions_str);
|
|
|
|
menu_update_title(weather_humidity_entry, weather_humidity_str);
|
|
|
|
menu_update_title(weather_clouds_entry, weather_clouds_str);
|
|
|
|
}
|
|
|
|
if (!weather->window) {
|
|
|
|
menu_show(weather, yctx);
|
|
|
|
if (weather->window) {
|
2021-06-23 15:19:16 +03:00
|
|
|
if (weather_left + weather->window->width > (unsigned int)width - X_PAD) {
|
|
|
|
yutani_window_move(yctx, weather->window, weather_left + WIDGET_WIDTH * 2 - weather->window->width, DROPDOWN_OFFSET);
|
|
|
|
weather->flags = (weather->flags & ~MENU_FLAG_BUBBLE) | MENU_FLAG_BUBBLE_RIGHT;
|
2020-03-28 17:21:38 +03:00
|
|
|
} else {
|
2021-06-23 15:19:16 +03:00
|
|
|
yutani_window_move(yctx, weather->window, weather_left, DROPDOWN_OFFSET);
|
|
|
|
weather->flags = (weather->flags & ~MENU_FLAG_BUBBLE) | MENU_FLAG_BUBBLE_LEFT;
|
2020-03-28 17:21:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-20 17:08:20 +03:00
|
|
|
static void show_network_status(void) {
|
|
|
|
if (!netstat) {
|
|
|
|
netstat = menu_create();
|
2021-06-23 15:19:16 +03:00
|
|
|
netstat->flags |= MENU_FLAG_BUBBLE_LEFT;
|
2018-07-20 17:08:20 +03:00
|
|
|
menu_insert(netstat, menu_create_normal(NULL, NULL, "Network Status", NULL));
|
|
|
|
menu_insert(netstat, menu_create_separator());
|
|
|
|
}
|
2021-06-06 12:34:24 +03:00
|
|
|
while (netstat->entries->length > 2) {
|
|
|
|
node_t * node = list_pop(netstat->entries);
|
|
|
|
menu_free_entry((struct MenuEntry *)node->value);
|
|
|
|
free(node);
|
|
|
|
}
|
|
|
|
if (!network_status) {
|
|
|
|
menu_insert(netstat, menu_create_normal(NULL, NULL, "No network.", NULL));
|
2018-07-20 17:08:20 +03:00
|
|
|
} else {
|
2021-06-06 12:34:24 +03:00
|
|
|
for (int i = 0; i < netstat_count; ++i) {
|
|
|
|
menu_insert(netstat, menu_create_normal(NULL, NULL, netstat_data[i], NULL));
|
|
|
|
}
|
2018-07-20 17:08:20 +03:00
|
|
|
}
|
|
|
|
if (!netstat->window) {
|
|
|
|
menu_show(netstat, yctx);
|
|
|
|
if (netstat->window) {
|
2018-07-20 17:53:45 +03:00
|
|
|
if (netstat_left + netstat->window->width > (unsigned int)width) {
|
2021-06-23 15:19:16 +03:00
|
|
|
yutani_window_move(yctx, netstat->window, width - netstat->window->width, DROPDOWN_OFFSET);
|
2018-07-20 17:53:45 +03:00
|
|
|
} else {
|
2021-06-23 15:19:16 +03:00
|
|
|
yutani_window_move(yctx, netstat->window, netstat_left, DROPDOWN_OFFSET);
|
2018-07-20 17:53:45 +03:00
|
|
|
}
|
2018-07-20 17:08:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
/* Callback for mouse events */
|
|
|
|
static void panel_check_click(struct yutani_msg_window_mouse_event * evt) {
|
|
|
|
if (evt->wid == panel->wid) {
|
2018-07-21 12:36:50 +03:00
|
|
|
if (evt->command == YUTANI_MOUSE_EVENT_CLICK || _close_enough(evt)) {
|
2018-04-17 14:03:19 +03:00
|
|
|
/* Up-down click */
|
2021-06-23 15:19:16 +03:00
|
|
|
if (evt->new_x >= width - LOGOUT_WIDTH ) {
|
2018-07-20 15:54:24 +03:00
|
|
|
show_logout_menu();
|
2018-04-17 14:03:19 +03:00
|
|
|
} else if (evt->new_x < APP_OFFSET) {
|
2018-07-20 15:54:24 +03:00
|
|
|
show_app_menu();
|
2020-03-28 13:51:52 +03:00
|
|
|
} else if (evt->new_x >= width - TIME_LEFT) {
|
2020-03-29 07:23:42 +03:00
|
|
|
show_clock_menu();
|
|
|
|
} else if (evt->new_x >= width - TIME_LEFT - DATE_WIDTH) {
|
2020-03-28 13:51:52 +03:00
|
|
|
show_cal_menu();
|
2018-04-17 14:03:19 +03:00
|
|
|
} else if (evt->new_x >= APP_OFFSET && evt->new_x < LEFT_BOUND) {
|
|
|
|
for (int i = 0; i < MAX_WINDOW_COUNT; ++i) {
|
|
|
|
if (ads_by_l[i] == NULL) break;
|
|
|
|
if (evt->new_x >= ads_by_l[i]->left && evt->new_x < ads_by_l[i]->left + TOTAL_CELL_WIDTH) {
|
|
|
|
yutani_focus_window(yctx, ads_by_l[i]->wid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-18 13:24:53 +03:00
|
|
|
int widget = 0;
|
2020-03-28 17:21:38 +03:00
|
|
|
if (widgets_weather_enabled) {
|
|
|
|
if (evt->new_x > WIDGET_POSITION(widget+1) && evt->new_x < WIDGET_POSITION(widget-1)) {
|
2021-06-23 15:19:16 +03:00
|
|
|
weather_left = WIDGET_POSITION(widget+1);
|
2020-03-28 17:21:38 +03:00
|
|
|
show_weather_status();
|
|
|
|
}
|
|
|
|
widget += 2;
|
|
|
|
}
|
2018-04-18 13:24:53 +03:00
|
|
|
if (widgets_network_enabled) {
|
|
|
|
if (evt->new_x > WIDGET_POSITION(widget) && evt->new_x < WIDGET_POSITION(widget-1)) {
|
2018-07-20 17:08:20 +03:00
|
|
|
netstat_left = WIDGET_POSITION(widget);
|
|
|
|
show_network_status();
|
2018-04-18 13:24:53 +03:00
|
|
|
}
|
|
|
|
widget++;
|
|
|
|
}
|
|
|
|
if (widgets_volume_enabled) {
|
|
|
|
if (evt->new_x > WIDGET_POSITION(widget) && evt->new_x < WIDGET_POSITION(widget-1)) {
|
2021-06-23 15:19:16 +03:00
|
|
|
volume_left = WIDGET_POSITION(widget);
|
|
|
|
show_volume_status();
|
2018-04-18 13:24:53 +03:00
|
|
|
}
|
|
|
|
widget++;
|
|
|
|
}
|
2018-04-28 05:33:31 +03:00
|
|
|
} else if (evt->buttons & YUTANI_MOUSE_BUTTON_RIGHT) {
|
|
|
|
if (evt->new_x >= APP_OFFSET && evt->new_x < LEFT_BOUND) {
|
|
|
|
for (int i = 0; i < MAX_WINDOW_COUNT; ++i) {
|
|
|
|
if (ads_by_l[i] == NULL) break;
|
|
|
|
if (evt->new_x >= ads_by_l[i]->left && evt->new_x < ads_by_l[i]->left + TOTAL_CELL_WIDTH) {
|
2021-06-23 15:19:16 +03:00
|
|
|
window_show_menu(ads_by_l[i]->wid, evt->new_x, DROPDOWN_OFFSET);
|
2018-04-28 05:33:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-17 14:03:19 +03:00
|
|
|
} else if (evt->command == YUTANI_MOUSE_EVENT_MOVE || evt->command == YUTANI_MOUSE_EVENT_ENTER) {
|
|
|
|
/* Movement, or mouse entered window */
|
|
|
|
if (evt->new_y < PANEL_HEIGHT) {
|
|
|
|
for (int i = 0; i < MAX_WINDOW_COUNT; ++i) {
|
|
|
|
if (ads_by_l[i] == NULL) {
|
|
|
|
set_focused(-1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (evt->new_x >= ads_by_l[i]->left && evt->new_x < ads_by_l[i]->left + TOTAL_CELL_WIDTH) {
|
|
|
|
set_focused(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
set_focused(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int scroll_direction = 0;
|
|
|
|
if (evt->buttons & YUTANI_MOUSE_SCROLL_UP) scroll_direction = -1;
|
|
|
|
else if (evt->buttons & YUTANI_MOUSE_SCROLL_DOWN) scroll_direction = 1;
|
|
|
|
|
|
|
|
if (scroll_direction) {
|
2018-04-18 13:24:53 +03:00
|
|
|
int widget = 0;
|
2020-03-28 17:21:38 +03:00
|
|
|
if (widgets_weather_enabled) {
|
|
|
|
if (evt->new_x > WIDGET_POSITION(widget+1) && evt->new_x < WIDGET_POSITION(widget-1)) {
|
|
|
|
/* Ignore */
|
|
|
|
}
|
|
|
|
widget += 2;
|
|
|
|
}
|
2018-04-18 13:24:53 +03:00
|
|
|
if (widgets_network_enabled) {
|
|
|
|
if (evt->new_x > WIDGET_POSITION(widget) && evt->new_x < WIDGET_POSITION(widget-1)) {
|
|
|
|
/* Ignore */
|
|
|
|
}
|
|
|
|
widget++;
|
|
|
|
}
|
|
|
|
if (widgets_volume_enabled) {
|
|
|
|
if (evt->new_x > WIDGET_POSITION(widget) && evt->new_x < WIDGET_POSITION(widget-1)) {
|
|
|
|
if (scroll_direction == 1) {
|
|
|
|
volume_lower();
|
|
|
|
} else if (scroll_direction == -1) {
|
|
|
|
volume_raise();
|
|
|
|
}
|
2018-04-17 14:03:19 +03:00
|
|
|
}
|
2018-04-18 13:24:53 +03:00
|
|
|
widget++;
|
|
|
|
}
|
|
|
|
if (evt->new_x >= APP_OFFSET && evt->new_x < LEFT_BOUND) {
|
2018-04-17 14:03:19 +03:00
|
|
|
if (scroll_direction != 0) {
|
|
|
|
struct window_ad * last = window_list->tail ? window_list->tail->value : NULL;
|
|
|
|
int focus_next = 0;
|
|
|
|
foreach(node, window_list) {
|
|
|
|
struct window_ad * ad = node->value;
|
|
|
|
if (focus_next) {
|
|
|
|
yutani_focus_window(yctx, ad->wid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ad->flags & 1) {
|
|
|
|
if (scroll_direction == -1) {
|
|
|
|
yutani_focus_window(yctx, last->wid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (scroll_direction == 1) {
|
|
|
|
focus_next = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
last = ad;
|
|
|
|
}
|
|
|
|
if (focus_next && window_list->head) {
|
|
|
|
struct window_ad * ad = window_list->head->value;
|
|
|
|
yutani_focus_window(yctx, ad->wid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (evt->command == YUTANI_MOUSE_EVENT_LEAVE) {
|
|
|
|
/* Mouse left panel window */
|
|
|
|
set_focused(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-20 15:54:24 +03:00
|
|
|
static char altf2_buffer[1024] = {0};
|
|
|
|
static unsigned int altf2_collected = 0;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static list_t * altf2_apps = NULL;
|
|
|
|
|
|
|
|
struct altf2_app {
|
|
|
|
char * name;
|
|
|
|
sprite_t * icon;
|
|
|
|
};
|
|
|
|
|
|
|
|
static sprite_t * find_icon(char * name) {
|
|
|
|
struct {
|
|
|
|
char * name;
|
|
|
|
char * icon;
|
|
|
|
} special[] = {
|
|
|
|
{"about", "star"},
|
|
|
|
{"help-browser", "help"},
|
|
|
|
{"terminal", "utilities-terminal"},
|
|
|
|
{NULL,NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
while (special[i].name) {
|
|
|
|
if (!strcmp(special[i].name, name)) {
|
|
|
|
return icon_get_48(special[i].icon);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return icon_get_48(name);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void close_altf2(void) {
|
|
|
|
free(a2ctx->backbuffer);
|
|
|
|
free(a2ctx);
|
|
|
|
|
|
|
|
altf2_buffer[0] = 0;
|
|
|
|
altf2_collected = 0;
|
|
|
|
|
|
|
|
yutani_close(yctx, alt_f2);
|
|
|
|
alt_f2 = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void redraw_altf2(void) {
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (!altf2_apps) {
|
|
|
|
/* initialize */
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
draw_fill(a2ctx, 0);
|
|
|
|
draw_rounded_rectangle(a2ctx,0,0, ALTF2_WIDTH, ALTF2_HEIGHT, 10, ALTTAB_BACKGROUND);
|
|
|
|
|
2021-07-06 03:39:52 +03:00
|
|
|
tt_set_size(font, 20);
|
|
|
|
int t = tt_string_width(font, altf2_buffer);
|
|
|
|
tt_draw_string(a2ctx, font, center_x_a2(t), 80, altf2_buffer, rgb(255,255,255));
|
2018-07-20 15:54:24 +03:00
|
|
|
|
|
|
|
flip(a2ctx);
|
|
|
|
yutani_flip(yctx, alt_f2);
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
static void redraw_alttab(void) {
|
|
|
|
/* Draw the background, right now just a dark semi-transparent box */
|
2018-07-20 15:54:24 +03:00
|
|
|
draw_fill(actx, 0);
|
|
|
|
draw_rounded_rectangle(actx,0,0, ALTTAB_WIDTH, ALTTAB_HEIGHT, 10, ALTTAB_BACKGROUND);
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
if (ads_by_z[new_focused]) {
|
|
|
|
struct window_ad * ad = ads_by_z[new_focused];
|
|
|
|
|
2018-04-20 14:47:50 +03:00
|
|
|
sprite_t * icon = icon_get_48(ad->icon);
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
/* Draw it, scaled if necessary */
|
2018-04-20 14:47:50 +03:00
|
|
|
if (icon->width == 48) {
|
|
|
|
draw_sprite(actx, icon, center_x_a(48), ALTTAB_OFFSET);
|
2018-04-17 14:03:19 +03:00
|
|
|
} else {
|
2018-04-20 14:47:50 +03:00
|
|
|
draw_sprite_scaled(actx, icon, center_x_a(48), ALTTAB_OFFSET, 48, 48);
|
2018-04-17 14:03:19 +03:00
|
|
|
}
|
|
|
|
|
2021-07-06 03:39:52 +03:00
|
|
|
tt_set_size(font, 16);
|
|
|
|
int t = tt_string_width(font, ad->name);
|
|
|
|
tt_draw_string(actx, font, center_x_a(t), 12 + ALTTAB_OFFSET + 40 + 16, ad->name, rgb(255,255,255));
|
2018-04-17 14:03:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
flip(actx);
|
|
|
|
yutani_flip(yctx, alttab);
|
|
|
|
}
|
|
|
|
|
2021-06-23 16:44:44 +03:00
|
|
|
static pthread_t _waiter_thread;
|
|
|
|
static void * logout_prompt_waiter(void * arg) {
|
|
|
|
if (system("showdialog \"Log Out\" /usr/share/icons/48/exit.png \"Are you sure you want to log out?\"") == 0) {
|
|
|
|
yutani_session_end(yctx);
|
|
|
|
_continue = 0;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-04-24 15:32:39 +03:00
|
|
|
static void launch_application_menu(struct MenuEntry * self) {
|
|
|
|
struct MenuEntry_Normal * _self = (void *)self;
|
|
|
|
|
2018-05-19 13:58:39 +03:00
|
|
|
if (!strcmp((char *)_self->action,"log-out")) {
|
2021-06-23 16:44:44 +03:00
|
|
|
/* Spin off a thread for this */
|
|
|
|
pthread_create(&_waiter_thread, NULL, logout_prompt_waiter, NULL);
|
2018-05-19 13:58:39 +03:00
|
|
|
} else {
|
|
|
|
launch_application((char *)_self->action);
|
|
|
|
}
|
2018-04-24 15:32:39 +03:00
|
|
|
}
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
static void handle_key_event(struct yutani_msg_key_event * ke) {
|
2018-07-20 15:54:24 +03:00
|
|
|
if (alt_f2 && ke->wid == alt_f2->wid) {
|
|
|
|
if (ke->event.action == KEY_ACTION_DOWN) {
|
|
|
|
if (ke->event.keycode == KEY_ESCAPE) {
|
|
|
|
close_altf2();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ke->event.key == '\b') {
|
|
|
|
if (altf2_collected) {
|
|
|
|
altf2_buffer[altf2_collected-1] = '\0';
|
|
|
|
altf2_collected--;
|
|
|
|
redraw_altf2();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ke->event.key == '\n') {
|
|
|
|
/* execute */
|
|
|
|
launch_application(altf2_buffer);
|
|
|
|
close_altf2();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!ke->event.key) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to add it */
|
|
|
|
if (altf2_collected < sizeof(altf2_buffer) - 1) {
|
|
|
|
altf2_buffer[altf2_collected] = ke->event.key;
|
|
|
|
altf2_collected++;
|
|
|
|
altf2_buffer[altf2_collected] = 0;
|
|
|
|
redraw_altf2();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
if ((ke->event.modifiers & KEY_MOD_LEFT_CTRL) &&
|
|
|
|
(ke->event.modifiers & KEY_MOD_LEFT_ALT) &&
|
|
|
|
(ke->event.keycode == 't') &&
|
|
|
|
(ke->event.action == KEY_ACTION_DOWN)) {
|
|
|
|
|
2018-09-22 16:37:47 +03:00
|
|
|
launch_application("exec terminal");
|
2018-07-20 15:54:24 +03:00
|
|
|
return;
|
2018-04-17 14:03:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((ke->event.modifiers & KEY_MOD_LEFT_CTRL) &&
|
|
|
|
(ke->event.keycode == KEY_F11) &&
|
|
|
|
(ke->event.action == KEY_ACTION_DOWN)) {
|
2018-07-20 15:54:24 +03:00
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
fprintf(stderr, "[panel] Toggling visibility.\n");
|
|
|
|
toggle_hide_panel();
|
2018-07-20 15:54:24 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ke->event.modifiers & KEY_MOD_LEFT_ALT) &&
|
|
|
|
(ke->event.keycode == KEY_F1) &&
|
|
|
|
(ke->event.action == KEY_ACTION_DOWN)) {
|
|
|
|
/* show menu */
|
|
|
|
show_app_menu();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ke->event.modifiers & KEY_MOD_LEFT_ALT) &&
|
|
|
|
(ke->event.keycode == KEY_F2) &&
|
|
|
|
(ke->event.action == KEY_ACTION_DOWN)) {
|
|
|
|
/* show menu */
|
|
|
|
if (!alt_f2) {
|
|
|
|
alt_f2 = yutani_window_create(yctx, ALTF2_WIDTH, ALTF2_HEIGHT);
|
|
|
|
yutani_window_move(yctx, alt_f2, center_x(ALTF2_WIDTH), center_y(ALTF2_HEIGHT));
|
|
|
|
a2ctx = init_graphics_yutani_double_buffer(alt_f2);
|
|
|
|
redraw_altf2();
|
|
|
|
}
|
2018-04-17 14:03:19 +03:00
|
|
|
}
|
|
|
|
|
2018-12-23 12:12:55 +03:00
|
|
|
if ((ke->event.modifiers & KEY_MOD_LEFT_ALT) &&
|
|
|
|
(ke->event.keycode == KEY_F3) &&
|
|
|
|
(ke->event.action == KEY_ACTION_DOWN)) {
|
|
|
|
for (int i = 0; i < MAX_WINDOW_COUNT; ++i) {
|
|
|
|
if (ads_by_l[i] == NULL) break;
|
|
|
|
if (ads_by_l[i]->flags & 1) {
|
2021-06-23 15:19:16 +03:00
|
|
|
window_show_menu(ads_by_l[i]->wid, ads_by_l[i]->left, DROPDOWN_OFFSET);
|
2018-12-23 12:12:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
if ((was_tabbing) && (ke->event.keycode == 0 || ke->event.keycode == KEY_LEFT_ALT) &&
|
|
|
|
(ke->event.modifiers == 0) && (ke->event.action == KEY_ACTION_UP)) {
|
|
|
|
|
|
|
|
fprintf(stderr, "[panel] Stopping focus new_focused = %d\n", new_focused);
|
|
|
|
|
|
|
|
struct window_ad * ad = ads_by_z[new_focused];
|
|
|
|
|
|
|
|
if (!ad) return;
|
|
|
|
|
|
|
|
yutani_focus_window(yctx, ad->wid);
|
|
|
|
was_tabbing = 0;
|
|
|
|
new_focused = -1;
|
|
|
|
|
|
|
|
free(actx->backbuffer);
|
|
|
|
free(actx);
|
|
|
|
|
|
|
|
yutani_close(yctx, alttab);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ke->event.modifiers & KEY_MOD_LEFT_ALT) &&
|
|
|
|
(ke->event.keycode == '\t') &&
|
|
|
|
(ke->event.action == KEY_ACTION_DOWN)) {
|
|
|
|
|
|
|
|
int direction = (ke->event.modifiers & KEY_MOD_LEFT_SHIFT) ? 1 : -1;
|
|
|
|
|
|
|
|
if (window_list->length < 1) return;
|
|
|
|
|
|
|
|
if (was_tabbing) {
|
|
|
|
new_focused = new_focused + direction;
|
|
|
|
} else {
|
|
|
|
new_focused = active_window + direction;
|
|
|
|
/* Create tab window */
|
|
|
|
alttab = yutani_window_create(yctx, ALTTAB_WIDTH, ALTTAB_HEIGHT);
|
|
|
|
|
|
|
|
/* Center window */
|
|
|
|
yutani_window_move(yctx, alttab, center_x(ALTTAB_WIDTH), center_y(ALTTAB_HEIGHT));
|
|
|
|
|
|
|
|
/* Initialize graphics context against the window */
|
|
|
|
actx = init_graphics_yutani_double_buffer(alttab);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_focused < 0) {
|
|
|
|
new_focused = 0;
|
|
|
|
for (int i = 0; i < MAX_WINDOW_COUNT; i++) {
|
|
|
|
if (ads_by_z[i+1] == NULL) {
|
|
|
|
new_focused = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (ads_by_z[new_focused] == NULL) {
|
|
|
|
new_focused = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
was_tabbing = 1;
|
|
|
|
|
|
|
|
redraw_alttab();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void redraw(void) {
|
|
|
|
spin_lock(&drawlock);
|
|
|
|
|
|
|
|
struct timeval now;
|
|
|
|
struct tm * timeinfo;
|
|
|
|
char buffer[80];
|
|
|
|
|
|
|
|
uint32_t txt_color = TEXT_COLOR;
|
|
|
|
int t = 0;
|
|
|
|
|
|
|
|
/* Redraw the background */
|
|
|
|
memcpy(ctx->backbuffer, bg_blob, bg_size);
|
|
|
|
|
|
|
|
/* Get the current time for the clock */
|
|
|
|
gettimeofday(&now, NULL);
|
|
|
|
timeinfo = localtime((time_t *)&now.tv_sec);
|
|
|
|
|
|
|
|
/* Hours : Minutes : Seconds */
|
|
|
|
strftime(buffer, 80, "%H:%M:%S", timeinfo);
|
2021-07-06 15:14:28 +03:00
|
|
|
tt_set_size(font, 16);
|
2021-07-06 03:39:52 +03:00
|
|
|
tt_draw_string(ctx, font, width - TIME_LEFT, 3 + Y_PAD + 17, buffer, clockmenu->window ? HILIGHT_COLOR : txt_color);
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
/* Day-of-week */
|
|
|
|
strftime(buffer, 80, "%A", timeinfo);
|
2021-07-06 03:39:52 +03:00
|
|
|
tt_set_size(font, 11);
|
|
|
|
t = tt_string_width(font, buffer);
|
2018-04-17 14:03:19 +03:00
|
|
|
t = (DATE_WIDTH - t) / 2;
|
2021-07-06 03:39:52 +03:00
|
|
|
tt_draw_string(ctx, font, width - TIME_LEFT - DATE_WIDTH + t, 2 + Y_PAD + 11, buffer, calmenu->window ? HILIGHT_COLOR : txt_color);
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
/* Month Day */
|
|
|
|
strftime(buffer, 80, "%h %e", timeinfo);
|
2021-07-06 03:39:52 +03:00
|
|
|
tt_set_size(font_bold, 11);
|
|
|
|
t = tt_string_width(font_bold, buffer);
|
2018-04-17 14:03:19 +03:00
|
|
|
t = (DATE_WIDTH - t) / 2;
|
2021-07-06 03:39:52 +03:00
|
|
|
tt_draw_string(ctx, font_bold, width - TIME_LEFT - DATE_WIDTH + t, 12 + Y_PAD + 11, buffer, calmenu->window ? HILIGHT_COLOR : txt_color);
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
/* Applications menu */
|
2021-07-06 15:14:28 +03:00
|
|
|
tt_set_size(font, 16);
|
|
|
|
tt_draw_string(ctx, font, 16, 3 + Y_PAD + 17, "Applications", appmenu->window ? HILIGHT_COLOR : txt_color);
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
/* Draw each widget */
|
2018-04-18 13:24:53 +03:00
|
|
|
int widget = 0;
|
2020-03-28 17:21:38 +03:00
|
|
|
/* Weather */
|
|
|
|
if (widgets_weather_enabled) {
|
|
|
|
uint32_t color = (weather && weather->window) ? HILIGHT_COLOR : ICON_COLOR;
|
2021-07-06 03:39:52 +03:00
|
|
|
tt_set_size(font, 12);
|
|
|
|
int t = tt_string_width(font, weather_temp_str);
|
|
|
|
tt_draw_string(ctx, font, WIDGET_POSITION(widget) + (WIDGET_WIDTH - t) / 2, 5 + Y_PAD + 12, weather_temp_str, color);
|
2021-06-23 15:19:16 +03:00
|
|
|
draw_sprite_alpha_paint(ctx, weather_icon, WIDGET_POSITION(widget+1), ICON_Y_PAD, 1.0, color);
|
2020-03-28 17:21:38 +03:00
|
|
|
widget += 2;
|
|
|
|
}
|
|
|
|
/* - Network */
|
2018-04-18 13:24:53 +03:00
|
|
|
if (widgets_network_enabled) {
|
2018-07-20 17:14:39 +03:00
|
|
|
uint32_t color = (netstat && netstat->window) ? HILIGHT_COLOR : ICON_COLOR;
|
2021-06-06 12:34:24 +03:00
|
|
|
if (network_status & 2) {
|
2021-06-23 15:19:16 +03:00
|
|
|
draw_sprite_alpha_paint(ctx, sprite_net_active, WIDGET_POSITION(widget), ICON_Y_PAD, 1.0, color);
|
2018-04-18 13:24:53 +03:00
|
|
|
} else {
|
2021-06-23 15:19:16 +03:00
|
|
|
draw_sprite_alpha_paint(ctx, sprite_net_disabled, WIDGET_POSITION(widget), ICON_Y_PAD, 1.0, color);
|
2018-04-18 13:24:53 +03:00
|
|
|
}
|
|
|
|
widget++;
|
|
|
|
}
|
2020-03-28 17:21:38 +03:00
|
|
|
/* - Volume */
|
2018-04-17 14:03:19 +03:00
|
|
|
if (widgets_volume_enabled) {
|
2021-06-23 15:19:16 +03:00
|
|
|
uint32_t color = (volume_menu && volume_menu->window) ? HILIGHT_COLOR : ICON_COLOR;
|
2018-04-17 14:03:19 +03:00
|
|
|
if (volume_level < 10) {
|
2021-06-23 15:19:16 +03:00
|
|
|
draw_sprite_alpha_paint(ctx, sprite_volume_mute, WIDGET_POSITION(widget), ICON_Y_PAD, 1.0, color);
|
2018-04-17 14:03:19 +03:00
|
|
|
} else if (volume_level < 0x547ae147) {
|
2021-06-23 15:19:16 +03:00
|
|
|
draw_sprite_alpha_paint(ctx, sprite_volume_low, WIDGET_POSITION(widget), ICON_Y_PAD, 1.0, color);
|
2018-04-17 14:03:19 +03:00
|
|
|
} else if (volume_level < 0xa8f5c28e) {
|
2021-06-23 15:19:16 +03:00
|
|
|
draw_sprite_alpha_paint(ctx, sprite_volume_med, WIDGET_POSITION(widget), ICON_Y_PAD, 1.0, color);
|
2018-04-17 14:03:19 +03:00
|
|
|
} else {
|
2021-06-23 15:19:16 +03:00
|
|
|
draw_sprite_alpha_paint(ctx, sprite_volume_high, WIDGET_POSITION(widget), ICON_Y_PAD, 1.0, color);
|
2018-04-17 14:03:19 +03:00
|
|
|
}
|
2018-04-18 13:24:53 +03:00
|
|
|
widget++;
|
2018-04-17 14:03:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now draw the window list */
|
|
|
|
int i = 0, j = 0;
|
|
|
|
spin_lock(&lock);
|
|
|
|
if (window_list) {
|
|
|
|
foreach(node, window_list) {
|
|
|
|
struct window_ad * ad = node->value;
|
|
|
|
char * s = "";
|
|
|
|
char tmp_title[50];
|
2018-04-25 16:04:24 +03:00
|
|
|
int w = 0;
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
if (APP_OFFSET + i + w > LEFT_BOUND) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (title_width > MIN_TEXT_WIDTH) {
|
|
|
|
|
|
|
|
memset(tmp_title, 0x0, 50);
|
|
|
|
int t_l = strlen(ad->name);
|
|
|
|
if (t_l > 45) {
|
|
|
|
t_l = 45;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < t_l; ++i) {
|
|
|
|
tmp_title[i] = ad->name[i];
|
|
|
|
if (!ad->name[i]) break;
|
|
|
|
}
|
|
|
|
|
2021-07-06 03:39:52 +03:00
|
|
|
tt_set_size(font, 14);
|
|
|
|
while (tt_string_width(font, tmp_title) > title_width - ICON_PADDING) {
|
2018-04-17 14:03:19 +03:00
|
|
|
t_l--;
|
|
|
|
tmp_title[t_l] = '.';
|
|
|
|
tmp_title[t_l+1] = '.';
|
|
|
|
tmp_title[t_l+2] = '.';
|
|
|
|
tmp_title[t_l+3] = '\0';
|
|
|
|
}
|
|
|
|
w += title_width;
|
|
|
|
|
|
|
|
s = tmp_title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hilight the focused window */
|
|
|
|
if (ad->flags & 1) {
|
|
|
|
/* This is the focused window */
|
|
|
|
for (int y = 0; y < GRADIENT_HEIGHT; ++y) {
|
|
|
|
for (int x = APP_OFFSET + i; x < APP_OFFSET + i + w; ++x) {
|
2021-06-23 15:19:16 +03:00
|
|
|
GFX(ctx, x, y+Y_PAD) = alpha_blend_rgba(GFX(ctx, x, y+Y_PAD), GRADIENT_AT(y));
|
2018-04-17 14:03:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the icon for this window */
|
2018-04-20 14:47:50 +03:00
|
|
|
sprite_t * icon = icon_get_48(ad->icon);
|
2018-04-17 14:03:19 +03:00
|
|
|
|
2018-04-25 16:04:24 +03:00
|
|
|
{
|
2021-06-23 15:19:16 +03:00
|
|
|
sprite_t * _tmp_s = create_sprite(48, PANEL_HEIGHT-Y_PAD*2, ALPHA_EMBEDDED);
|
2018-04-25 16:04:24 +03:00
|
|
|
gfx_context_t * _tmp = init_graphics_sprite(_tmp_s);
|
|
|
|
|
|
|
|
draw_fill(_tmp, rgba(0,0,0,0));
|
|
|
|
/* Draw it, scaled if necessary */
|
|
|
|
if (icon->width == 48) {
|
|
|
|
draw_sprite(_tmp, icon, 0, 0);
|
|
|
|
} else {
|
|
|
|
draw_sprite_scaled(_tmp, icon, 0, 0, 48, 48);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(_tmp);
|
2021-06-23 15:19:16 +03:00
|
|
|
draw_sprite_alpha(ctx, _tmp_s, APP_OFFSET + i + w - 48 - 2, Y_PAD, 0.7);
|
2018-04-25 16:04:24 +03:00
|
|
|
sprite_free(_tmp_s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
sprite_t * _tmp_s = create_sprite(w, PANEL_HEIGHT, ALPHA_EMBEDDED);
|
|
|
|
gfx_context_t * _tmp = init_graphics_sprite(_tmp_s);
|
|
|
|
|
|
|
|
draw_fill(_tmp, rgba(0,0,0,0));
|
2021-07-06 03:39:52 +03:00
|
|
|
tt_set_size(font, 14);
|
|
|
|
tt_draw_string(_tmp, font, 0, 14, s, rgb(0,0,0));
|
2018-04-25 16:04:24 +03:00
|
|
|
blur_context_box(_tmp, 4);
|
|
|
|
|
|
|
|
free(_tmp);
|
|
|
|
draw_sprite(ctx, _tmp_s, APP_OFFSET + i + 2, TEXT_Y_OFFSET + 2);
|
|
|
|
sprite_free(_tmp_s);
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (title_width > MIN_TEXT_WIDTH) {
|
|
|
|
/* Then draw the window title, with appropriate color */
|
2021-07-06 03:39:52 +03:00
|
|
|
uint32_t color;
|
2018-04-17 14:03:19 +03:00
|
|
|
if (j == focused_app) {
|
|
|
|
/* Current hilighted - title should be a light blue */
|
2021-07-06 03:39:52 +03:00
|
|
|
color = HILIGHT_COLOR;
|
2018-04-17 14:03:19 +03:00
|
|
|
} else {
|
|
|
|
if (ad->flags & 1) {
|
2021-07-06 03:39:52 +03:00
|
|
|
color = FOCUS_COLOR;
|
2018-04-17 14:03:19 +03:00
|
|
|
} else {
|
2021-07-06 03:39:52 +03:00
|
|
|
color = txt_color;
|
2018-04-17 14:03:19 +03:00
|
|
|
}
|
|
|
|
}
|
2021-07-06 03:39:52 +03:00
|
|
|
tt_draw_string(ctx, font, APP_OFFSET + i + 2, TEXT_Y_OFFSET + 2 + 14, s, color);
|
2018-04-17 14:03:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX This keeps track of how far left each window list item is
|
|
|
|
* so we can map clicks up in the mouse callback. */
|
|
|
|
if (j < MAX_WINDOW_COUNT) {
|
|
|
|
if (ads_by_l[j]) {
|
|
|
|
ads_by_l[j]->left = APP_OFFSET + i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
j++;
|
|
|
|
i += w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock(&lock);
|
|
|
|
|
|
|
|
/* Draw the logout button; XXX This should probably have some sort of focus hilight */
|
2021-06-23 15:19:16 +03:00
|
|
|
draw_sprite_alpha_paint(ctx, sprite_logout, width - LOGOUT_WIDTH, 1 + ICON_Y_PAD, 1.0, (logout_menu->window ? HILIGHT_COLOR : ICON_COLOR)); /* Logout button */
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
/* Flip */
|
|
|
|
flip(ctx);
|
|
|
|
yutani_flip(yctx, panel);
|
|
|
|
|
|
|
|
spin_unlock(&drawlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_window_list(void) {
|
|
|
|
yutani_query_windows(yctx);
|
|
|
|
|
|
|
|
list_t * new_window_list = list_create();
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
while (1) {
|
|
|
|
/* We wait for a series of WINDOW_ADVERTISE messsages */
|
|
|
|
yutani_msg_t * m = yutani_wait_for(yctx, YUTANI_MSG_WINDOW_ADVERTISE);
|
|
|
|
struct yutani_msg_window_advertise * wa = (void*)m->data;
|
|
|
|
|
|
|
|
if (wa->size == 0) {
|
|
|
|
/* A sentinal at the end will have a size of 0 */
|
|
|
|
free(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store each window advertisement */
|
|
|
|
struct window_ad * ad = malloc(sizeof(struct window_ad));
|
|
|
|
|
|
|
|
char * s = malloc(wa->size);
|
|
|
|
memcpy(s, wa->strings, wa->size);
|
|
|
|
ad->name = &s[wa->offsets[0]];
|
|
|
|
ad->icon = &s[wa->offsets[1]];
|
|
|
|
ad->strings = s;
|
|
|
|
ad->flags = wa->flags;
|
|
|
|
ad->wid = wa->wid;
|
|
|
|
|
|
|
|
ads_by_z[i] = ad;
|
|
|
|
i++;
|
|
|
|
ads_by_z[i] = NULL;
|
|
|
|
|
|
|
|
node_t * next = NULL;
|
|
|
|
|
|
|
|
/* And insert it, ordered by wid, into the window list */
|
|
|
|
foreach(node, new_window_list) {
|
|
|
|
struct window_ad * n = node->value;
|
|
|
|
|
|
|
|
if (n->wid > ad->wid) {
|
|
|
|
next = node;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next) {
|
|
|
|
list_insert_before(new_window_list, next, ad);
|
|
|
|
} else {
|
|
|
|
list_insert(new_window_list, ad);
|
|
|
|
}
|
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
active_window = i-1;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
/*
|
|
|
|
* Update each of the wid entries in our array so we can map
|
|
|
|
* clicks to window focus events for each window
|
|
|
|
*/
|
|
|
|
foreach(node, new_window_list) {
|
|
|
|
struct window_ad * ad = node->value;
|
|
|
|
if (i < MAX_WINDOW_COUNT) {
|
|
|
|
ads_by_l[i] = ad;
|
|
|
|
ads_by_l[i+1] = NULL;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then free up the old list and replace it with the new list */
|
|
|
|
spin_lock(&lock);
|
|
|
|
|
|
|
|
if (new_window_list->length) {
|
|
|
|
int tmp = LEFT_BOUND;
|
|
|
|
tmp -= APP_OFFSET;
|
|
|
|
if (tmp < 0) {
|
|
|
|
title_width = 0;
|
|
|
|
} else {
|
|
|
|
title_width = tmp / new_window_list->length;
|
|
|
|
if (title_width > MAX_TEXT_WIDTH) {
|
|
|
|
title_width = MAX_TEXT_WIDTH;
|
|
|
|
}
|
|
|
|
if (title_width < MIN_TEXT_WIDTH) {
|
|
|
|
title_width = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
title_width = 0;
|
|
|
|
}
|
|
|
|
if (window_list) {
|
|
|
|
foreach(node, window_list) {
|
|
|
|
struct window_ad * ad = (void*)node->value;
|
|
|
|
free(ad->strings);
|
|
|
|
free(ad);
|
|
|
|
}
|
|
|
|
list_free(window_list);
|
|
|
|
free(window_list);
|
|
|
|
}
|
|
|
|
window_list = new_window_list;
|
|
|
|
spin_unlock(&lock);
|
|
|
|
|
|
|
|
/* And redraw the panel */
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2021-06-23 15:19:16 +03:00
|
|
|
static void redraw_panel_background(gfx_context_t * ctx, int width, int height) {
|
|
|
|
draw_fill(ctx, rgba(0,0,0,0));
|
|
|
|
draw_rounded_rectangle(ctx, X_PAD, Y_PAD, width - X_PAD * 2, panel->height - Y_PAD * 2, 14, rgba(0,0,0,200));
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
static void resize_finish(int xwidth, int xheight) {
|
|
|
|
yutani_window_resize_accept(yctx, panel, xwidth, xheight);
|
|
|
|
|
|
|
|
reinit_graphics_yutani(ctx, panel);
|
|
|
|
yutani_window_resize_done(yctx, panel);
|
|
|
|
|
|
|
|
width = xwidth;
|
|
|
|
|
2021-06-23 15:19:16 +03:00
|
|
|
redraw_panel_background(ctx, xwidth, xheight);
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
/* Copy the prerendered background so we can redraw it quickly */
|
|
|
|
bg_size = panel->width * panel->height * sizeof(uint32_t);
|
|
|
|
bg_blob = realloc(bg_blob, bg_size);
|
|
|
|
memcpy(bg_blob, ctx->backbuffer, bg_size);
|
|
|
|
|
|
|
|
update_window_list();
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2018-10-03 13:23:03 +03:00
|
|
|
static void bind_keys(void) {
|
|
|
|
|
|
|
|
/* Cltr-Alt-T = launch terminal */
|
|
|
|
yutani_key_bind(yctx, 't', KEY_MOD_LEFT_CTRL | KEY_MOD_LEFT_ALT, YUTANI_BIND_STEAL);
|
|
|
|
|
|
|
|
/* Alt+Tab = app switcher*/
|
|
|
|
yutani_key_bind(yctx, '\t', KEY_MOD_LEFT_ALT, YUTANI_BIND_STEAL);
|
|
|
|
yutani_key_bind(yctx, '\t', KEY_MOD_LEFT_ALT | KEY_MOD_LEFT_SHIFT, YUTANI_BIND_STEAL);
|
|
|
|
|
|
|
|
/* Ctrl-F11 = toggle panel visibility */
|
|
|
|
yutani_key_bind(yctx, KEY_F11, KEY_MOD_LEFT_CTRL, YUTANI_BIND_STEAL);
|
|
|
|
|
|
|
|
/* Alt+F1 = show menu */
|
|
|
|
yutani_key_bind(yctx, KEY_F1, KEY_MOD_LEFT_ALT, YUTANI_BIND_STEAL);
|
|
|
|
|
|
|
|
/* Alt+F2 = show app runner */
|
|
|
|
yutani_key_bind(yctx, KEY_F2, KEY_MOD_LEFT_ALT, YUTANI_BIND_STEAL);
|
|
|
|
|
2018-12-23 12:12:55 +03:00
|
|
|
/* Alt+F3 = window context menu */
|
|
|
|
yutani_key_bind(yctx, KEY_F3, KEY_MOD_LEFT_ALT, YUTANI_BIND_STEAL);
|
|
|
|
|
2018-10-03 13:23:03 +03:00
|
|
|
/* This lets us receive all just-modifier key releases */
|
|
|
|
yutani_key_bind(yctx, KEY_LEFT_ALT, 0, YUTANI_BIND_PASSTHROUGH);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
static void sig_usr2(int sig) {
|
|
|
|
yutani_set_stack(yctx, panel, YUTANI_ZORDER_TOP);
|
|
|
|
yutani_flip(yctx, panel);
|
2018-10-03 13:23:03 +03:00
|
|
|
bind_keys();
|
2018-10-31 12:58:10 +03:00
|
|
|
signal(SIGUSR2, sig_usr2);
|
2018-04-17 14:03:19 +03:00
|
|
|
}
|
|
|
|
|
2020-03-29 07:23:42 +03:00
|
|
|
static sprite_t * watchface = NULL;
|
|
|
|
|
|
|
|
static void watch_draw_line(gfx_context_t * ctx, int offset, double r, double a, double b, uint32_t color, float thickness) {
|
|
|
|
double theta = (a / b) * 2.0 * M_PI;
|
|
|
|
draw_line_aa(ctx,
|
|
|
|
70 + 4,
|
|
|
|
70 + 4 + sin(theta) * r,
|
|
|
|
70 + offset,
|
|
|
|
70 + offset - cos(theta) * r, color, thickness);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _menu_draw_MenuEntry_Clock(gfx_context_t * ctx, struct MenuEntry * self, int offset) {
|
|
|
|
self->offset = offset;
|
|
|
|
|
|
|
|
draw_sprite(ctx, watchface, 4, offset);
|
|
|
|
|
|
|
|
struct timeval now;
|
|
|
|
struct tm * timeinfo;
|
|
|
|
gettimeofday(&now, NULL);
|
|
|
|
timeinfo = localtime((time_t *)&now.tv_sec);
|
|
|
|
|
|
|
|
double sec = timeinfo->tm_sec + (double)now.tv_usec / 1000000.0;
|
|
|
|
double min = timeinfo->tm_min + sec / 60.0;
|
|
|
|
double hour = (timeinfo->tm_hour % 12) + min / 60.0;
|
|
|
|
|
|
|
|
watch_draw_line(ctx, offset, 40, hour, 12, rgb(0,0,0), 2.0);
|
|
|
|
watch_draw_line(ctx, offset, 60, min, 60, rgb(0,0,0), 1.5);
|
|
|
|
watch_draw_line(ctx, offset, 65, sec, 60, rgb(240,0,0), 1.0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
struct MenuEntry * menu_create_clock(void) {
|
|
|
|
struct MenuEntry * out = menu_create_separator(); /* Steal some defaults */
|
|
|
|
|
|
|
|
if (!watchface) {
|
|
|
|
watchface = malloc(sizeof(sprite_t));
|
2020-04-24 08:30:12 +03:00
|
|
|
load_sprite(watchface, "/usr/share/icons/watchface.png");
|
2020-03-29 07:23:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
out->_type = -1; /* Special */
|
|
|
|
out->height = 140;
|
|
|
|
out->rwidth = 148;
|
|
|
|
out->renderer = _menu_draw_MenuEntry_Clock;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2020-03-28 13:51:52 +03:00
|
|
|
const char * month_names[] = {
|
|
|
|
"January",
|
|
|
|
"February",
|
|
|
|
"March",
|
|
|
|
"April",
|
|
|
|
"May",
|
|
|
|
"June",
|
|
|
|
"July",
|
|
|
|
"August",
|
|
|
|
"September",
|
|
|
|
"October",
|
|
|
|
"November",
|
|
|
|
"December",
|
|
|
|
};
|
|
|
|
|
|
|
|
int days_in_months[] = {
|
|
|
|
31, 0, 31, 30, 31, 30, 31,
|
|
|
|
31, 30, 31, 30, 31,
|
|
|
|
};
|
|
|
|
|
|
|
|
void _menu_draw_MenuEntry_Calendar(gfx_context_t * ctx, struct MenuEntry * self, int offset) {
|
|
|
|
self->offset = offset;
|
|
|
|
|
|
|
|
char lines[9][22];
|
|
|
|
memset(lines, 0, sizeof(lines));
|
|
|
|
|
|
|
|
struct timeval now;
|
|
|
|
gettimeofday(&now, NULL);
|
|
|
|
|
|
|
|
struct tm actual;
|
|
|
|
struct tm * timeinfo;
|
|
|
|
timeinfo = localtime((time_t *)&now.tv_sec);
|
|
|
|
memcpy(&actual, timeinfo, sizeof(struct tm));
|
|
|
|
timeinfo = &actual;
|
|
|
|
|
|
|
|
char month[20];
|
|
|
|
sprintf(month, "%s %d", month_names[timeinfo->tm_mon], timeinfo->tm_year + 1900);
|
|
|
|
|
|
|
|
int len = (20 - strlen(month)) / 2;
|
|
|
|
while (len > 0) {
|
|
|
|
strcat(lines[0]," ");
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
strcat(lines[0],month);
|
|
|
|
|
|
|
|
/* Days of week */
|
|
|
|
strcat(lines[1],"Su Mo Tu We Th Fr Sa");
|
|
|
|
|
|
|
|
int days_in_month = days_in_months[timeinfo->tm_mon];
|
|
|
|
if (days_in_month == 0) {
|
|
|
|
/* How many days in February? */
|
|
|
|
struct tm tmp;
|
|
|
|
memcpy(&tmp, timeinfo, sizeof(struct tm));
|
|
|
|
tmp.tm_mday = 29;
|
|
|
|
tmp.tm_hour = 12;
|
|
|
|
time_t tmp3 = mktime(&tmp);
|
|
|
|
struct tm * tmp2 = localtime(&tmp3);
|
|
|
|
if (tmp2->tm_mday == 29) {
|
|
|
|
days_in_month = 29;
|
|
|
|
} else {
|
|
|
|
days_in_month = 28;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int mday = timeinfo->tm_mday;
|
|
|
|
int wday = timeinfo->tm_wday; /* 0 == sunday */
|
|
|
|
|
|
|
|
while (mday > 1) {
|
|
|
|
mday--;
|
|
|
|
wday = (wday + 6) % 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < wday; ++i) {
|
|
|
|
strcat(lines[2]," ");
|
|
|
|
}
|
|
|
|
|
|
|
|
int line = 2;
|
|
|
|
while (mday <= days_in_month) {
|
|
|
|
/* TODO Bold text? */
|
|
|
|
char tmp[5];
|
|
|
|
sprintf(tmp, "%2d ", mday);
|
|
|
|
strcat(lines[line], tmp);
|
|
|
|
if (wday == 6) line++;
|
|
|
|
mday++;
|
|
|
|
wday = (wday + 1) % 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->height = 16 * (line+1) + 8;
|
|
|
|
|
|
|
|
/* Go through each and draw with monospace font */
|
|
|
|
for (int i = 0; i < 9; ++i) {
|
|
|
|
if (lines[i][0] != 0) {
|
2021-07-06 03:39:52 +03:00
|
|
|
tt_set_size(i == 0 ? font_mono_bold : font_mono, 13);
|
|
|
|
tt_draw_string(ctx, i == 0 ? font_mono_bold : font_mono, 10, self->offset + i * 17 + 13, lines[i], rgb(0,0,0));
|
2020-03-28 13:51:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Special menu entry to display a calendar
|
|
|
|
*/
|
|
|
|
struct MenuEntry * menu_create_calendar(void) {
|
|
|
|
struct MenuEntry * out = menu_create_separator(); /* Steal some defaults */
|
|
|
|
|
|
|
|
out->_type = -1; /* Special */
|
|
|
|
out->height = 16 * 9 + 8;
|
2021-07-06 03:39:52 +03:00
|
|
|
tt_set_size(font_mono, 13);
|
|
|
|
out->rwidth = tt_string_width(font_mono, "XX XX XX XX XX XX XX") + 20;
|
2020-03-28 13:51:52 +03:00
|
|
|
out->renderer = _menu_draw_MenuEntry_Calendar;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
int main (int argc, char ** argv) {
|
2018-05-10 15:54:19 +03:00
|
|
|
if (argc < 2 || strcmp(argv[1],"--really")) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: Desktop environment panel / dock\n"
|
|
|
|
"\n"
|
|
|
|
" Renders the application menu, window list, widgets,\n"
|
|
|
|
" alt-tab window switcher, clock, etc.\n"
|
|
|
|
" You probably don't want to run this directly - it is\n"
|
|
|
|
" started automatically by the session manager.\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
/* Connect to window server */
|
|
|
|
yctx = yutani_init();
|
|
|
|
|
2021-07-06 03:39:52 +03:00
|
|
|
font = tt_font_from_file("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf");
|
|
|
|
font_bold = tt_font_from_file("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf");
|
|
|
|
font_mono = tt_font_from_file("/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf");
|
|
|
|
font_mono_bold = tt_font_from_file("/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf");
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
/* For convenience, store the display size */
|
|
|
|
width = yctx->display_width;
|
|
|
|
height = yctx->display_height;
|
|
|
|
|
|
|
|
/* Create the panel window */
|
|
|
|
panel = yutani_window_create_flags(yctx, width, PANEL_HEIGHT, YUTANI_WINDOW_FLAG_NO_STEAL_FOCUS);
|
|
|
|
|
|
|
|
/* And move it to the top layer */
|
|
|
|
yutani_set_stack(yctx, panel, YUTANI_ZORDER_TOP);
|
2021-06-23 15:19:16 +03:00
|
|
|
yutani_window_update_shape(yctx, panel, YUTANI_SHAPE_THRESHOLD_CLEAR);
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
/* Initialize graphics context against the window */
|
|
|
|
ctx = init_graphics_yutani_double_buffer(panel);
|
|
|
|
|
|
|
|
/* Clear it out (the compositor should initialize it cleared anyway */
|
|
|
|
draw_fill(ctx, rgba(0,0,0,0));
|
|
|
|
flip(ctx);
|
|
|
|
yutani_flip(yctx, panel);
|
|
|
|
|
|
|
|
/* Load textures for the background and logout button */
|
|
|
|
sprite_panel = malloc(sizeof(sprite_t));
|
|
|
|
sprite_logout = malloc(sizeof(sprite_t));
|
|
|
|
|
2020-04-24 08:30:12 +03:00
|
|
|
load_sprite(sprite_panel, "/usr/share/panel.png");
|
|
|
|
load_sprite(sprite_logout, "/usr/share/icons/panel-shutdown.png");
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
struct stat stat_tmp;
|
|
|
|
if (!stat("/dev/dsp",&stat_tmp)) {
|
|
|
|
widgets_volume_enabled = 1;
|
|
|
|
widgets_width += WIDGET_WIDTH;
|
|
|
|
sprite_volume_mute = malloc(sizeof(sprite_t));
|
|
|
|
sprite_volume_low = malloc(sizeof(sprite_t));
|
|
|
|
sprite_volume_med = malloc(sizeof(sprite_t));
|
|
|
|
sprite_volume_high = malloc(sizeof(sprite_t));
|
2020-04-24 08:30:12 +03:00
|
|
|
load_sprite(sprite_volume_mute, "/usr/share/icons/24/volume-mute.png");
|
|
|
|
load_sprite(sprite_volume_low, "/usr/share/icons/24/volume-low.png");
|
|
|
|
load_sprite(sprite_volume_med, "/usr/share/icons/24/volume-medium.png");
|
|
|
|
load_sprite(sprite_volume_high, "/usr/share/icons/24/volume-full.png");
|
2018-04-17 14:03:19 +03:00
|
|
|
/* XXX store current volume */
|
|
|
|
}
|
|
|
|
|
2018-04-18 13:24:53 +03:00
|
|
|
{
|
|
|
|
widgets_network_enabled = 1;
|
|
|
|
widgets_width += WIDGET_WIDTH;
|
|
|
|
sprite_net_active = malloc(sizeof(sprite_t));
|
2020-04-24 08:30:12 +03:00
|
|
|
load_sprite(sprite_net_active, "/usr/share/icons/24/net-active.png");
|
2018-04-18 13:24:53 +03:00
|
|
|
sprite_net_disabled = malloc(sizeof(sprite_t));
|
2020-04-24 08:30:12 +03:00
|
|
|
load_sprite(sprite_net_disabled, "/usr/share/icons/24/net-disconnected.png");
|
2018-04-18 13:24:53 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 11:17:03 +03:00
|
|
|
weather_refresh(NULL);
|
2020-03-28 17:21:38 +03:00
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
/* Draw the background */
|
2021-06-23 15:19:16 +03:00
|
|
|
redraw_panel_background(ctx, panel->width, panel->height);
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
/* Copy the prerendered background so we can redraw it quickly */
|
|
|
|
bg_size = panel->width * panel->height * sizeof(uint32_t);
|
|
|
|
bg_blob = malloc(bg_size);
|
|
|
|
memcpy(bg_blob, ctx->backbuffer, bg_size);
|
|
|
|
|
|
|
|
/* Catch SIGINT */
|
|
|
|
signal(SIGINT, sig_int);
|
|
|
|
signal(SIGUSR2, sig_usr2);
|
|
|
|
|
2018-11-21 15:32:17 +03:00
|
|
|
appmenu = menu_set_get_root(menu_set_from_description("/etc/panel.menu", launch_application_menu));
|
2021-06-23 15:19:16 +03:00
|
|
|
appmenu->flags = MENU_FLAG_BUBBLE_CENTER;
|
2018-04-24 15:32:39 +03:00
|
|
|
|
2020-03-29 07:23:42 +03:00
|
|
|
clockmenu = menu_create();
|
2021-06-23 15:19:16 +03:00
|
|
|
clockmenu->flags |= MENU_FLAG_BUBBLE_RIGHT;
|
2020-03-29 07:23:42 +03:00
|
|
|
menu_insert(clockmenu, menu_create_clock());
|
|
|
|
|
2020-03-28 13:51:52 +03:00
|
|
|
calmenu = menu_create();
|
2021-06-23 15:19:16 +03:00
|
|
|
calmenu->flags |= MENU_FLAG_BUBBLE_CENTER;
|
2020-03-28 13:51:52 +03:00
|
|
|
menu_insert(calmenu, menu_create_calendar());
|
|
|
|
|
2018-04-28 05:33:31 +03:00
|
|
|
window_menu = menu_create();
|
2021-06-23 15:19:16 +03:00
|
|
|
window_menu->flags |= MENU_FLAG_BUBBLE_LEFT;
|
2018-04-28 05:33:31 +03:00
|
|
|
menu_insert(window_menu, menu_create_normal(NULL, NULL, "Maximize", _window_menu_start_maximize));
|
|
|
|
menu_insert(window_menu, menu_create_normal(NULL, NULL, "Move", _window_menu_start_move));
|
|
|
|
menu_insert(window_menu, menu_create_separator());
|
|
|
|
menu_insert(window_menu, menu_create_normal(NULL, NULL, "Close", _window_menu_close));
|
|
|
|
|
2018-05-19 13:58:39 +03:00
|
|
|
logout_menu = menu_create();
|
2021-06-23 15:19:16 +03:00
|
|
|
logout_menu->flags |= MENU_FLAG_BUBBLE_RIGHT;
|
2018-05-19 13:58:39 +03:00
|
|
|
menu_insert(logout_menu, menu_create_normal("exit", "log-out", "Log Out", launch_application_menu));
|
|
|
|
|
2018-04-17 14:03:19 +03:00
|
|
|
/* Subscribe to window updates */
|
|
|
|
yutani_subscribe_windows(yctx);
|
|
|
|
|
|
|
|
/* Ask compositor for window list */
|
|
|
|
update_window_list();
|
|
|
|
|
|
|
|
/* Key bindings */
|
2018-10-03 13:23:03 +03:00
|
|
|
bind_keys();
|
2018-04-17 14:03:19 +03:00
|
|
|
|
2018-04-25 08:03:29 +03:00
|
|
|
time_t last_tick = 0;
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
int fds[1] = {fileno(yctx->sock)};
|
|
|
|
|
|
|
|
while (_continue) {
|
|
|
|
|
2020-03-29 07:23:42 +03:00
|
|
|
int index = fswait2(1,fds,clockmenu->window ? 50 : 200);
|
|
|
|
|
|
|
|
if (clockmenu->window) {
|
|
|
|
menu_force_redraw(clockmenu);
|
|
|
|
}
|
2018-04-17 14:03:19 +03:00
|
|
|
|
|
|
|
if (index == 0) {
|
|
|
|
/* Respond to Yutani events */
|
|
|
|
yutani_msg_t * m = yutani_poll(yctx);
|
2018-04-27 16:13:16 +03:00
|
|
|
while (m) {
|
|
|
|
menu_process_event(yctx, m);
|
2018-04-17 14:03:19 +03:00
|
|
|
switch (m->type) {
|
|
|
|
/* New window information is available */
|
|
|
|
case YUTANI_MSG_NOTIFY:
|
|
|
|
update_window_list();
|
|
|
|
break;
|
|
|
|
/* Mouse movement / click */
|
|
|
|
case YUTANI_MSG_WINDOW_MOUSE_EVENT:
|
|
|
|
panel_check_click((struct yutani_msg_window_mouse_event *)m->data);
|
|
|
|
break;
|
|
|
|
case YUTANI_MSG_KEY_EVENT:
|
|
|
|
handle_key_event((struct yutani_msg_key_event *)m->data);
|
|
|
|
break;
|
|
|
|
case YUTANI_MSG_WELCOME:
|
|
|
|
{
|
|
|
|
struct yutani_msg_welcome * mw = (void*)m->data;
|
|
|
|
width = mw->display_width;
|
|
|
|
height = mw->display_height;
|
|
|
|
yutani_window_resize(yctx, panel, mw->display_width, PANEL_HEIGHT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case YUTANI_MSG_RESIZE_OFFER:
|
|
|
|
{
|
|
|
|
struct yutani_msg_window_resize * wr = (void*)m->data;
|
|
|
|
resize_finish(wr->width, wr->height);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(m);
|
2018-04-27 16:13:16 +03:00
|
|
|
m = yutani_poll_async(yctx);
|
2018-04-17 14:03:19 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct timeval now;
|
|
|
|
gettimeofday(&now, NULL);
|
|
|
|
if (now.tv_sec != last_tick) {
|
|
|
|
last_tick = now.tv_sec;
|
|
|
|
waitpid(-1, NULL, WNOHANG);
|
|
|
|
update_volume_level();
|
2018-04-18 13:24:53 +03:00
|
|
|
update_network_status();
|
2020-03-28 17:21:38 +03:00
|
|
|
update_weather_status();
|
2018-04-17 14:03:19 +03:00
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close the panel window */
|
|
|
|
yutani_close(yctx, panel);
|
|
|
|
|
|
|
|
/* Stop notifying us of window changes */
|
|
|
|
yutani_unsubscribe_windows(yctx);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|