コード例 #1
0
ファイル: MessageBox.cpp プロジェクト: GustavoMOG/edelib
void MessageBox::add_button(Fl_Button* b, MessageBoxButtonType bt) {
	E_RETURN_IF_FAIL(nbuttons < MSGBOX_MAX_BUTTONS);
	E_RETURN_IF_FAIL(b != NULL);

	int W = 0, H = 0;

	fl_font(b->labelfont(), b->labelsize());
	fl_measure(b->label(), W, H);

	if(W > 90) {
		W += 10; // some spaces between label an button edges
		if(bt == MSGBOX_BUTTON_RETURN)
			W += 30; // increase again since Fl_Return_Button have that stupid marker
		else
			W += 10; // ordinary button
		b_start -= W;
	} else {
		W = 90;
		b_start -= W;
	}

	b->resize(b_start, 75, W, 25);
	b_start -= 5; // space between buttons

	gr->add(b);
	buttons[nbuttons] = b;
	nbuttons++;
}
コード例 #2
0
ファイル: Sipc.cpp プロジェクト: GustavoMOG/edelib
void SipcClient::send(const char* msg) {
	E_RETURN_IF_FAIL(priv != NULL);
	E_RETURN_IF_FAIL(priv->fd != -1);

	int len = strlen(msg);
	if(len > MSG_LEN_MAX)
		len = MSG_LEN_MAX;

	::write(priv->fd, msg, len);
	::write(priv->fd, "\n", 1);
}
コード例 #3
0
ファイル: Desktop.cpp プロジェクト: GustavoMOG/ede
static void arrange_icons_cb(Fl_Widget*, void *d) {
	E_RETURN_IF_FAIL(d != NULL);

	Desktop *self = (Desktop*)d;
	self->arrange_icons();
	self->redraw();
}
コード例 #4
0
ファイル: Taskbar.cpp プロジェクト: edeproject/svn
void Taskbar::activate_window(TaskButton *b) {
	E_RETURN_IF_FAIL(b != NULL);

	Window xid = b->get_window_xid();

	/* if clicked on activated button, it will be minimized, then next one will be activated */
	if(b == curr_active) {
		if(wm_get_window_state(xid) != WM_STATE_ICONIC) {
			/* minimize if not so */
			wm_set_window_state(xid, WM_STATE_ICONIC);

			if(prev_active && 
			   prev_active != b && 
			   wm_get_window_state(prev_active->get_window_xid()) != WM_STATE_ICONIC) 
			{
				xid = prev_active->get_window_xid();
				b   = prev_active;
			} else {
				return;
			}
		}
	} 

	/* active or restore minimized */
	netwm_set_active_window(xid);
	update_active_button(xid);

	/* TODO: use stack for this (case when this can't handle: minimize three window, out of four on the workspace) */
	prev_active = curr_active;
	curr_active = b;
}
コード例 #5
0
ファイル: theme.cpp プロジェクト: GustavoMOG/edelib
static void load_theme_cb(Fl_Widget*, void*) {
	E_RETURN_IF_FAIL(ThemeLoader::global()->load_with_path("theme-sample"));

	char buf[128];
	if(ThemeLoader::global()->theme()->get_item("ede", "sample", buf, sizeof(buf)))
		E_DEBUG(E_STRLOC ": evaluated => %s\n", buf);
}
コード例 #6
0
ファイル: Desktop.cpp プロジェクト: GustavoMOG/ede
static void folder_create_cb(Fl_Widget*, void *d) {
	E_RETURN_IF_FAIL(d != NULL);

	const char *n = input(_("Create a new folder with the name"));
	if(!n) return;
	
	Desktop *self = (Desktop*)d;
	self->create_folder(n);
}
コード例 #7
0
ファイル: Panel.cpp プロジェクト: GustavoMOG/ede
void Panel::load_applets(const char *applets) {
	mgr.clear(this);

	/*
	 * Hardcoded order, unless configuration file was found. For easier and uniform parsing
	 * (similar string is expected from configuration), fallback is plain string.
	 */
	static const char *fallback =
		"start_menu,"
		"quick_launch,"
		"pager,"
		"clock,"
		"taskbar,"
		"keyboard_layout,"
		"battery_monitor,"
		"cpu_monitor,"
#ifdef __linux__
		"mem_monitor,"
#endif
		"system_tray";
	
	String dir = Resource::find_data("panel-applets");
	E_RETURN_IF_FAIL(!dir.empty());
	
	char *dup = strdup(applets ? applets : fallback);
	E_RETURN_IF_FAIL(dup != NULL);

	char path[PATH_MAX];
	for(char *tok = strtok(dup, ","); tok; tok = strtok(NULL, ",")) {
		tok = str_trim(tok);

#ifndef EDE_PANEL_LOCAL_APPLETS
		snprintf(path, sizeof(path), "%s" E_DIR_SEPARATOR_STR "%s" APPLET_EXTENSION, dir.c_str(), tok);
#else
		/* only for testing, so path separator is hardcoded */
		snprintf(path, sizeof(path), "./applets/%s/%s" APPLET_EXTENSION, dir.c_str(), tok);
#endif
		mgr.load(path);
	}

	free(dup);
	mgr.fill_group(this);
}
コード例 #8
0
ファイル: Desktop.cpp プロジェクト: GustavoMOG/ede
void Desktop::read_desktop_folder(const char *dpath) {
	E_RETURN_IF_FAIL(dpath != NULL);
	String path;

	DIR *dir = opendir(dpath);
	E_RETURN_IF_FAIL(dir != NULL);
	
	DesktopConfig pos;
	pos.load(ICONS_POS_FILE);

	dirent *d;
	while((d = readdir(dir)) != NULL) {
		if(DOT_OR_DOTDOT(d->d_name))
			continue;

		if(d->d_type > 0) {
			if(d->d_type != DT_REG && d->d_type != DT_LNK && d->d_type != DT_DIR)
				continue;

			path = dpath;
			path += E_DIR_SEPARATOR;
			path += d->d_name;
		} else {
			/* 
			 * If we got here, it means d_type isn't set and we must do it via file_test() which could be much slower.
			 * By POSIX standard, only d_name must be set, but many modern *nixes set all dirent members correctly. Except Slackware ;)
			 */
			path = dpath;
			path += E_DIR_SEPARATOR;
			path += d->d_name;

			if(!(file_test(path.c_str(), FILE_TEST_IS_REGULAR) ||
			     file_test(path.c_str(), FILE_TEST_IS_DIR)     ||
			     file_test(path.c_str(), FILE_TEST_IS_SYMLINK)))
				continue;
		}

		DesktopIcon *o = read_desktop_file(path.c_str(), (const char*)d->d_name, &pos);
		if(o) add(o);
	}

	closedir(dir);
}
コード例 #9
0
ファイル: Taskbar.cpp プロジェクト: edeproject/svn
void Taskbar::update_child_title(Window xid) {
	E_RETURN_IF_FAIL(xid >= 0);

	TaskButton *o;
	for(int i = 0; i < children(); i++) {
		o = (TaskButton*)child(i);

		if(o->get_window_xid() == xid) {
			o->update_title_from_xid();
			break;
		}
	}
}
コード例 #10
0
ファイル: TaskButton.cpp プロジェクト: GustavoMOG/ede
void TaskButton::update_title_from_xid(void) {
	E_RETURN_IF_FAIL(xid >= 0);

	char *title = netwm_window_get_title(xid);
	if(!title) {
		label("...");
		tooltip("...");
	} else {
		copy_label(title);
		tooltip(label());
		free(title);
	}
}
コード例 #11
0
ファイル: StartupNotify.cpp プロジェクト: GustavoMOG/ede
void startup_notify_end(StartupNotify *s) {
#if HAVE_LIBSTARTUP_NOTIFICATION
	E_RETURN_IF_FAIL(s != 0);
	sn_launcher_context_complete(s->context);
	sn_launcher_context_unref(s->context);
	sn_display_unref(s->display);

	edelib_unsetenv("DESKTOP_STARTUP_ID");
	XSync(fl_display, False);

	delete s;
#endif
}
コード例 #12
0
ファイル: BatteryMonitor.cpp プロジェクト: GustavoMOG/ede
void BatteryMonitor::scan_and_init(void) {
	if(con.connected()) return;
	E_RETURN_IF_FAIL(con.connect(EDBUS_SYSTEM));
	
	/* get battery devices */
	EdbusMessage msg, reply;
	msg.create_method_call(UPOWER_SERVICE, UPOWER_PATH, UPOWER_SERVICE, "EnumerateDevices");

	E_RETURN_IF_FAIL(con.send_with_reply_and_block(msg, 1000, reply));
	E_RETURN_IF_FAIL(reply.size() == 1);

	EdbusMessage::const_iterator it = reply.begin();
	E_RETURN_IF_FAIL(it->is_array());

	EdbusList arr = it->to_array();
	it = arr.begin();
	EdbusMessage::const_iterator ite = arr.end();

	for(; it != ite; ++it) {
		if(!it->is_object_path()) continue;

		EdbusObjectPath p = it->to_object_path();

		if(is_battery(con, p.path())) {
			/* filters so signal_cb() doesn't get clobbered with uninterested dbus signals */
			con.add_signal_match(p.path(), UPOWER_INTERFACE, "Changed");
			//con.add_signal_match(p.path(), UPOWER_SERVICE, "DeviceChanged");
			batts.push_back(p);
		}
	}
	
	update_icon_and_tooltip();

	/* ready to receive signals */
	con.signal_callback(signal_cb, this);
	con.setup_listener_with_fltk();
}
コード例 #13
0
ファイル: ObjectTree.cpp プロジェクト: GustavoMOG/edelib
static void send_to_editor_cb(Fl_Widget*, void *s) {
	ObjectTree *self = (ObjectTree*)s;
	Fl_Tree_Item *titem = self->first_selected_item();

	if(!titem || !titem->user_data()) return;

	Entity *en = (Entity*)titem->user_data();
	Fl_Text_Buffer *ebuf = self->get_editor_buffer();

	E_RETURN_IF_FAIL(ebuf != NULL);

	char buf[EDELIB_DBUS_EXPLORER_DEFAULT_SCRIPT_EVAL_BUFSIZE];
	if(en->get_prototype_as_scheme(buf, sizeof(buf)))
		ebuf->append(buf);
}
コード例 #14
0
ファイル: Run.cpp プロジェクト: edeproject/svn
static void write_int(int fd, int val) {
	E_RETURN_IF_FAIL(fd != -1);

	char* buf = (char*)&val;
	int bufsz = sizeof(val);
	unsigned int count;

	while(bufsz > 0) {
		count = write(fd, buf, bufsz);
		if(count < 0) {
			if(errno != EINTR)
				return;
		} else {
			bufsz -= count;
			buf += count;
		}
	}
}
コード例 #15
0
ファイル: DesktopFile.cpp プロジェクト: GustavoMOG/edelib
void DesktopFile::set_type(DesktopFileType t) {
	E_RETURN_IF_FAIL(errcode == DESK_FILE_SUCCESS || errcode == DESK_FILE_EMPTY);

	const char* val = 0;
	switch(t) {
		case DESK_FILE_TYPE_APPLICATION:
			val = "Application";
			break;
		case DESK_FILE_TYPE_LINK:
			val = "Link";
			break;
		case DESK_FILE_TYPE_DIRECTORY:
			val = "Directory";
			break;
		default:
			E_ASSERT(0 && "Feeding me with invalid type value! Make sure type is application, link or directory");
			break;
	}

	Config::set(ENTRY_SECT, "Type", val);
}
コード例 #16
0
ファイル: Taskbar.cpp プロジェクト: edeproject/svn
static void net_event_cb(int action, Window xid, void *data) {
	E_RETURN_IF_FAIL(data != NULL);

	if(action == NETWM_CHANGED_CURRENT_WORKSPACE || action == NETWM_CHANGED_WINDOW_LIST) {
		Taskbar *tt = (Taskbar*)data;
		tt->create_task_buttons();
		return;
	}

	if(action == NETWM_CHANGED_WINDOW_NAME) {
		Taskbar *tt = (Taskbar*)data;
		tt->update_child_title(xid);
		return;
	}

	/* this is a message, so property is not changed and netwm_get_active_window() must be called */
	if(action == NETWM_CHANGED_ACTIVE_WINDOW) {
		Taskbar *tt = (Taskbar*)data;
		tt->update_active_button();
		return;
	}
}
コード例 #17
0
ファイル: TaskButton.cpp プロジェクト: GustavoMOG/ede
void TaskButton::update_image_from_xid(void) {
	E_RETURN_IF_FAIL(xid >= 0);

	Fl_RGB_Image *img = netwm_window_get_icon(xid, TASKBUTTON_ICON_W);
	if(!img) return;
	
	int width = img->w(), height = img->h();

	/* some safety, scale it if needed */
	if((width  > TASKBUTTON_ICON_W) || (height > TASKBUTTON_ICON_H)) {
		width  = (width  > TASKBUTTON_ICON_W) ? TASKBUTTON_ICON_W : width;
		height = (height > TASKBUTTON_ICON_H) ? TASKBUTTON_ICON_H : height;

		/* safe casting */
		Fl_RGB_Image *scaled = (Fl_RGB_Image*)img->copy(width, height);
		delete img;

		img = scaled;
	}

	clear_image();
	image(img);
	image_alloc = true;
}
コード例 #18
0
ファイル: Entity.cpp プロジェクト: edeproject/edelib
void Entity::set_doc(const char *s) {
	E_RETURN_IF_FAIL(doc == NULL);
	doc = edelib_strndup(s, MAX_STRSZ);
}
コード例 #19
0
ファイル: Entity.cpp プロジェクト: edeproject/edelib
void Entity::set_service(const char *s) {
	E_RETURN_IF_FAIL(service == NULL);
	service = edelib_strndup(s, MAX_STRSZ);
}
コード例 #20
0
ファイル: Entity.cpp プロジェクト: edeproject/edelib
void Entity::set_interface(const char *i) {
	E_RETURN_IF_FAIL(interface == NULL);
	interface = edelib_strndup(i, MAX_STRSZ);
}
コード例 #21
0
ファイル: Entity.cpp プロジェクト: edeproject/edelib
void Entity::set_path(const char *p) {
	E_RETURN_IF_FAIL(path == NULL);
	path = edelib_strndup(p, MAX_STRSZ);
}
コード例 #22
0
ファイル: Entity.cpp プロジェクト: edeproject/edelib
void Entity::set_name(const char *n) {
	E_RETURN_IF_FAIL(name == NULL);
	name = edelib_strndup(n, MAX_STRSZ);
}
コード例 #23
0
ファイル: Taskbar.cpp プロジェクト: edeproject/svn
void Taskbar::panel_redraw(void) {
	E_RETURN_IF_FAIL(panel != NULL);
	panel->redraw();
}
コード例 #24
0
ファイル: SchemeEditor.cpp プロジェクト: edeproject/svn
void SchemeEditor::object_color(int id, int c) {
	unsigned int sz = sizeof(styletable) / sizeof(styletable[0]);
	E_RETURN_IF_FAIL(sz > (unsigned int)id);

	styletable[id].color = (Fl_Color)c;
}
コード例 #25
0
ファイル: Panel.cpp プロジェクト: GustavoMOG/ede
void Panel::do_layout(void) {
	E_RETURN_IF_FAIL(children() > 0);

	Fl_Widget     *o;
	unsigned long  opts;
	unsigned int   lsz;
	int            X, W, free_w;

	WidgetList left, right, center, unmanaged, resizable_h;

	for(int i = 0; i < children(); i++) {
		o = child(i);

		/* first resize it to some reasonable height and center it vertically */
		fix_widget_h(o, this);

		/* manage hider specifically */
		if(hider && o == hider) {
			right.push_back(o);
			continue;
		}

		/* could be slow, but I'm relaying how number of loaded applets will not be that large */
		if(!mgr.get_applet_options(o, opts)) {
			/* here are put widgets not loaded as applets */
			unmanaged.push_back(o);
			continue;
		}

		if(opts & EDE_PANEL_APPLET_OPTION_RESIZABLE_H)
			resizable_h.push_back(o);

		if(opts & EDE_PANEL_APPLET_OPTION_ALIGN_LEFT) {
			/* first item will be most leftest */
			left.push_back(o);
			continue;
		}

		if(opts & EDE_PANEL_APPLET_OPTION_ALIGN_RIGHT) {
			/* first item will be most rightest */
			right.push_back(o);
			continue;
		}

		/* rest of them */
		center.push_back(o);
	}

	/* make sure we at the end have all widgets, so we can overwrite group array */
	lsz = left.size() + center.size() + right.size() + unmanaged.size();
	E_ASSERT(lsz == (unsigned int)children() && "Size of layout lists size not equal to group size");

	X = INITIAL_SPACING;

	/* 
	 * Call add() on each element, processing lists in order. add() will remove element
	 * in group array and put it at the end of array. At the end, we should have array ordered by
	 * layout flags.
	 */
	add_from_list(left, this, X, true);
	add_from_list(center, this, X, true);
	add_from_list(unmanaged, this, X, true);

	free_w = X;

	/* elements right will be put from starting from the right panel border */
	X = w() - INITIAL_SPACING;
	add_from_list(right, this, X, false);

	/* 
	 * Code for horizontal streching. 
	 *
	 * FIXME: This code pretty sucks and need better rewrite in the future.
	 * To work properly, applets that will be streched must be successive or everything will be
	 * messed up. Also, applets that are placed right2left does not work with it; they will be resized to right.
	 */
	if(resizable_h.empty())
		return;

	/* calculate free space for horizontal alignement, per item in resizable_h list */
	free_w = (X - free_w) / resizable_h.size();
	if(!free_w) free_w = 0;

	/* 
	 * since add_from_list() will already reserve some space by current child width and default spacing,
	 * those values will be used again or holes will be made
	 */
	WidgetListIt it = resizable_h.begin(), ite = resizable_h.end();
	o = resizable_h.front();
	X = o->x();

	while(it != ite) {
		o = *it;

		W = o->w() + free_w;
		o->resize(X, o->y(), W, o->h());
		X += W + DEFAULT_SPACING;

		it = resizable_h.erase(it);
	}
}
コード例 #26
0
ファイル: Sipc.cpp プロジェクト: GustavoMOG/edelib
void SipcServer::callback(SipcCallback cb, void* data) {
	E_RETURN_IF_FAIL(priv != NULL);

	priv->cb = cb;
	priv->arg = data;
}