Refactoring
This commit is contained in:
@@ -988,3 +988,17 @@ void execp_update_post_read(Execp *execp)
|
|||||||
schedule_panel_redraw();
|
schedule_panel_redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handle_execp_events()
|
||||||
|
{
|
||||||
|
for (GList *l = panel_config.execp_list; l; l = l->next) {
|
||||||
|
Execp *execp = (Execp *)l->data;
|
||||||
|
if (read_execp(execp)) {
|
||||||
|
GList *l_instance;
|
||||||
|
for (l_instance = execp->backend->instances; l_instance; l_instance = l_instance->next) {
|
||||||
|
Execp *instance = (Execp *)l_instance->data;
|
||||||
|
execp_update_post_read(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -148,4 +148,6 @@ void execp_update_post_read(Execp *execp);
|
|||||||
|
|
||||||
void execp_default_font_changed();
|
void execp_default_font_changed();
|
||||||
|
|
||||||
|
void handle_execp_events();
|
||||||
|
|
||||||
#endif // EXECPLUGIN_H
|
#endif // EXECPLUGIN_H
|
||||||
|
|||||||
@@ -166,6 +166,8 @@ void init_post_config()
|
|||||||
RED "Could not load default_icon.png. Please check that tint2 has been installed correctly!" RESET
|
RED "Could not load default_icon.png. Please check that tint2 has been installed correctly!" RESET
|
||||||
"\n");
|
"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XSync(server.display, False);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_X11_pre_config()
|
void init_X11_pre_config()
|
||||||
|
|||||||
206
src/main.c
206
src/main.c
@@ -68,64 +68,13 @@ XSettingsClient *xsettings_client = NULL;
|
|||||||
|
|
||||||
gboolean debug_fps = FALSE;
|
gboolean debug_fps = FALSE;
|
||||||
gboolean debug_frames = FALSE;
|
gboolean debug_frames = FALSE;
|
||||||
int frame = 0;
|
static int frame = 0;
|
||||||
|
static double ts_event_read;
|
||||||
|
static double ts_event_processed;
|
||||||
|
static double ts_render_finished;
|
||||||
|
static double ts_flush_finished;
|
||||||
|
|
||||||
void dump_panel_to_file(const Panel *panel, const char *path)
|
static gboolean first_render;
|
||||||
{
|
|
||||||
imlib_context_set_drawable(panel->temp_pmap);
|
|
||||||
Imlib_Image img = imlib_create_image_from_drawable(0, 0, 0, panel->area.width, panel->area.height, 1);
|
|
||||||
|
|
||||||
if (!img) {
|
|
||||||
XImage *ximg =
|
|
||||||
XGetImage(server.display, panel->temp_pmap, 0, 0, panel->area.width, panel->area.height, AllPlanes, ZPixmap);
|
|
||||||
|
|
||||||
if (ximg) {
|
|
||||||
DATA32 *pixels = (DATA32 *)calloc(panel->area.width * panel->area.height, sizeof(DATA32));
|
|
||||||
for (int x = 0; x < panel->area.width; x++) {
|
|
||||||
for (int y = 0; y < panel->area.height; y++) {
|
|
||||||
DATA32 xpixel = XGetPixel(ximg, x, y);
|
|
||||||
|
|
||||||
DATA32 r = (xpixel >> 16) & 0xff;
|
|
||||||
DATA32 g = (xpixel >> 8) & 0xff;
|
|
||||||
DATA32 b = (xpixel >> 0) & 0xff;
|
|
||||||
DATA32 a = 0x0;
|
|
||||||
|
|
||||||
DATA32 argb = (a << 24) | (r << 16) | (g << 8) | b;
|
|
||||||
pixels[y * panel->area.width + x] = argb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
XDestroyImage(ximg);
|
|
||||||
img = imlib_create_image_using_data(panel->area.width, panel->area.height, pixels);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (img) {
|
|
||||||
imlib_context_set_image(img);
|
|
||||||
if (!panel_horizontal) {
|
|
||||||
// rotate 90° vertical panel
|
|
||||||
imlib_image_flip_horizontal();
|
|
||||||
imlib_image_flip_diagonal();
|
|
||||||
}
|
|
||||||
imlib_save_image(path);
|
|
||||||
imlib_free_image();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void save_screenshot(const char *path)
|
|
||||||
{
|
|
||||||
Panel *panel = &panels[0];
|
|
||||||
|
|
||||||
if (panel->area.width > server.monitors[0].width)
|
|
||||||
panel->area.width = server.monitors[0].width;
|
|
||||||
|
|
||||||
panel->temp_pmap =
|
|
||||||
XCreatePixmap(server.display, server.root_win, panel->area.width, panel->area.height, server.depth);
|
|
||||||
render_panel(panel);
|
|
||||||
|
|
||||||
XSync(server.display, False);
|
|
||||||
|
|
||||||
dump_panel_to_file(panel, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_event_property_notify(XEvent *e)
|
void handle_event_property_notify(XEvent *e)
|
||||||
{
|
{
|
||||||
@@ -613,24 +562,50 @@ void handle_x_event(XEvent *e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void run_tint2_event_loop()
|
void handle_x_events()
|
||||||
{
|
{
|
||||||
double ts_event_read = 0;
|
if (XPending(server.display) > 0) {
|
||||||
double ts_event_processed = 0;
|
XEvent e;
|
||||||
double ts_render_finished = 0;
|
XNextEvent(server.display, &e);
|
||||||
double ts_flush_finished = 0;
|
if (debug_fps)
|
||||||
gboolean first_render = TRUE;
|
ts_event_read = get_time();
|
||||||
|
|
||||||
while (!get_signal_pending()) {
|
handle_x_event(&e);
|
||||||
if (panel_refresh) {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void prepare_fd_set(fd_set *fd_set, int *max_fd)
|
||||||
|
{
|
||||||
|
FD_ZERO(fd_set);
|
||||||
|
FD_SET(server.x11_fd, fd_set);
|
||||||
|
*max_fd = server.x11_fd;
|
||||||
|
if (sigchild_pipe_valid) {
|
||||||
|
FD_SET(sigchild_pipe[0], fd_set);
|
||||||
|
*max_fd = MAX(*max_fd, sigchild_pipe[0]);
|
||||||
|
}
|
||||||
|
for (GList *l = panel_config.execp_list; l; l = l->next) {
|
||||||
|
Execp *execp = (Execp *)l->data;
|
||||||
|
int fd = execp->backend->child_pipe_stdout;
|
||||||
|
if (fd > 0) {
|
||||||
|
FD_SET(fd, fd_set);
|
||||||
|
*max_fd = MAX(*max_fd, fd);
|
||||||
|
}
|
||||||
|
fd = execp->backend->child_pipe_stderr;
|
||||||
|
if (fd > 0) {
|
||||||
|
FD_SET(fd, fd_set);
|
||||||
|
*max_fd = MAX(*max_fd, fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (uevent_fd > 0) {
|
||||||
|
FD_SET(uevent_fd, fd_set);
|
||||||
|
*max_fd = MAX(*max_fd, uevent_fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_panel_refresh()
|
||||||
|
{
|
||||||
if (debug_fps)
|
if (debug_fps)
|
||||||
ts_event_processed = get_time();
|
ts_event_processed = get_time();
|
||||||
if (systray_profile)
|
|
||||||
fprintf(stderr,
|
|
||||||
BLUE "[%f] %s:%d redrawing panel" RESET "\n",
|
|
||||||
profiling_get_time(),
|
|
||||||
__FUNCTION__,
|
|
||||||
__LINE__);
|
|
||||||
panel_refresh = FALSE;
|
panel_refresh = FALSE;
|
||||||
|
|
||||||
for (int i = 0; i < num_panels; i++) {
|
for (int i = 0; i < num_panels; i++) {
|
||||||
@@ -708,9 +683,11 @@ void run_tint2_event_loop()
|
|||||||
if (panel_shrink)
|
if (panel_shrink)
|
||||||
schedule_panel_redraw();
|
schedule_panel_redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug_fps)
|
if (debug_fps)
|
||||||
ts_render_finished = get_time();
|
ts_render_finished = get_time();
|
||||||
XFlush(server.display);
|
XFlush(server.display);
|
||||||
|
|
||||||
if (debug_fps && ts_event_read > 0) {
|
if (debug_fps && ts_event_read > 0) {
|
||||||
ts_flush_finished = get_time();
|
ts_flush_finished = get_time();
|
||||||
double period = ts_flush_finished - ts_event_read;
|
double period = ts_flush_finished - ts_event_read;
|
||||||
@@ -739,68 +716,35 @@ void run_tint2_event_loop()
|
|||||||
for (int i = 0; i < num_panels; i++) {
|
for (int i = 0; i < num_panels; i++) {
|
||||||
char path[256];
|
char path[256];
|
||||||
sprintf(path, "tint2-%d-panel-%d-frame-%d.png", getpid(), i, frame);
|
sprintf(path, "tint2-%d-panel-%d-frame-%d.png", getpid(), i, frame);
|
||||||
dump_panel_to_file(&panels[i], path);
|
save_panel_screenshot(&panels[i], path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
frame++;
|
frame++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a File Description Set containing x11_fd
|
void run_tint2_event_loop()
|
||||||
fd_set fdset;
|
{
|
||||||
FD_ZERO(&fdset);
|
ts_event_read = 0;
|
||||||
FD_SET(server.x11_fd, &fdset);
|
ts_event_processed = 0;
|
||||||
int maxfd = server.x11_fd;
|
ts_render_finished = 0;
|
||||||
if (sigchild_pipe_valid) {
|
ts_flush_finished = 0;
|
||||||
FD_SET(sigchild_pipe[0], &fdset);
|
first_render = TRUE;
|
||||||
maxfd = MAX(maxfd, sigchild_pipe[0]);
|
|
||||||
}
|
while (!get_signal_pending()) {
|
||||||
for (GList *l = panel_config.execp_list; l; l = l->next) {
|
if (panel_refresh)
|
||||||
Execp *execp = (Execp *)l->data;
|
handle_panel_refresh();
|
||||||
int fd = execp->backend->child_pipe_stdout;
|
|
||||||
if (fd > 0) {
|
fd_set fd_set;
|
||||||
FD_SET(fd, &fdset);
|
int max_fd;
|
||||||
maxfd = MAX(maxfd, fd);
|
prepare_fd_set(&fd_set, &max_fd);
|
||||||
}
|
|
||||||
fd = execp->backend->child_pipe_stderr;
|
|
||||||
if (fd > 0) {
|
|
||||||
FD_SET(fd, &fdset);
|
|
||||||
maxfd = MAX(maxfd, fd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (uevent_fd > 0) {
|
|
||||||
FD_SET(uevent_fd, &fdset);
|
|
||||||
maxfd = MAX(maxfd, uevent_fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for an event and handle it
|
// Wait for an event and handle it
|
||||||
ts_event_read = 0;
|
ts_event_read = 0;
|
||||||
if (XPending(server.display) > 0 || select(maxfd + 1, &fdset, 0, 0, get_next_timeout()) >= 0) {
|
if (XPending(server.display) > 0 || select(max_fd + 1, &fd_set, 0, 0, get_next_timeout()) >= 0) {
|
||||||
uevent_handler();
|
uevent_handler();
|
||||||
|
handle_sigchld_events();
|
||||||
if (sigchild_pipe_valid) {
|
handle_execp_events();
|
||||||
char buffer[1];
|
handle_x_events();
|
||||||
while (read(sigchild_pipe[0], buffer, sizeof(buffer)) > 0) {
|
|
||||||
sigchld_handler_async();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (GList *l = panel_config.execp_list; l; l = l->next) {
|
|
||||||
Execp *execp = (Execp *)l->data;
|
|
||||||
if (read_execp(execp)) {
|
|
||||||
GList *l_instance;
|
|
||||||
for (l_instance = execp->backend->instances; l_instance; l_instance = l_instance->next) {
|
|
||||||
Execp *instance = (Execp *)l_instance->data;
|
|
||||||
execp_update_post_read(instance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (XPending(server.display) > 0) {
|
|
||||||
XEvent e;
|
|
||||||
XNextEvent(server.display, &e);
|
|
||||||
if (debug_fps)
|
|
||||||
ts_event_read = get_time();
|
|
||||||
|
|
||||||
handle_x_event(&e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_expired_timers();
|
handle_expired_timers();
|
||||||
@@ -809,8 +753,6 @@ void run_tint2_event_loop()
|
|||||||
|
|
||||||
void tint2(int argc, char **argv, gboolean *restart)
|
void tint2(int argc, char **argv, gboolean *restart)
|
||||||
{
|
{
|
||||||
*restart = FALSE;
|
|
||||||
|
|
||||||
init(argc, argv);
|
init(argc, argv);
|
||||||
|
|
||||||
if (snapshot_path) {
|
if (snapshot_path) {
|
||||||
@@ -819,10 +761,7 @@ void tint2(int argc, char **argv, gboolean *restart)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
XSync(server.display, False);
|
|
||||||
|
|
||||||
dnd_init();
|
dnd_init();
|
||||||
|
|
||||||
uevent_init();
|
uevent_init();
|
||||||
run_tint2_event_loop();
|
run_tint2_event_loop();
|
||||||
|
|
||||||
@@ -847,9 +786,10 @@ void tint2(int argc, char **argv, gboolean *restart)
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
gboolean run = TRUE;
|
gboolean restart;
|
||||||
while (run) {
|
do {
|
||||||
tint2(argc, argv, &run);
|
restart = FALSE;
|
||||||
}
|
tint2(argc, argv, &restart);
|
||||||
|
} while(restart);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
57
src/panel.c
57
src/panel.c
@@ -1149,3 +1149,60 @@ void _schedule_panel_redraw(const char *file, const char *function, const int li
|
|||||||
fprintf(stderr, YELLOW "%s %s %d: triggering panel redraw" RESET "\n", file, function, line);
|
fprintf(stderr, YELLOW "%s %s %d: triggering panel redraw" RESET "\n", file, function, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void save_panel_screenshot(const Panel *panel, const char *path)
|
||||||
|
{
|
||||||
|
imlib_context_set_drawable(panel->temp_pmap);
|
||||||
|
Imlib_Image img = imlib_create_image_from_drawable(0, 0, 0, panel->area.width, panel->area.height, 1);
|
||||||
|
|
||||||
|
if (!img) {
|
||||||
|
XImage *ximg =
|
||||||
|
XGetImage(server.display, panel->temp_pmap, 0, 0, panel->area.width, panel->area.height, AllPlanes, ZPixmap);
|
||||||
|
|
||||||
|
if (ximg) {
|
||||||
|
DATA32 *pixels = (DATA32 *)calloc(panel->area.width * panel->area.height, sizeof(DATA32));
|
||||||
|
for (int x = 0; x < panel->area.width; x++) {
|
||||||
|
for (int y = 0; y < panel->area.height; y++) {
|
||||||
|
DATA32 xpixel = XGetPixel(ximg, x, y);
|
||||||
|
|
||||||
|
DATA32 r = (xpixel >> 16) & 0xff;
|
||||||
|
DATA32 g = (xpixel >> 8) & 0xff;
|
||||||
|
DATA32 b = (xpixel >> 0) & 0xff;
|
||||||
|
DATA32 a = 0x0;
|
||||||
|
|
||||||
|
DATA32 argb = (a << 24) | (r << 16) | (g << 8) | b;
|
||||||
|
pixels[y * panel->area.width + x] = argb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
XDestroyImage(ximg);
|
||||||
|
img = imlib_create_image_using_data(panel->area.width, panel->area.height, pixels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (img) {
|
||||||
|
imlib_context_set_image(img);
|
||||||
|
if (!panel_horizontal) {
|
||||||
|
// rotate 90° vertical panel
|
||||||
|
imlib_image_flip_horizontal();
|
||||||
|
imlib_image_flip_diagonal();
|
||||||
|
}
|
||||||
|
imlib_save_image(path);
|
||||||
|
imlib_free_image();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void save_screenshot(const char *path)
|
||||||
|
{
|
||||||
|
Panel *panel = &panels[0];
|
||||||
|
|
||||||
|
if (panel->area.width > server.monitors[0].width)
|
||||||
|
panel->area.width = server.monitors[0].width;
|
||||||
|
|
||||||
|
panel->temp_pmap =
|
||||||
|
XCreatePixmap(server.display, server.root_win, panel->area.width, panel->area.height, server.depth);
|
||||||
|
render_panel(panel);
|
||||||
|
|
||||||
|
XSync(server.display, False);
|
||||||
|
|
||||||
|
save_panel_screenshot(panel, path);
|
||||||
|
}
|
||||||
|
|||||||
@@ -206,4 +206,7 @@ void default_font_changed();
|
|||||||
void free_icon(Imlib_Image icon);
|
void free_icon(Imlib_Image icon);
|
||||||
Imlib_Image scale_icon(Imlib_Image original, int icon_size);
|
Imlib_Image scale_icon(Imlib_Image original, int icon_size);
|
||||||
|
|
||||||
|
void save_screenshot(const char *path);
|
||||||
|
void save_panel_screenshot(const Panel *panel, const char *path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -98,6 +98,16 @@ void sigchld_handler_async()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handle_sigchld_events()
|
||||||
|
{
|
||||||
|
if (sigchild_pipe_valid) {
|
||||||
|
char buffer[1];
|
||||||
|
while (read(sigchild_pipe[0], buffer, sizeof(buffer)) > 0) {
|
||||||
|
sigchld_handler_async();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void init_signals_postconfig()
|
void init_signals_postconfig()
|
||||||
{
|
{
|
||||||
gboolean need_sigchld = FALSE;
|
gboolean need_sigchld = FALSE;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ void init_signals_postconfig();
|
|||||||
void emit_self_restart(const char *reason);
|
void emit_self_restart(const char *reason);
|
||||||
int get_signal_pending();
|
int get_signal_pending();
|
||||||
|
|
||||||
void sigchld_handler_async();
|
void handle_sigchld_events();
|
||||||
|
|
||||||
extern int sigchild_pipe_valid;
|
extern int sigchild_pipe_valid;
|
||||||
extern int sigchild_pipe[2];
|
extern int sigchild_pipe[2];
|
||||||
|
|||||||
Reference in New Issue
Block a user