Beispiel #1
0
DesktopWindow::DesktopWindow(BRect frame, bool editMode)
	: BWindow(frame, B_TRANSLATE("Desktop"), 
		kPrivateDesktopWindowLook, 
		kPrivateDesktopWindowFeel, 
		B_NOT_MOVABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE
		 | B_NOT_MINIMIZABLE | B_NOT_RESIZABLE
		 | B_ASYNCHRONOUS_CONTROLS,
		editMode?B_CURRENT_WORKSPACE:B_ALL_WORKSPACES),
	  fEditShelfMode(editMode)
{
	BScreen screen;
	BView *desktop = new BView(Bounds(), "desktop", B_FOLLOW_NONE, 0);
	desktop->SetViewColor(screen.DesktopColor());
	AddChild(desktop);

	// load the shelf
	BPath path;
	status_t err;
	entry_ref ref;
	err = find_directory(B_SYSTEM_SETTINGS_DIRECTORY, &path, true);
	if (err >= B_OK) {
		BDirectory dir(path.Path());
		if (!dir.Contains("x-vnd.Haiku-Login", B_DIRECTORY_NODE))
			dir.CreateDirectory("x-vnd.Haiku-Login", NULL);
		path.Append("x-vnd.Haiku-Login");
		dir.SetTo(path.Path());
		if (!dir.Contains("Shelf", B_FILE_NODE))
			dir.CreateFile("Shelf", NULL);
		path.Append("Shelf");
		get_ref_for_path(path.Path(), &ref);
	}

	fDesktopShelf = new BShelf(&ref, desktop, fEditShelfMode, "DesktopShelf");
	if (fDesktopShelf)
		fDesktopShelf->SetDisplaysZombies(true);
}
Beispiel #2
0
/**
 * set option from pen
 */
static nserror
set_colour_from_ui(struct nsoption_s *opts,
                   color_which ui,
                   enum nsoption_e option,
                   colour def_colour)
{
	if (ui != NOCOL) {
		rgb_color c;
		if (ui == B_DESKTOP_COLOR) {
			BScreen s;
			c = s.DesktopColor();
		} else {
			c = ui_color(ui);
		}

		def_colour = ((((uint32_t)c.blue << 16) & 0xff0000) |
					  ((c.green << 8) & 0x00ff00) |
					  ((c.red) & 0x0000ff));
	}

	opts[option].value.c = def_colour;

	return NSERROR_OK;
}
Beispiel #3
0
status_t
BackgroundThemesAddon::MakeTheme(BMessage &theme, uint32 flags)
{
	BMessage backgrounds;
	status_t err = B_OK;
	BPath pDesktop;
	struct attr_info ai;
	char *pAttr;
	BScreen bs;
	rgb_color last_color = {0, 0, 0, 254};
	rgb_color col;
	int last_change = 0;
	int i;
	
	(void)flags;
	err = MyMessage(theme, backgrounds);
	if (err)
		backgrounds.MakeEmpty();
	
	if (find_directory(B_DESKTOP_DIRECTORY, &pDesktop) < B_OK)
		return EINVAL;
	BNode nDesktop(pDesktop.Path());
	if (nDesktop.InitCheck() < B_OK)
		return nDesktop.InitCheck();
	if (nDesktop.GetAttrInfo(B_BACKGROUND_INFO, &ai) < B_OK)
		return EIO;
	pAttr = new char[ai.size];
	if (pAttr == NULL)
		return ENOMEM;
	err = nDesktop.ReadAttr(B_BACKGROUND_INFO, ai.type, 0LL, pAttr, ai.size);
	if (err < B_OK)
		goto getout;
	err = backgrounds.Unflatten(pAttr);
	if (err < B_OK)
		goto getout;

	// make sure other colors are removed
	backgrounds.RemoveName(B__DESKTOP_COLOR);

	// get desktop color... XXX: move it in ui_settings ?
	// should work as the rest of the fields (grouping)
	for (i = 0; i < count_workspaces(); i++) {
		col = bs.DesktopColor(i);
		if (memcmp(&last_color, &col, sizeof(rgb_color))) {
			last_change = i;
			last_color = col;
		}
	}
	//printf("ws col cnt %d\n", last_change);
	for (i = 0; i <= last_change; i++) {
		col = bs.DesktopColor(i);
		AddRGBColor(backgrounds, B__DESKTOP_COLOR, col);
		//backgrounds->AddData(B__DESKTOP_COLOR, (type_code)'RGBC', &col, 4);
	}

	err = SetMyMessage(theme, backgrounds);
	return err;

getout:
	delete [] pAttr;
	return err;
}
Beispiel #4
0
status_t
BackgroundThemesAddon::ApplyTheme(BMessage &theme, uint32 flags)
{
	BMessage backgrounds;
	status_t err = B_OK;
	BPath pDesktop;
	ssize_t flatSize;
	char *pAttr;

	if (!(flags & UI_THEME_SETTINGS_SET_ALL) || !(AddonFlags() & Z_THEME_ADDON_DO_SET_ALL))
		return B_OK;

	err = MyMessage(theme, backgrounds);
	if (err)
		return err;

	// set desktop colors
	BScreen bs;
	rgb_color col;
	//const rgb_color *c;
	col = bs.DesktopColor(0); // by
	// should work as the rest of the fields (grouping)
	for (int i = 0; i < count_workspaces(); i++) {
		//ssize_t sz = 4;
		if (FindRGBColor(backgrounds, B__DESKTOP_COLOR, i, &col) != B_OK && i == 0)
		//if (backgrounds.FindData(B__DESKTOP_COLOR, (type_code)'RGBC', i, (const void **)&c, &sz) != B_OK && i == 0)
			break; // if no color at all, don't set them
		bs.SetDesktopColor(col, i, true);
	}
	// make sure we don't leave our garbage in the message
	// as it would offset the next call by adding rgb_colors on existing ones
	backgrounds.RemoveName(B__DESKTOP_COLOR);

	BMessenger tracker("application/x-vnd.Be-TRAK");
	BMessage m(B_RESTORE_BACKGROUND_IMAGE);

	if (find_directory(B_DESKTOP_DIRECTORY, &pDesktop) < B_OK)
		return EINVAL;
	BNode nDesktop(pDesktop.Path());
	if (nDesktop.InitCheck() < B_OK)
		return nDesktop.InitCheck();
	flatSize = backgrounds.FlattenedSize();
	pAttr = new char[flatSize];
	if (pAttr == NULL)
		return ENOMEM;
	err = backgrounds.Flatten(pAttr, flatSize);
	if (err < B_OK)
		goto getout;
	err = nDesktop.WriteAttr(B_BACKGROUND_INFO, B_MESSAGE_TYPE, 0LL, pAttr, flatSize);
	if (err < B_OK)
		goto getout;

	//m.AddSpecifier("Window", "Desktop");
	tracker.SendMessage(&m);

	return B_OK;

getout:
	delete [] pAttr;
	return err;
}