Esempio n. 1
0
WorkspacesWindow::WorkspacesWindow(WorkspacesSettings *settings)
	: BWindow(settings->WindowFrame(), "Workspaces", B_TITLED_WINDOW_LOOK,
 			B_NORMAL_WINDOW_FEEL, B_AVOID_FRONT | B_WILL_ACCEPT_FIRST_CLICK,
 			B_ALL_WORKSPACES),
 	fSettings(settings),
 	fAutoRaising(false)
{
	AddChild(new WorkspacesView(Bounds()));

	if (!fSettings->HasBorder())
		SetLook(B_NO_BORDER_WINDOW_LOOK);
	else if (!fSettings->HasTitle())
		SetLook(B_MODAL_WINDOW_LOOK);

	if (fSettings->AlwaysOnTop())
		SetFeel(B_FLOATING_ALL_WINDOW_FEEL);
	else
		SetAutoRaise(fSettings->AutoRaising());
}
Esempio n. 2
0
void
WorkspacesWindow::MessageReceived(BMessage *message)
{
	switch (message->what) {
		case B_SIMPLE_DATA:
		{
			// Drop from Tracker
			entry_ref ref;
			for (int i = 0; (message->FindRef("refs", i, &ref) == B_OK); i++)
				be_roster->Launch(&ref);
			break;
		}

		case B_ABOUT_REQUESTED:
			PostMessage(message, ChildAt(0));
			break;

		case kMsgToggleBorder:
		{
			bool enable = false;
			if (Look() == B_NO_BORDER_WINDOW_LOOK)
				enable = true;

			if (enable)
				if (fSettings->HasTitle())
					SetLook(B_TITLED_WINDOW_LOOK);
				else
					SetLook(B_MODAL_WINDOW_LOOK);
			else
				SetLook(B_NO_BORDER_WINDOW_LOOK);

			fSettings->SetHasBorder(enable);
			break;
		}

		case kMsgToggleTitle:
		{
			bool enable = false;
			if (Look() == B_MODAL_WINDOW_LOOK
				|| Look() == B_NO_BORDER_WINDOW_LOOK)
				enable = true;

			if (enable)
				SetLook(B_TITLED_WINDOW_LOOK);
			else
				SetLook(B_MODAL_WINDOW_LOOK);

			// No matter what the setting for title, we must force the border on
			fSettings->SetHasBorder(true);
			fSettings->SetHasTitle(enable);
			break;
		}

		case kMsgToggleAutoRaise:
			SetAutoRaise(!IsAutoRaising());
			SetFeel(B_NORMAL_WINDOW_FEEL);
			break;

		case kMsgToggleAlwaysOnTop:
		{
			bool enable = false;
			if (Feel() != B_FLOATING_ALL_WINDOW_FEEL)
				enable = true;

			if (enable)
				SetFeel(B_FLOATING_ALL_WINDOW_FEEL);
			else
				SetFeel(B_NORMAL_WINDOW_FEEL);

			fSettings->SetAlwaysOnTop(enable);
			break;
		}

		default:
			BWindow::MessageReceived(message);
			break;
	}
}
Esempio n. 3
0
WorkspacesWindow::WorkspacesWindow(WorkspacesSettings *settings)
	:
	BWindow(settings->WindowFrame(), B_TRANSLATE_SYSTEM_NAME("Workspaces"),
		B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
		B_AVOID_FRONT | B_WILL_ACCEPT_FIRST_CLICK | B_CLOSE_ON_ESCAPE,
		B_ALL_WORKSPACES),
	fSettings(settings),
	fSwitchOnWheel(false)
{
	// Turn window decor on to grab decor widths.
	BMessage windowSettings;
	float borderWidth = 0;

	SetLook(B_TITLED_WINDOW_LOOK);
	if (GetDecoratorSettings(&windowSettings) == B_OK) {
		BRect tabFrame = windowSettings.FindRect("tab frame");
		borderWidth = windowSettings.FindFloat("border width");
		fTabHeight = tabFrame.Height();
		fBorderWidth = borderWidth;
	}

	if (!fSettings->SettingsLoaded()) {
		// No settings, compute a reasonable default frame.
		// We aim for previews at 10% of actual screen size, and matching the
		// aspect ratio. We then scale that down, until it fits the screen.
		// Finally, we put the window on the bottom right of the screen so the
		// auto-raise mode can be used.

		BScreen screen;

		float screenWidth = screen.Frame().Width();
		float screenHeight = screen.Frame().Height();
		float aspectRatio = screenWidth / screenHeight;

		uint32 columns, rows;
		BPrivate::get_workspaces_layout(&columns, &rows);

		// default size of ~1/10 of screen width
		float workspaceWidth = screenWidth / 10;
		float workspaceHeight = workspaceWidth / aspectRatio;

		float width = floor(workspaceWidth * columns);
		float height = floor(workspaceHeight * rows);

		// If you have too many workspaces to fit on the screen, shrink until
		// they fit.
		while (width + 2 * borderWidth > screenWidth
				|| height + 2 * borderWidth + GetTabHeight() > screenHeight) {
			width = floor(0.95 * width);
			height = floor(0.95 * height);
		}

		BRect frame = fSettings->ScreenFrame();
		frame.OffsetBy(-2.0 * borderWidth, -2.0 * borderWidth);
		frame.left = frame.right - width;
		frame.top = frame.bottom - height;
		ResizeTo(frame.Width(), frame.Height());

		// Put it in bottom corner by default.
		MoveTo(screenWidth - frame.Width() - borderWidth,
			screenHeight - frame.Height() - borderWidth);

		fSettings->SetWindowFrame(frame);
	}

	if (!fSettings->HasBorder())
		SetLook(B_NO_BORDER_WINDOW_LOOK);
	else if (!fSettings->HasTitle())
		SetLook(B_MODAL_WINDOW_LOOK);

	AddChild(new WorkspacesView(Bounds()));

	if (fSettings->AlwaysOnTop())
		SetFeel(B_FLOATING_ALL_WINDOW_FEEL);
	else
		SetAutoRaise(fSettings->AutoRaising());

	SetSwitchOnWheel(fSettings->SwitchOnWheel());
}