📄 iconmanager.c
字号:
CSendEvent (xevent); XLowerWindow (CDisplay, win); } else if (cwevent->double_click) { execute_icon_double_click (cwevent, ic); } break;#ifdef HAVE_DND case ClientMessage:{ int xs, ys, data_type; unsigned char *data; unsigned long size; data_type = CGetDrop (xevent, &data, &size, &xs, &ys); if (data_type == DndNotDnd) return 0; execute_icon_drop (cwevent, ic, (char *) data, size, data_type); if (data) free (data); return 1; } return 0;#else#if 0 case ClientMessage:{ int xs, ys, data_type; Atom action, type; unsigned char *data; unsigned long size; action = xdnd_get_drop (CDisplay, xevent, 0, 0, &data, &size, &type, &x, &y); data_type = CGetDrop (xevent, &data, &size, &xs, &ys); if (data_type == DndNotDnd) return 0; execute_icon_drop (cwevent, ic, (char *) data, size, data_type); if (data) free (data); return 1; } return 0;#endif#endif } return 0;}/* main window only recieves drops, so... */static struct mouse_funcs icon_mouse_funcs ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (int (*)(void *, Window, unsigned char *, int, int, int, Atom, Atom)) handle_drop, 0, DndUnknown, /* no preference, rather use mime_major below */ 0};CWidget *CDrawPowerIcon (CPowerIcon * p){ static int n = 0; char *f; CWidget *w; n++; if (p->y + FONT_PIX_PER_LINE > HeightOfScreen (DefaultScreenOfDisplay (CDisplay))) p->y = HeightOfScreen (DefaultScreenOfDisplay (CDisplay)) - FONT_PIX_PER_LINE; if (p->x + 20 > WidthOfScreen (DefaultScreenOfDisplay (CDisplay))) p->x = WidthOfScreen (DefaultScreenOfDisplay (CDisplay)) - 20; if (*p->xpm_filename != '/') f = catstrs (LIBDIR, "/", p->xpm_filename, 0); else f = p->xpm_filename; w = CDrawIcon (catstrs ("_icon", itoa (n), 0), CRoot, p->x, p->y, f, p->title); w->funcs = mouse_funcs_new (w, &icon_mouse_funcs); w->funcs->mime_majors = p->mime_majors; xdnd_set_dnd_aware (CDndClass, w->winid, 0); if (!w) return 0; if (*p->tool_hint)/* Toolhint */ CSetToolHint (catstrs ("_icon", itoa (n), 0), p->tool_hint); w->user = CMalloc (sizeof (CPowerIcon)); memcpy (w->user, p, sizeof (CPowerIcon)); w->destroy = destroy_power_icon; w->callback = icon_callback; if (!strcmp (p->double_click_script, "<icon manager>")) { w->droppedmenu = CDrawMenuButton (catstrs ("_icon", itoa (n), ".menu", 0), w->winid, CRoot, 0, w->height, AUTO_WIDTH, 1, 9, _ (" Dummy "), _ ("Help..."), 0, (void (*)(unsigned long)) icon_help, 0, _ ("New icon..."), 0, new_dialog, (unsigned long) w, _ ("Auto arrange"), 0, arrange_icons, 0, _ ("Change directory..."), 0, edit_change_directory, 0, _ ("Save icons"), 0, save_icons, 0, _ ("Config file..."), 0, change_config_file, (unsigned long) w, _ ("Raise icons"), 0, raise_lower_all, 1, _ ("Lower icons"), 0, raise_lower_all, 0, _ ("Kill Coolicons..."), 0, close_all, (unsigned long) w ); } else { w->droppedmenu = CDrawMenuButton (catstrs ("_icon", itoa (n), ".menu", 0), w->winid, CRoot, 0, w->height, AUTO_WIDTH, 1, 7, _ (" Dummy "), _ ("Edit icon..."), 0, (void (*)(unsigned long)) edit_icon, (unsigned long) w, _ ("Execute icon"), 0, execute_icon, (unsigned long) w, _ ("Copy icon"), 0, copy_icon, (unsigned long) w, _ ("Delete icon"), 0, delete_icon, (unsigned long) w, _ ("New icon..."), 0, new_dialog, (unsigned long) w, _ ("Auto arrange"), 0, arrange_icons, 0, _ ("Save icons"), 0, save_icons, 0 ); } w->droppedmenu->options &= ~MENU_AUTO_PULL_UP; return w;}void strnlcpy (unsigned char *s, unsigned char *t){ for (;;) { *s = (*t == '\n') ? 129 : *t; if (!*t) break; s++; t++; }}void memlncpy (unsigned char *s, unsigned char *t, int l){ while (l--) { *s = (*t == 129) ? '\n' : *t; s++; t++; }}void convert_commalist_to_array (char *mime_majors, char ***a){ char **h, *p, *q; int i, done = 0; for (i = 0, p = q = mime_majors; (p = strchr (q, ',')); q = ++p, i++); h = *a = CMalloc ((i + 2) * sizeof (char *)); for (p = q = mime_majors; !done; q = p) { while (!strchr (", \t", *p) && *p) p++; if (*p) *p++ = '\0'; else done = 1; if (*q) { *h = (char *) strdup (q); h++; } while (strchr (", \t", *p) && *p) p++; } *h = 0;}void convert_array_to_commalist (char **a, char **mime_majors){ if (!a) { *mime_majors = (char *) strdup (""); } else { int i, l; for (l = i = 0; a[i]; i++) l += strlen (a[i]) + 2; *mime_majors = CMalloc (l + 1); **mime_majors = '\0'; for (i = 0; a[i]; i++) { strcat (*mime_majors, a[i]); if (a[i + 1]) strcat (*mime_majors, ", "); } }}char *gather_icon_options_for_config (void){ char *t, *p, *q; int i = 0, size = 0, n; while (last_widget > i++) if (CIndex (i) != NULL) if ((CIndex (i))->kind == C_ICON_WIDGET && (CIndex (i))->user) { CPowerIcon *icon; icon = (CPowerIcon *) (CIndex (i))->user; size += strlen (icon->title); size += strlen (icon->xpm_filename); size += strlen (icon->prompt); size += strlen (icon->confirm); size += strlen (icon->drop_script); size += strlen (icon->double_click_script); size += strlen (icon->tool_hint); if (icon->mime_majors) for (n = 0; icon->mime_majors[n]; n++) size += strlen (icon->mime_majors[n]) + 2; size += 256; } p = t = CMalloc (size); i = 0; while (last_widget > i++) if (CIndex (i) != NULL) if ((CIndex (i))->kind == C_ICON_WIDGET && (CIndex (i))->user) { CPowerIcon *icon; icon = (CPowerIcon *) (CIndex (i))->user; strcpy (p, "title = "); p += strlen (p); strnlcpy ((unsigned char *) p, (unsigned char *) icon->title); strcat (p, "\nxpm_filename = "); strcat (p, icon->xpm_filename); strcat (p, "\nx = "); strcat (p, itoa ((CIndex (i))->x)); strcat (p, "\ny = "); strcat (p, itoa ((CIndex (i))->y)); strcat (p, "\nprompt = "); p += strlen (p); strnlcpy ((unsigned char *) p, (unsigned char *) icon->prompt); strcat (p, "\nconfirm = "); p += strlen (p); strnlcpy ((unsigned char *) p, (unsigned char *) icon->confirm); strcat (p, "\noptions = "); strcat (p, itoa (icon->options)); strcat (p, "\ndrop_script = "); p += strlen (p); strnlcpy ((unsigned char *) p, (unsigned char *) icon->drop_script); strcat (p, "\ndouble_click_script = "); p += strlen (p); strnlcpy ((unsigned char *) p, (unsigned char *) icon->double_click_script); strcat (p, "\ntool_hint = "); strcat (p, icon->tool_hint); strcat (p, "\nmime_majors = "); convert_array_to_commalist (icon->mime_majors, &q); strcat (p, q); free (q); strcat (p, "\n\n"); p += strlen (p); } *p = '\0'; return t;}static char *advance_equate (char *p, char *g, int *l){ char *q; while (strchr ("\n\t ", *p)) p++; if (strncmp (p, g, strlen (g))) return 0; p += strlen (g); q = strchr (p, '\n'); if (!q) return 0; *l = (unsigned long) q - (unsigned long) p; return p;}/* returns 1 on error */static int read_string (char **p, char *g, char **s){ char *q; int l; q = advance_equate (*p, g, &l); if (!q) return 1; *s = CMalloc (l + 1); memlncpy ((unsigned char *) *s, (unsigned char *) q, l); (*s)[l] = '\0'; *p = q + l + 1; return 0;}/* returns 1 on error */static int read_int (char **p, char *g, int *i){ char *q; int l; q = advance_equate (*p, g, &l); if (!q) return 1; *i = atoi (q); *p = q + l + 1; return 0;}/* returns 1 on error */int draw_icons_from_config (char *t){ char *p, *mime_majors; int n = 0; p = t; for (;;) { CPowerIcon icon; memset (&icon, 0, sizeof (CPowerIcon)); n++; p = strstr (p, "title = "); if (!p) break; if (read_string (&p, "title = ", &icon.title)) goto icon_error; if (read_string (&p, "xpm_filename = ", &icon.xpm_filename)) goto icon_error; if (read_int (&p, "x = ", &icon.x)) goto icon_error; if (read_int (&p, "y = ", &icon.y)) goto icon_error; if (read_string (&p, "prompt = ", &icon.prompt)) goto icon_error; if (read_string (&p, "confirm = ", &icon.confirm)) goto icon_error; if (read_int (&p, "options = ", &icon.options)) goto icon_error; if (read_string (&p, "drop_script = ", &icon.drop_script)) goto icon_error; if (read_string (&p, "double_click_script = ", &icon.double_click_script)) goto icon_error; if (read_string (&p, "tool_hint = ", &icon.tool_hint)) goto icon_error; if (read_string (&p, "mime_majors = ", &mime_majors)) { icon.mime_majors = 0; } else { convert_commalist_to_array (mime_majors, &icon.mime_majors); free (mime_majors); } if (*p != '\n') break; CDrawPowerIcon (&icon); p++; } return 0; icon_error: CErrorDialog (CRoot, 20, 20, _ (" Reading Config "), _ (" Error interpreting icon %d from config, \n not bothering to read further "), n); return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -