示例#1
0
文件: mgrgldi.go 项目: sqp/godock
// sendApp sends an event to the applet matching the icon.
//
func (o *AppManager) sendApp(icon gldi.Icon, event string, data ...interface{}) bool {
	app := o.actives[unsafe.Pointer(icon.ToNative())]
	if app == nil {
		return notif.AnswerLetPass
	}
	o.log.Debug(event, data...)
	app.OnEvent(event, data...)
	return notif.AnswerIntercept // an app received the event (even if unused). intercept it.
}
示例#2
0
文件: dialog.go 项目: sqp/godock
// ShowTemporaryWithIcon opens a simple dialog with a timeout.
//
func ShowTemporaryWithIcon(str string, icon gldi.Icon, container *gldi.Container, duration float64, iconPath string) {
	cstr := (*C.gchar)(C.CString(str))
	defer C.free(unsafe.Pointer((*C.char)(cstr)))
	cpath := (*C.gchar)(C.CString(iconPath))
	defer C.free(unsafe.Pointer((*C.char)(cpath)))

	cicon := (*C.Icon)(unsafe.Pointer(icon.ToNative()))
	ccontainer := (*C.GldiContainer)(unsafe.Pointer(container.Ptr))

	C.gldi_dialog_show_temporary_with_icon(cstr, cicon, ccontainer, C.double(duration), cpath)
}
示例#3
0
文件: dialog.go 项目: sqp/godock
// ShowWithQuestion opens a dialog with a question to answer.
//
func ShowWithQuestion(str string, icon gldi.Icon, container *gldi.Container, iconPath string, onAnswer func(int, *gtk.Widget)) {
	cstr := (*C.gchar)(C.CString(str))
	defer C.free(unsafe.Pointer((*C.char)(cstr)))
	cpath := (*C.gchar)(C.CString(iconPath))
	defer C.free(unsafe.Pointer((*C.char)(cpath)))

	cicon := (*C.Icon)(unsafe.Pointer(icon.ToNative()))
	ccontainer := (*C.GldiContainer)(unsafe.Pointer(container.Ptr))

	dialogCall = onAnswer
	removeDialog()
	c := C.gldi_dialog_show_with_question(cstr, cicon, ccontainer, cpath, C.CairoDockActionOnAnswerFunc(C.onDialogAnswer), nil, nil)
	dialogPtr = NewDialogFromNative(unsafe.Pointer(c))
}
示例#4
0
文件: mgrgldi.go 项目: sqp/godock
// sendIconOrSub sends an event to the applet matching the icon or subicon.
//
func (o *AppManager) sendIconOrSub(icon gldi.Icon, container *gldi.Container, mainEvent, subEvent string, data ...interface{}) bool {
	var appIcon gldi.Icon
	switch { // Find the base icon of the icon that was clicked on (for subdock or desklets).
	case container.IsDesklet():
		appIcon = container.ToDesklet().GetIcon()

	case gldi.ObjectIsDock(container) && container.ToCairoDock().GetRefCount() != 0 && !icon.IsApplet():
		appIcon = container.ToCairoDock().SearchIconPointingOnDock(nil)

	default:
		appIcon = icon
	}

	if appIcon == nil || icon == nil || icon.ToNative() == nil { // TODO: need to check why.
		return notif.AnswerLetPass
	}

	if appIcon.ToNative() == icon.ToNative() {
		return o.sendApp(appIcon, mainEvent, data...) // Main Icon event.
	}
	data = append(data, icon.GetCommand())       // add reference to subicon key.
	return o.sendApp(appIcon, subEvent, data...) // SubIcon event.
}
示例#5
0
文件: dialog.go 项目: sqp/godock
// NewDialog creates a custom dialog.
//
func NewDialog(icon gldi.Icon, container *gldi.Container, dialog cdtype.DialogData) *Dialog {
	dialogCall = nil

	// Common dialog attributes.
	attr := new(C.CairoDialogAttr)
	if icon != nil {
		attr.pIcon = (*C.Icon)(unsafe.Pointer(icon.ToNative()))
	}
	attr.pContainer = (*C.GldiContainer)(unsafe.Pointer(container.Ptr))

	if dialog.Icon != "" {
		// w,h :=
		// 		cairo_dock_get_icon_extent (pIcon, &w, &h);
		// 		cImageFilePath = cairo_dock_search_icon_s_path (g_value_get_string (v), MAX (w, h));
		attr.cImageFilePath = gchar(dialog.Icon)
	} else {
		attr.cImageFilePath = gchar("same icon")
	}

	if dialog.Message != "" {
		attr.cText = gchar(dialog.Message)
	}

	if dialog.Buttons != "" {
		cstr := gchar(dialog.Buttons)
		csep := gchar(";")
		clist := C.g_strsplit(cstr, csep, -1) // NULL-terminated
		C.free(unsafe.Pointer((*C.char)(cstr)))
		C.free(unsafe.Pointer((*C.char)(csep)))
		defer C.g_strfreev(clist)
		attr.cButtonsImage = C.constListString(clist)

		// Set the common C callback for all methods.
		attr.pActionFunc = C.CairoDockActionOnAnswerFunc(C.onDialogAnswer)
	}

	attr.iTimeLength = C.gint(1000 * dialog.TimeLength)
	attr.bForceAbove = cbool(dialog.ForceAbove)
	attr.bUseMarkup = cbool(dialog.UseMarkup)

	attr.pUserData = C.intToPointer(1) // unused, but it seems it must be set so the onDialogDestroyed can be called.
	attr.pFreeDataFunc = C.GFreeFunc(C.onDialogDestroyed)

	var widget *gtk.Widget
	var getValue = func() interface{} { return nil }
	switch typed := dialog.Widget.(type) {

	case cdtype.DialogWidgetText:
		widget, getValue = dialogWidgetText(typed)

	case cdtype.DialogWidgetScale:
		widget, getValue = dialogWidgetScale(typed)

	case cdtype.DialogWidgetList:
		widget, getValue = dialogWidgetList(typed)

		// default:
		// return errors.New("PopupDialog: invalid widget type")
	}

	if widget != nil {
		attr.pInteractiveWidget = (*C.GtkWidget)(unsafe.Pointer(widget.Native()))
	}

	if dialog.Buttons != "" && dialog.Callback != nil {
		dialogCall = func(clickedButton int, _ *gtk.Widget) { // No special widget, return button ID.
			dialog.Callback(clickedButton, getValue())
		}
	}

	removeDialog()
	c := C.gldi_dialog_new(attr)
	dialogPtr = NewDialogFromNative(unsafe.Pointer(c))
	return dialogPtr
}