]> Dogcows Code - chaz/tint2/blobdiff - src/tint.c
mem leak
[chaz/tint2] / src / tint.c
index 903a4cfc8dc701fa1c31f58fec0b62d9ff5234bb..163fd9ea223e8a2b2e649ebda61dd93cad6fac09 100644 (file)
@@ -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] <config_file>\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,25 @@ 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);
+       imlib_free_image();
+}
+
+
 Taskbar *click_taskbar (Panel *panel, int x, int y)
 {
        Taskbar *tskbar;
@@ -402,9 +426,9 @@ void event_property_notify (XEvent *e)
                                if (panel_mode == MULTI_DESKTOP && panel->g_taskbar.use_active) {
                                        // redraw both taskbar
                                        panel->taskbar[old_desktop].area.is_active = 0;
-                                       panel->taskbar[old_desktop].area.redraw = 1;
+                                       panel->taskbar[old_desktop].area.resize = 1;
                                        panel->taskbar[server.desktop].area.is_active = 1;
-                                       panel->taskbar[server.desktop].area.redraw = 1;
+                                       panel->taskbar[server.desktop].area.resize = 1;
                                        panel_refresh = 1;
                                }
                                // check ALLDESKTOP task => resize taskbar
@@ -587,7 +611,10 @@ void event_configure_notify (Window win)
        // change in root window (xrandr)
        if (win == server.root_win) {
                get_monitors();
+               init_config();
+               config_read_file (config_path);
                init_panel();
+               cleanup_config();
                return;
        }
 
@@ -715,9 +742,8 @@ int main (int argc, char *argv[])
        }
        init_panel();
        cleanup_config();
-       if (thumbnail_path) {
-               // usage: tint2 -j <file> for internal use
-               printf("file %s\n", thumbnail_path);
+       if (snapshot_path) {
+               get_snapshot(snapshot_path);
                cleanup();
                exit(0);
        }
@@ -750,6 +776,7 @@ int main (int argc, char *argv[])
                                                break;
 
                                        case MotionNotify: {
+                                               if (!g_tooltip.enabled) break;
                                                Panel* panel = get_panel(e.xmotion.window);
                                                Task* task = click_task(panel, e.xmotion.x, e.xmotion.y);
                                                if (task)
@@ -776,7 +803,7 @@ int main (int argc, char *argv[])
                                                break;
 
                                        case ReparentNotify:
-                                               if (!systray.area.on_screen)
+                                               if (!systray_enabled)
                                                        break;
                                                panel = (Panel*)systray.area.panel;
                                                if (e.xany.window == panel->main_win) // reparented to us
This page took 0.02607 seconds and 4 git commands to generate.