Exemplo n.º 1
0
// 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.
}
Exemplo n.º 2
0
Arquivo: dialog.go Projeto: 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)
}
Exemplo n.º 3
0
Arquivo: dialog.go Projeto: 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))
}
Exemplo n.º 4
0
// 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.
}
Exemplo n.º 5
0
Arquivo: dialog.go Projeto: 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
}