📄 iconmanager.c
字号:
/* iconmanager.c - runs stuff when icons are clicked on etc. Copyright (C) 1996-2000 Paul Sheer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */#include "coolwidget.h"#include "icon.h"#include "mad.h"extern int option_mouse_double_click;extern int cursor_revert_timeout;extern Window cursor_revert_window;extern void destroy_icon (CWidget * w);CWidget *CDrawPowerIcon (CPowerIcon * p);int edit_dialog (CPowerIcon * icon, char *heading);char *substitute_strings (char *text, char *cmdline_options, char *editor_file, char *dnd_major_type, char *dnd_minor_type, char *dnd_data_file);void new_dialog (CWidget * w);int save_icons (void);void change_config_file (CWidget * icon);void edit_change_directory (void);void raise_lower_all (int r);void arrange_icons (void);void close_all (CWidget * w);void icon_help (void);void edit_tri_cursor (Window win);void free_icon_elements (CPowerIcon * icon){ if (icon->title) free (icon->title); if (icon->xpm_filename) free (icon->xpm_filename); if (icon->prompt) free (icon->prompt); if (icon->confirm) free (icon->confirm); if (icon->drop_script) free (icon->drop_script); if (icon->double_click_script) free (icon->double_click_script); if (icon->tool_hint) free (icon->tool_hint); if (icon->mime_majors) { int i; for (i = 0; icon->mime_majors[i]; i++) free (icon->mime_majors[i]); free (icon->mime_majors); } memset (icon, 0, sizeof (CPowerIcon));}void copy_icon_elements (CPowerIcon * icon, CPowerIcon * icon2){ int i; memcpy (icon, icon2, sizeof (CPowerIcon)); icon->title = (char *) strdup (icon->title); icon->xpm_filename = (char *) strdup (icon->xpm_filename); icon->prompt = (char *) strdup (icon->prompt); icon->confirm = (char *) strdup (icon->confirm); icon->drop_script = (char *) strdup (icon->drop_script); icon->double_click_script = (char *) strdup (icon->double_click_script); icon->tool_hint = (char *) strdup (icon->tool_hint); if (icon2->mime_majors) { for (i = 0; icon2->mime_majors[i]; i++); icon->mime_majors = CMalloc ((i + 1) * (sizeof (char *))); for (i = 0; icon2->mime_majors[i]; i++) icon->mime_majors[i] = (char *) strdup (icon2->mime_majors[i]); icon->mime_majors[i] = 0; }}void destroy_power_icon (CWidget * w){ CPowerIcon *icon; destroy_icon (w); icon = (CPowerIcon *) w->user; if (!icon) return; free_icon_elements (icon); free (icon); w->user = 0;}void CDestroyIconWidget (char *ident){ CWidget *w; w = CIdent (ident); if (w->droppedmenu) { CPullUp (w->droppedmenu); CDestroyWidget (w->droppedmenu->ident); w->droppedmenu = 0; } CDestroyWidget (ident);}int savefile (const char *filename, const char *data, int len, int permissions);void icon_system (char *script, char *temp_data_file){ pid_t p; p = fork (); if (p == -1) { CErrorDialog (CRoot, 20, 20, _ (" Execute Script "), _ (" Fork Failed ")); } else { if (!p) { char *temp_script_file; temp_script_file = (char *) tempnam ("/tmp", "cicon"); savefile (temp_script_file, script, strlen (script), 0700);#if 0 usleep ((unsigned long) option_mouse_double_click * 1000 * 2);#endif CSystem (temp_script_file); remove (temp_script_file); if (*temp_data_file) remove (temp_data_file); exit (0); }#if 0 usleep ((unsigned long) option_mouse_double_click * 1000 * 2);#endif }}char *filename_from_url (char *data, int size, int i);void run_script (char *script, char *arg, char *drop_data, int dnd_len, char *dnd_mime_type){ char *f = 0, *temp_data_file = 0; char *dnd_major_type, *dnd_minor_type; char *data_str; data_str = CMalloc (dnd_len + 1); memcpy (data_str, drop_data, dnd_len); data_str[dnd_len] = '\0'; drop_data = data_str; dnd_major_type = (char *) strdup (dnd_mime_type); dnd_minor_type = strchr (dnd_major_type, '/'); if (dnd_minor_type) *dnd_minor_type++ = '\0'; else dnd_minor_type = ""; if (!strcmp (dnd_mime_type, "url/url") || !strcmp (dnd_mime_type, "text/uri-list")) if (!strncmp (data_str, "file:/", 6)) f = filename_from_url (data_str, dnd_len, strlen ("file:")); if (!f) f = (char *) strdup (""); temp_data_file = (char *) tempnam ("/tmp", "cicon"); savefile (temp_data_file, drop_data, dnd_len, 0600); script = substitute_strings (script, arg, f, dnd_major_type, dnd_minor_type, temp_data_file); icon_system (script, temp_data_file); free (script); free (temp_data_file); free (data_str); free (f); free (dnd_major_type);}void execute_icon_double_click (CEvent * cevent, CPowerIcon * icon){ char *a = 0; if (!*icon->double_click_script) return; CHourGlass (cevent->window); CSetOverrideRedirect (); if (icon->options & ICON_OPTION_CONFIRM_DOUBLE_CLICK) { switch (CQueryDialog (CRoot, icon->x, icon->y, _ (" Execute "), catstrs (" ", icon->confirm, " ", 0), _ (" Ok "), _ (" Cancel "), 0)) { case -1: case 1: CClearOverrideRedirect (); goto done; case 0: break; } } CClearOverrideRedirect (); if (icon->options & ICON_OPTION_PROMPT_DOUBLE_CLICK) { a = CInputDialog ("iconinput", CRoot, icon->x, icon->y, 300 | INPUT_DIALOG_BROWSE_SAVE, CLastInput ("iconinput"), _ (" Execute icon "), icon->prompt); if (!a) goto done; } run_script (icon->double_click_script, a ? a : "", "", 0, "none/none"); done: cursor_revert_timeout = 4; cursor_revert_window = cevent->window; if (a) free (a);}void execute_icon (CWidget * w){ CEvent cevent; memset (&cevent, 0, sizeof (CEvent)); cevent.window = w->winid; execute_icon_double_click (&cevent, (CPowerIcon *) w->user);}void execute_icon_drop (CWidget * w, CPowerIcon * icon, char *drop_data, int dnd_len, char *dnd_mime_type){ char *a = 0; if (!*icon->drop_script) return; CHourGlass (w->winid); CSetOverrideRedirect (); if (icon->options & ICON_OPTION_CONFIRM_DROP) { switch (CQueryDialog (CRoot, icon->x, icon->y, _ (" Execute "), catstrs (" ", icon->confirm, " ", 0), _ (" Ok "), _ (" Cancel "), 0)) { case -1: case 1: CClearOverrideRedirect (); goto done; case 0: break; } } CClearOverrideRedirect (); if (icon->options & ICON_OPTION_PROMPT_DROP) { a = CInputDialog ("iconinput", CRoot, icon->x, icon->y, 300 | INPUT_DIALOG_BROWSE_SAVE, CLastInput ("iconinput"), _ (" Execute icon "), icon->prompt); if (!a) goto done; } run_script (icon->drop_script, a ? a : "", drop_data, dnd_len, dnd_mime_type); done: cursor_revert_timeout = 4; cursor_revert_window = w->winid; if (a) free (a);}void copy_icon (CWidget * w){ CPowerIcon icon; copy_icon_elements (&icon, (CPowerIcon *) w->user); icon.x = w->x + 10; icon.y = w->y + 10; CDrawPowerIcon (&icon);}void edit_icon (CWidget *w){ CPowerIcon icon; XUngrabPointer (CDisplay, CurrentTime); copy_icon_elements (&icon, (CPowerIcon *) w->user); CDisable (w->ident); if (edit_dialog (&icon, _(" Edit Icon "))) { CDestroyIconWidget (w->ident); CDrawPowerIcon (&icon); save_icons (); } else { CEnable (w->ident); free_icon_elements (&icon); }}void delete_icon (CWidget * w){ XUngrabPointer (CDisplay, CurrentTime); CSetOverrideRedirect (); switch (CQueryDialog (CRoot, w->x, w->y, _(" Delete "), _(" Remove icon from desktop : "), _(" Remove "), _(" Cancel "), 0)) { case -1: case 1: CClearOverrideRedirect (); return; case 0: break; } CClearOverrideRedirect (); CDestroyIconWidget (w->ident);}void icon_menu (char *ident){ CEvent cwevent; XEvent xevent; CWidget *w; w = CIdent (ident); if (!w) return; if (!w->droppedmenu) return; CMenuSelectionDialog (w->droppedmenu);}#ifndef HAVE_DND/* If a filename is dropped onto the main window, open an edit window with that file. */struct drop drop;int handle_drop (CWidget * w, Window from, unsigned char *data, int size, int xs, int ys, Atom type, Atom action){ drop.data = CMalloc (size); memcpy (drop.data, data, size); drop.size = size; drop.atom_name = (char *) strdup (XGetAtomName (CDisplay, type)); drop.ident = (char *) strdup (w->ident); return 0;}#endifint icon_callback (CWidget * w, XEvent * xevent, CEvent * cwevent){ CPowerIcon *ic; char ident[33]; ic = (CPowerIcon *) w->user; ic->x = w->x; ic->y = w->y; switch (cwevent->type) { case ButtonPress: if (cwevent->button == Button2) { Window win; win = w->winid; strcpy (ident, cwevent->ident); icon_menu (ident); memset (cwevent, 0, sizeof (CEvent)); xevent->type = MotionNotify; xevent->xmotion.state = Button1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -