[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haiku-commits
Subject:    [haiku-commits] BRANCH looncraz-github.fontaware [0ca86935494e] src/servers/app src/kits/interface s
From:       looncraz-github.fontaware <community () haiku-os ! org>
Date:       2015-10-28 22:47:00
Message-ID: 20151028224700.541C95C211D () vmrepo ! haiku-os ! org
[Download RAW message or body]

added 3 changesets to branch 'refs/remotes/looncraz-github/fontaware'
old head: 98016a17029e6e54b713a150527318f97f525185
new head: 0ca86935494e6719cfa61610456e43aefd727d6a
overview: https://github.com/looncraz/haiku/compare/98016a17029e...0ca86935494e

----------------------------------------------------------------------------

11d589f5b383: Initial font awareness
  
  This is already surprisingly functional.

217513784042: Remove cruft
  
  No longer receive this message in ServerWindow

0ca86935494e: Set B_FONT_AWARE and handle B_MENU_FONT
  
  This is a place-holder a proper global be_menu_font.

                                        [ looncraz <looncraz@looncraz.net> ]

----------------------------------------------------------------------------

11 files changed, 200 insertions(+), 32 deletions(-)
headers/os/app/Application.h             | 10 +++-
headers/os/interface/InterfaceDefs.h     | 10 ++++
headers/os/interface/View.h              |  1 +
headers/private/interface/ViewPrivate.h  |  1 +
src/kits/app/Application.cpp             | 60 +++++++++++++++++++++++-
src/kits/interface/View.cpp              | 51 +++++++++++++++++++-
src/servers/app/DesktopSettings.cpp      | 70 +++++++++++++++++++++-------
src/servers/app/DesktopSettings.h        |  1 +
src/servers/app/DesktopSettingsPrivate.h |  6 +--
src/servers/app/ServerApp.cpp            | 13 ++++++
src/servers/app/ServerWindow.cpp         |  9 ----

############################################################################

Commit:      11d589f5b38384d9a3e65f65e3e3120acee60c9d
Author:      looncraz <looncraz@looncraz.net>
Date:        Mon Oct 26 03:27:58 2015 UTC

Initial font awareness

This is already surprisingly functional.

----------------------------------------------------------------------------

diff --git a/headers/os/interface/InterfaceDefs.h b/headers/os/interface/InterfaceDefs.h
index 93dee79..4225ec7 100644
--- a/headers/os/interface/InterfaceDefs.h
+++ b/headers/os/interface/InterfaceDefs.h
@@ -404,6 +404,16 @@ enum {
 };
 
 
+// Global font definitions for B_FONTS_UPDATED
+enum font_which {
+	B_UNKNOWN_FONT	= 0,
+	B_PLAIN_FONT	= 1,	// be_plain_font
+	B_BOLD_FONT		= 2,	// be_bold_font
+	B_FIXED_FONT	= 3,	// be_fixed_font
+	B_MENU_FONT		= 4		// menu_info...
+};
+
+
 status_t		get_deskbar_frame(BRect* frame);
 
 const color_map* system_colors();
diff --git a/headers/private/interface/ViewPrivate.h b/headers/private/interface/ViewPrivate.h
index 676454a..82d7fd9 100644
--- a/headers/private/interface/ViewPrivate.h
+++ b/headers/private/interface/ViewPrivate.h
@@ -144,6 +144,7 @@ class ViewState {
 		alpha_function		alpha_function_mode;
 
 		// fonts
+		font_which			which_font;
 		BFont				font;
 		uint16				font_flags;
 		bool				font_aliasing;
diff --git a/src/kits/app/Application.cpp b/src/kits/app/Application.cpp
index e603788..a0893cd 100644
--- a/src/kits/app/Application.cpp
+++ b/src/kits/app/Application.cpp
@@ -215,6 +215,10 @@ check_app_signature(const char* signature)
 }
 
 
+// BFont update method
+void _init_global_fonts_();
+
+
 #ifndef RUN_WITHOUT_REGISTRAR
 // Fills the passed BMessage with B_ARGV_RECEIVED infos.
 static void
@@ -689,6 +693,26 @@ BApplication::MessageReceived(BMessage* message)
 			be_roster->ActivateApp(Team());
 			break;
 
+		case B_FONTS_UPDATED:
+		{
+			// Each application must update its own font globals
+			_init_global_fonts_();
+
+			AutoLocker<BLooperList> listLock(gLooperList);
+			if (!listLock.IsLocked())
+				break;
+
+			BWindow* window = NULL;
+			uint32 count = gLooperList.CountLoopers();
+			for (uint32 index = 0; index < count; ++index) {
+				window = dynamic_cast<BWindow*>(gLooperList.LooperAt(index));
+				if (window == NULL || (window != NULL && window->fOffscreen))
+					continue;
+				window->PostMessage(message);
+			}
+			break;	
+		}
+
 		case kMsgAppServerRestarted:
 			_ReconnectToServer();
 			break;
diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp
index 980f7ff..ad4890a 100644
--- a/src/kits/interface/View.cpp
+++ b/src/kits/interface/View.cpp
@@ -165,6 +165,7 @@ ViewState::ViewState()
 
 	scale = 1.0;
 
+	which_font = B_PLAIN_FONT;
 	font = *be_plain_font;
 	font_flags = font.Flags();
 	font_aliasing = false;
@@ -2729,6 +2730,15 @@ BView::SetFont(const BFont* font, uint32 mask)
 	if (!font || mask == 0)
 		return;
 
+	if (font == be_plain_font)
+		fState->which_font = B_PLAIN_FONT;
+	else if (font == be_bold_font)
+		fState->which_font = B_BOLD_FONT;
+	else if (font == be_fixed_font)
+		fState->which_font = B_FIXED_FONT;
+	else
+		fState->which_font = B_UNKNOWN_FONT;
+
 	if (mask == B_FONT_ALL) {
 		fState->font = *font;
 	} else {
@@ -6034,12 +6044,35 @@ BView::_DrawAfterChildren(BRect updateRect)
 void
 BView::_FontsUpdated(BMessage* message)
 {
+	font_which which = B_UNKNOWN_FONT;
+	if (fState->which_font != B_UNKNOWN_FONT
+		&& message->FindInt32("which", (int32*)&which) == B_OK
+		&& fState->which_font == which) {
+
+		switch (which) {
+			case B_PLAIN_FONT:
+				SetFont(be_plain_font, fState->font_flags);
+				break;
+			case B_BOLD_FONT:
+				SetFont(be_bold_font, fState->font_flags);
+				break;
+			case B_FIXED_FONT:
+				SetFont(be_fixed_font, fState->font_flags);
+				break;
+			default:
+				break;
+		}
+	}
+
 	MessageReceived(message);
 
 	for (BView* child = fFirstChild; child != NULL;
 			child = child->fNextSibling) {
 		child->_FontsUpdated(message);
 	}
+
+	InvalidateLayout();
+	Invalidate();
 }
 
 
diff --git a/src/servers/app/DesktopSettings.cpp b/src/servers/app/DesktopSettings.cpp
index 3ed9902..9c6764b 100644
--- a/src/servers/app/DesktopSettings.cpp
+++ b/src/servers/app/DesktopSettings.cpp
@@ -461,11 +461,15 @@ DesktopSettingsPrivate::Save(uint32 mask)
 }
 
 
-void
+bool
 DesktopSettingsPrivate::SetDefaultPlainFont(const ServerFont &font)
 {
+	if (fPlainFont == font)
+		return false;
+
 	fPlainFont = font;
 	Save(kFontSettings);
+	return true;
 }
 
 
@@ -476,11 +480,15 @@ DesktopSettingsPrivate::DefaultPlainFont() const
 }
 
 
-void
+bool
 DesktopSettingsPrivate::SetDefaultBoldFont(const ServerFont &font)
 {
+	if (fBoldFont == font)
+		return false;
+
 	fBoldFont = font;
 	Save(kFontSettings);
+	return true;
 }
 
 
@@ -491,11 +499,15 @@ DesktopSettingsPrivate::DefaultBoldFont() const
 }
 
 
-void
+bool
 DesktopSettingsPrivate::SetDefaultFixedFont(const ServerFont &font)
 {
+	if (fFixedFont == font)
+		return false;	
+
 	fFixedFont = font;
 	Save(kFontSettings);
+	return true;
 }
 
 
@@ -958,31 +970,32 @@ LockedDesktopSettings::~LockedDesktopSettings()
 void
 LockedDesktopSettings::SetDefaultPlainFont(const ServerFont &font)
 {
-	fSettings->SetDefaultPlainFont(font);
-	fDesktop->DelayedBroadcastToAllWindows(B_FONTS_UPDATED, DM_60HZ_DELAY,
-		true, DM_MERGE_CANCEL);
+	if (fSettings->SetDefaultPlainFont(font))
+		_FontChanged(B_PLAIN_FONT);
 }
 
 
 void
 LockedDesktopSettings::SetDefaultBoldFont(const ServerFont &font)
 {
-	fSettings->SetDefaultBoldFont(font);
-	fDesktop->DelayedBroadcastToAllWindows(AS_SYSTEM_FONT_CHANGED,
-		DM_60HZ_DELAY, true, DM_MERGE_CANCEL);
-	fDesktop->DelayedBroadcastToAllWindows(B_FONTS_UPDATED, DM_60HZ_DELAY,
-		true, DM_MERGE_CANCEL);
+	if (fSettings->SetDefaultBoldFont(font)) {
+		fDesktop->DelayedBroadcastToAllWindows(AS_SYSTEM_FONT_CHANGED,
+			DM_60HZ_DELAY, true, DM_MERGE_CANCEL);
+
+		_FontChanged(B_BOLD_FONT);
+	}
 }
 
 
 void
 LockedDesktopSettings::SetDefaultFixedFont(const ServerFont &font)
 {
-	fSettings->SetDefaultFixedFont(font);
-	fDesktop->DelayedBroadcastToAllWindows(AS_SYSTEM_FONT_CHANGED,
-		DM_60HZ_DELAY, true, DM_MERGE_CANCEL);
-	fDesktop->DelayedBroadcastToAllWindows(B_FONTS_UPDATED, DM_60HZ_DELAY,
-		true, DM_MERGE_CANCEL);
+	if (fSettings->SetDefaultFixedFont(font)) {
+		fDesktop->DelayedBroadcastToAllWindows(AS_SYSTEM_FONT_CHANGED,
+			DM_60HZ_DELAY, true, DM_MERGE_CANCEL);
+
+		_FontChanged(B_FIXED_FONT);
+	}
 }
 
 
@@ -996,7 +1009,18 @@ LockedDesktopSettings::SetScrollBarInfo(const scroll_bar_info& info)
 void
 LockedDesktopSettings::SetMenuInfo(const menu_info& info)
 {
+	const menu_info& current = fSettings->MenuInfo();
+	bool fontChanged = false;
+
+	if (info.font_size != current.font_size
+		|| info.f_family != current.f_family
+		|| info.f_style != current.f_style)
+		fontChanged = true;
+
 	fSettings->SetMenuInfo(info);
+
+	if (fontChanged)
+		_FontChanged(B_MENU_FONT);	
 }
 
 
@@ -1080,9 +1104,23 @@ LockedDesktopSettings::SetSubpixelAverageWeight(uint8 averageWeight)
 	fSettings->SetSubpixelAverageWeight(averageWeight);
 }
 
+
 void
 LockedDesktopSettings::SetSubpixelOrderingRegular(bool subpixelOrdering)
 {
 	fSettings->SetSubpixelOrderingRegular(subpixelOrdering);
 }
 
+
+void
+LockedDesktopSettings::_FontChanged(font_which which)
+{
+	DelayedMessage delayed(-1, B_FONTS_UPDATED, DM_60HZ_DELAY,
+		B_RELATIVE_TIMEOUT, DM_MERGE_DUPLICATES);
+
+	if (fDesktop->GetAllAppTargets(delayed) <= 0)
+		return;
+
+	if (delayed.Attach<font_which>(which) == B_OK)
+		delayed.Flush();
+}
diff --git a/src/servers/app/DesktopSettings.h b/src/servers/app/DesktopSettings.h
index 6f0a2df..3aa385f 100644
--- a/src/servers/app/DesktopSettings.h
+++ b/src/servers/app/DesktopSettings.h
@@ -110,6 +110,7 @@ public:
 									bool subpixelOrdering);
 
 private:
+			void				_FontChanged(font_which which);
 			Desktop*			fDesktop;
 };
 
diff --git a/src/servers/app/DesktopSettingsPrivate.h b/src/servers/app/DesktopSettingsPrivate.h
index 679b1b4..35f7b5e 100644
--- a/src/servers/app/DesktopSettingsPrivate.h
+++ b/src/servers/app/DesktopSettingsPrivate.h
@@ -28,13 +28,13 @@ public:
 
 			status_t			Save(uint32 mask = kAllSettings);
 
-			void				SetDefaultPlainFont(const ServerFont& font);
+			bool				SetDefaultPlainFont(const ServerFont& font);
 			const ServerFont&	DefaultPlainFont() const;
 
-			void				SetDefaultBoldFont(const ServerFont& font);
+			bool				SetDefaultBoldFont(const ServerFont& font);
 			const ServerFont&	DefaultBoldFont() const;
 
-			void				SetDefaultFixedFont(const ServerFont& font);
+			bool				SetDefaultFixedFont(const ServerFont& font);
 			const ServerFont&	DefaultFixedFont() const;
 
 			void				SetScrollBarInfo(const scroll_bar_info &info);
diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp
index 5edb7dc..2f677e8 100644
--- a/src/servers/app/ServerApp.cpp
+++ b/src/servers/app/ServerApp.cpp
@@ -1827,6 +1827,19 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
 			break;
 		}
 
+		case B_FONTS_UPDATED:
+		{
+			font_which which = B_UNKNOWN_FONT;
+			if (link.Read<font_which>(&which) != B_OK
+				|| which == B_UNKNOWN_FONT)
+				break;
+
+			BMessage message(B_FONTS_UPDATED);
+			message.AddInt32("which", (int32)which);
+			SendMessageToClient(&message);			
+			break;
+		}
+
 		case AS_GET_STRING_WIDTHS:
 		{
 			FTRACE(("ServerApp %s: AS_GET_STRING_WIDTHS\n", Signature()));

############################################################################

Commit:      2175137840425a4b8841430552a97c5b1e95d8d7
Author:      looncraz <looncraz@looncraz.net>
Date:        Wed Oct 28 22:27:10 2015 UTC

Remove cruft

No longer receive this message in ServerWindow

----------------------------------------------------------------------------

diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp
index e69d7a0..7f8be3d 100644
--- a/src/servers/app/ServerWindow.cpp
+++ b/src/servers/app/ServerWindow.cpp
@@ -1016,15 +1016,6 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
 			break;
 		}
 
-		// Forward to client
-		case B_FONTS_UPDATED:
-		{
-			// TODO: would knowing which font was changed be useful?
-			BMessage message(code);
-			SendMessageToClient(&message);
-			break;
-		}
-
 		case AS_REDRAW:
 			// Nothing to do here - the redraws are actually handled by looking
 			// at the fRedrawRequested member variable in _MessageLooper().

############################################################################

Commit:      0ca86935494e6719cfa61610456e43aefd727d6a
Author:      looncraz <looncraz@looncraz.net>
Date:        Wed Oct 28 22:32:28 2015 UTC

Set B_FONT_AWARE and handle B_MENU_FONT

This is a place-holder a proper global be_menu_font.

----------------------------------------------------------------------------

diff --git a/headers/os/app/Application.h b/headers/os/app/Application.h
index ef7881d..898960f 100644
--- a/headers/os/app/Application.h
+++ b/headers/os/app/Application.h
@@ -85,6 +85,13 @@ public:
 									BHandler* handler);
 			void				SetPulseRate(bigtime_t rate);
 
+	// Application-wide font/color update options
+			void				SetFontUpdatesEnabled(bool enabled);
+			bool				FontUpdatesEnabled() const;
+
+			void				SetColorUpdatesEnabled(bool enabled);
+			bool				ColorUpdatesEnabled() const;
+
 	// More scripting
 	virtual status_t			GetSupportedSuites(BMessage* data);
 
@@ -153,7 +160,8 @@ private:
 			BMessageRunner*		fPulseRunner;
 			status_t			fInitError;
 			void*				fServerReadOnlyMemory;
-			uint32				_reserved[12];
+			uint32				fInternalFlags;
+			uint32				_reserved[11];
 
 			bool				fReadyToRunCalled;
 };
diff --git a/headers/os/interface/View.h b/headers/os/interface/View.h
index 1574ba3..0aafae1 100644
--- a/headers/os/interface/View.h
+++ b/headers/os/interface/View.h
@@ -80,6 +80,7 @@ const uint32 B_INPUT_METHOD_AWARE		= 0x00400000UL;	/* 23 */
 const uint32 _B_RESERVED7_				= 0x00200000UL;	/* 22 */
 const uint32 B_SUPPORTS_LAYOUT			= 0x00100000UL;	/* 21 */
 const uint32 B_INVALIDATE_AFTER_LAYOUT	= 0x00080000UL;	/* 20 */
+const uint32 B_FONT_AWARE				= 0x00040000UL; /* 19 */
 
 #define _RESIZE_MASK_ (0xffff)
 
diff --git a/src/kits/app/Application.cpp b/src/kits/app/Application.cpp
index a0893cd..8655e5b 100644
--- a/src/kits/app/Application.cpp
+++ b/src/kits/app/Application.cpp
@@ -74,6 +74,16 @@ enum {
 };
 
 
+enum {
+	kNoInternalFlags	= 0,
+	kNoFontUpdates		= 1 << 0,
+	kNoColorUpdates		= 1 << 1
+};
+
+
+const uint32 kDefaultInternalFlags = kNoFontUpdates;
+
+
 static property_info sPropertyInfo[] = {
 	{
 		"Window",
@@ -357,6 +367,7 @@ BApplication::_InitData(const char* signature, bool initGUI, status_t* _error)
 	fInitialWorkspace = 0;
 	//fDraggedMessage = NULL;
 	fReadyToRunCalled = false;
+	fInternalFlags = kDefaultInternalFlags;
 
 	// initially, there is no pulse
 	fPulseRunner = NULL;
@@ -693,26 +704,6 @@ BApplication::MessageReceived(BMessage* message)
 			be_roster->ActivateApp(Team());
 			break;
 
-		case B_FONTS_UPDATED:
-		{
-			// Each application must update its own font globals
-			_init_global_fonts_();
-
-			AutoLocker<BLooperList> listLock(gLooperList);
-			if (!listLock.IsLocked())
-				break;
-
-			BWindow* window = NULL;
-			uint32 count = gLooperList.CountLoopers();
-			for (uint32 index = 0; index < count; ++index) {
-				window = dynamic_cast<BWindow*>(gLooperList.LooperAt(index));
-				if (window == NULL || (window != NULL && window->fOffscreen))
-					continue;
-				window->PostMessage(message);
-			}
-			break;	
-		}
-
 		case kMsgAppServerRestarted:
 			_ReconnectToServer();
 			break;
@@ -1086,9 +1077,16 @@ BApplication::DispatchMessage(BMessage* message, BHandler* handler)
 		}
 
 		case B_COLORS_UPDATED:
+			if (!ColorUpdatesEnabled())
+				break;
+		case B_FONTS_UPDATED:
 		{
-			// Update the current colormap (if we have one)
-			BPrivate::BColorMapPrivate::Update(message);
+			if (message->what == B_COLORS_UPDATED)
+				BPrivate::BColorMapPrivate::Update(message);
+			else if (FontUpdatesEnabled())
+				_init_global_fonts_();
+			else
+				break;
 
 			AutoLocker<BLooperList> listLock(gLooperList);
 			if (!listLock.IsLocked())
@@ -1159,6 +1157,40 @@ BApplication::SetPulseRate(bigtime_t rate)
 }
 
 
+void
+BApplication::SetFontUpdatesEnabled(bool enabled)
+{
+	if (enabled)
+		fInternalFlags &= ~kNoFontUpdates;
+	else
+		fInternalFlags |= kNoFontUpdates;
+}
+
+
+bool
+BApplication::FontUpdatesEnabled() const
+{
+	return (fInternalFlags & kNoFontUpdates) == 0;
+}
+
+
+void
+BApplication::SetColorUpdatesEnabled(bool enabled)
+{
+	if (enabled)
+		fInternalFlags &= ~kNoColorUpdates;
+	else
+		fInternalFlags |= kNoColorUpdates;
+}
+
+
+bool
+BApplication::ColorUpdatesEnabled() const
+{
+	return (fInternalFlags & kNoColorUpdates) == 0;
+}
+
+
 status_t
 BApplication::GetSupportedSuites(BMessage* data)
 {
diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp
index ad4890a..a7b52c7 100644
--- a/src/kits/interface/View.cpp
+++ b/src/kits/interface/View.cpp
@@ -410,7 +410,7 @@ BView::BView(const char* name, uint32 flags, BLayout* layout)
 	BHandler(name)
 {
 	_InitData(BRect(0, 0, 0, 0), name, B_FOLLOW_NONE,
-		flags | B_SUPPORTS_LAYOUT);
+		flags | B_SUPPORTS_LAYOUT | B_FONT_AWARE);
 	SetLayout(layout);
 }
 
@@ -2736,8 +2736,22 @@ BView::SetFont(const BFont* font, uint32 mask)
 		fState->which_font = B_BOLD_FONT;
 	else if (font == be_fixed_font)
 		fState->which_font = B_FIXED_FONT;
-	else
-		fState->which_font = B_UNKNOWN_FONT;
+	else {
+		// Detect menu font...
+		// TODO: create be_menu_font, and use it!
+		menu_info menuInfo;
+		font_family family;
+		font_style style;
+		font->GetFamilyAndStyle(&family, &style);
+		if (get_menu_info(&menuInfo) == B_OK
+			&& menuInfo.font_size == font->Size()
+			&& menuInfo.f_family == family
+			&& menuInfo.f_style == style) {
+			fState->which_font = B_MENU_FONT;
+		}
+		else
+			fState->which_font = B_UNKNOWN_FONT;
+	}
 
 	if (mask == B_FONT_ALL) {
 		fState->font = *font;
@@ -6045,7 +6059,7 @@ void
 BView::_FontsUpdated(BMessage* message)
 {
 	font_which which = B_UNKNOWN_FONT;
-	if (fState->which_font != B_UNKNOWN_FONT
+	if ((Flags() & B_FONT_AWARE) != 0 && fState->which_font != B_UNKNOWN_FONT
 		&& message->FindInt32("which", (int32*)&which) == B_OK
 		&& fState->which_font == which) {
 
@@ -6059,6 +6073,8 @@ BView::_FontsUpdated(BMessage* message)
 			case B_FIXED_FONT:
 				SetFont(be_fixed_font, fState->font_flags);
 				break;
+			// Menus need to respond to font changes on their own.
+			case B_MENU_FONT:
 			default:
 				break;
 		}


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic