From 332a02bc23e76658b1b865749b0ca1b082ad439b Mon Sep 17 00:00:00 2001 From: Thierry Lorthiois Date: Tue, 10 Nov 2009 21:11:31 +0000 Subject: [PATCH] panel snapshot --- src/config.c | 2 +- src/config.h | 2 +- src/tint.c | 58 ++++++++++++++++++++++++++++++++++++---------------- 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/config.c b/src/config.c index d8675c3..dee33d2 100644 --- a/src/config.c +++ b/src/config.c @@ -52,7 +52,7 @@ // global path char *config_path = 0; -char *thumbnail_path = 0; +char *snapshot_path = 0; // -------------------------------------------------- // backward compatibility diff --git a/src/config.h b/src/config.h index 4a922c7..c472f19 100644 --- a/src/config.h +++ b/src/config.h @@ -10,7 +10,7 @@ #define CONFIG_H extern char *config_path; -extern char *thumbnail_path; +extern char *snapshot_path; void init_config(); void cleanup_config(); diff --git a/src/tint.c b/src/tint.c index 3696911..95137dc 100644 --- a/src/tint.c +++ b/src/tint.c @@ -49,21 +49,27 @@ void signal_handler(int sig) void init (int argc, char *argv[]) { - int c; + int i; // read options - while ((c = getopt(argc , argv, "c:j:v")) != -1) { - switch (c) { - case 'c': - config_path = strdup (optarg); - break; - case 'j': - thumbnail_path = strdup (optarg); - break; - case 'v': - printf("tint2 version 0.7-svn\n"); + for (i = 1; i < argc; ++i) { + if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { + printf("Usage: tint2 [-c] \n"); exit(0); - break; + } + if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) { + printf("tint2 version 0.7.svn\n"); + exit(0); + } + if (!strcmp(argv[i], "-c")) { + i++; + if (i < argc) + config_path = strdup(argv[i]); + } + if (!strcmp(argv[i], "-s")) { + i++; + if (i < argc) + snapshot_path = strdup(argv[i]); } } @@ -91,7 +97,7 @@ void init (int argc, char *argv[]) server.visual = DefaultVisual (server.dsp, server.screen); server.desktop = server_get_current_desktop (); XGCValues gcv; - server.gc = XCreateGC (server.dsp, server.root_win, (unsigned long)0, &gcv) ; + server.gc = XCreateGC (server.dsp, server.root_win, (unsigned long)0, &gcv); XSetErrorHandler ((XErrorHandler) server_catch_error); @@ -105,7 +111,6 @@ void init (int argc, char *argv[]) setlocale (LC_ALL, ""); // load default icon - int i; char *path; const gchar * const *data_dirs; data_dirs = g_get_system_data_dirs (); @@ -138,7 +143,7 @@ void cleanup() imlib_free_image(); } if (config_path) g_free(config_path); - if (thumbnail_path) g_free(thumbnail_path); + if (snapshot_path) g_free(snapshot_path); if (server.monitor) free(server.monitor); XFreeGC(server.dsp, server.gc); @@ -146,6 +151,24 @@ void cleanup() } +void get_snapshot(const char *path) +{ + Panel *panel = &panel1[0]; + + if (panel->temp_pmap) XFreePixmap(server.dsp, panel->temp_pmap); + panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth); + + refresh(&panel->area); + + Imlib_Image img = NULL; + imlib_context_set_drawable(panel->temp_pmap); + img = imlib_create_image_from_drawable(0, 0, 0, panel->area.width, panel->area.height, 0); + + imlib_context_set_image(img); + imlib_save_image(path); +} + + Taskbar *click_taskbar (Panel *panel, int x, int y) { Taskbar *tskbar; @@ -718,9 +741,8 @@ int main (int argc, char *argv[]) } init_panel(); cleanup_config(); - if (thumbnail_path) { - // usage: tint2 -j for internal use - printf("file %s\n", thumbnail_path); + if (snapshot_path) { + get_snapshot(snapshot_path); cleanup(); exit(0); } -- 2.44.0