Dear LyX developers,

Here's a patch for adjusting editor text width in windowed mode (see
ticket https://www.lyx.org/trac/ticket/9376). It's an adaptation of
the previous patch uploaded by stwitt (two years ago). Please try it
out when you get a chance!

Since I couldn't access the true screen DPI from within
prefs2prefs.py, this patch removes the old settings \fullscreen_width
and \fullscreen_limit rather than hardcoding a default DPI value. But
if you think a different approach would be preferable, I'd be happy to
change it.

Best regards,
Christopher
From a6866f608764d758b91d7dfd1152f47711127456 Mon Sep 17 00:00:00 2001
From: chillenb <chillenb.li...@gmail.com>
Date: Fri, 21 Oct 2022 18:11:12 -0400
Subject: [PATCH] adjust text display width in windowed mode

---
 lib/configure.py                  |   2 +-
 lib/scripts/prefs2prefs_prefs.py  |  15 +++-
 src/BufferView.cpp                |  11 ++-
 src/LyXRC.cpp                     |  34 ++++----
 src/LyXRC.h                       |  10 +--
 src/frontends/qt/GuiPrefs.cpp     |  25 +++---
 src/frontends/qt/GuiPrefs.h       |   2 +-
 src/frontends/qt/ui/PrefEditUi.ui | 126 ++++++++++++++----------------
 8 files changed, 120 insertions(+), 105 deletions(-)

diff --git a/lib/configure.py b/lib/configure.py
index 727fb03868..615d294df1 100644
--- a/lib/configure.py
+++ b/lib/configure.py
@@ -2002,7 +2002,7 @@ if __name__ == '__main__':
     lyx_check_config = True
     lyx_kpsewhich = True
     outfile = 'lyxrc.defaults'
-    lyxrc_fileformat = 36
+    lyxrc_fileformat = 37
     rc_entries = ''
     lyx_keep_temps = False
     version_suffix = ''
diff --git a/lib/scripts/prefs2prefs_prefs.py b/lib/scripts/prefs2prefs_prefs.py
index 78870a3402..a5a3a7dbf1 100644
--- a/lib/scripts/prefs2prefs_prefs.py
+++ b/lib/scripts/prefs2prefs_prefs.py
@@ -162,6 +162,12 @@
 #   (the new default is true, so this keeps behavior the same for 
 #   existing users)
 
+# Incremented to format 37, by chillenb
+#  Remove \fullscreen_width
+#  Remove \fullscreen_limit
+#  Add \screen_width
+#  Add \screen_limit
+
 # NOTE: The format should also be updated in LYXRC.cpp and
 # in configure.py (search for lyxrc_fileformat).
 
@@ -492,6 +498,12 @@ def add_spellcheck_default(lines):
 			return
 	lines.append("\\spellcheck_continuously false")
 
+def remove_fullscreen_widthlimit(line):
+	lower = line.lower()
+	if lower.startswith("\\fullscreen_width") or lower.startswith("\\fullscreen_limit"):
+		return (True, "")
+	return no_match
+
 # End conversions for LyX 2.3 to 2.4
 ####################################
 
@@ -542,5 +554,6 @@ conversions = [
 	[ 33, []],
 	[ 34, [rename_cyrillic_kmap_files]],
 	[ 35, [add_dark_color]],
-	[ 36, [add_spellcheck_default]]
+	[ 36, [add_spellcheck_default]],
+	[ 37, [remove_fullscreen_widthlimit]]
 ]
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 52baf098ef..b36b8ee5b6 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -342,11 +342,14 @@ int BufferView::defaultMargin() const
 
 int BufferView::rightMargin() const
 {
-	// The additional test for the case the outliner is opened.
-	if (full_screen_ && lyxrc.full_screen_limit)
-		return max(defaultMargin(), (width_ - lyxrc.full_screen_width) / 2);
+	const int screen_width = inPixels(lyxrc.screen_width);
 
-	return defaultMargin();
+	// The additional test for the case the outliner is opened.
+	if (!lyxrc.screen_limit || width_ < screen_width + 2 * defaultMargin()) {
+		return defaultMargin();
+	} else {
+		return (width_ - screen_width) / 2;
+	}
 }
 
 
diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp
index 13164373f6..6e962c3506 100644
--- a/src/LyXRC.cpp
+++ b/src/LyXRC.cpp
@@ -60,7 +60,7 @@ namespace {
 
 // The format should also be updated in configure.py, and conversion code
 // should be added to prefs2prefs_prefs.py.
-static unsigned int const LYXRC_FILEFORMAT = 36; // rkh: spellcheck_continuously default
+static unsigned int const LYXRC_FILEFORMAT = 37; // chillenb: screen_width and screen_limit
 // when adding something to this array keep it sorted!
 LexerKeyword lyxrcTags[] = {
 	{ "\\accept_compound", LyXRC::RC_ACCEPT_COMPOUND },
@@ -116,13 +116,11 @@ LexerKeyword lyxrcTags[] = {
 	{ "\\format", LyXRC::RC_FILEFORMAT },
 	{ "\\forward_search_dvi", LyXRC::RC_FORWARD_SEARCH_DVI },
 	{ "\\forward_search_pdf", LyXRC::RC_FORWARD_SEARCH_PDF },
-	{ "\\fullscreen_limit", LyXRC::RC_FULL_SCREEN_LIMIT },
 	{ "\\fullscreen_menubar", LyXRC::RC_FULL_SCREEN_MENUBAR },
 	{ "\\fullscreen_scrollbar", LyXRC::RC_FULL_SCREEN_SCROLLBAR },
 	{ "\\fullscreen_statusbar", LyXRC::RC_FULL_SCREEN_STATUSBAR },
 	{ "\\fullscreen_tabbar", LyXRC::RC_FULL_SCREEN_TABBAR },
 	{ "\\fullscreen_toolbars", LyXRC::RC_FULL_SCREEN_TOOLBARS },
-	{ "\\fullscreen_width", LyXRC::RC_FULL_SCREEN_WIDTH },
 	{ "\\group_layouts", LyXRC::RC_GROUP_LAYOUTS },
 	{ "\\gui_language", LyXRC::RC_GUI_LANGUAGE },
 	{ "\\hunspelldir_path", LyXRC::RC_HUNSPELLDIR_PATH },
@@ -177,6 +175,8 @@ LexerKeyword lyxrcTags[] = {
 	{ "\\screen_font_sizes", LyXRC::RC_SCREEN_FONT_SIZES },
 	{ "\\screen_font_typewriter", LyXRC::RC_SCREEN_FONT_TYPEWRITER },
 	{ "\\screen_font_typewriter_foundry", LyXRC::RC_SCREEN_FONT_TYPEWRITER_FOUNDRY },
+	{ "\\screen_limit", LyXRC::RC_SCREEN_LIMIT },
+	{ "\\screen_width", LyXRC::RC_SCREEN_WIDTH },
 	{ "\\screen_zoom", LyXRC::RC_SCREEN_ZOOM },
 	{ "\\scroll_below_document", LyXRC::RC_SCROLL_BELOW_DOCUMENT },
 	{ "\\scroll_wheel_zoom", LyXRC::RC_SCROLL_WHEEL_ZOOM },
@@ -1038,8 +1038,8 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
 		case RC_GROUP_LAYOUTS:
 			lexrc >> group_layouts;
 			break;
-		case RC_FULL_SCREEN_LIMIT:
-			lexrc >> full_screen_limit;
+		case RC_SCREEN_LIMIT:
+			lexrc >> screen_limit;
 			break;
 		case RC_FULL_SCREEN_TOOLBARS:
 			lexrc >> full_screen_toolbars;
@@ -1056,8 +1056,8 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
 		case RC_FULL_SCREEN_MENUBAR:
 			lexrc >> full_screen_menubar;
 			break;
-		case RC_FULL_SCREEN_WIDTH:
-			lexrc >> full_screen_width;
+		case RC_SCREEN_WIDTH:
+			lexrc >> screen_width;
 			break;
 		case RC_OPEN_BUFFERS_IN_TABS:
 			lexrc >> open_buffers_in_tabs;
@@ -1920,11 +1920,11 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
 		if (tag != RC_LAST)
 			break;
 		// fall through
-	case RC_FULL_SCREEN_LIMIT:
+	case RC_SCREEN_LIMIT:
 		if (ignore_system_lyxrc ||
-		    full_screen_limit != system_lyxrc.full_screen_limit) {
-			os << "\\fullscreen_limit "
-			   << convert<string>(full_screen_limit)
+		    screen_limit != system_lyxrc.screen_limit) {
+			os << "\\screen_limit "
+			   << convert<string>(screen_limit)
 			   << '\n';
 		}
 		if (tag != RC_LAST)
@@ -1980,11 +1980,11 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
 		if (tag != RC_LAST)
 			break;
 		// fall through
-	case RC_FULL_SCREEN_WIDTH:
+	case RC_SCREEN_WIDTH:
 		if (ignore_system_lyxrc ||
-		    full_screen_width != system_lyxrc.full_screen_width) {
-			os << "\\fullscreen_width "
-			   << convert<string>(full_screen_width)
+		    screen_width != system_lyxrc.screen_width) {
+			os << "\\screen_width "
+			   << screen_width.asString()
 			   << '\n';
 		}
 		if (tag != RC_LAST)
@@ -3064,13 +3064,13 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
 	case LyXRC::RC_SINGLE_CLOSE_TAB_BUTTON:
 	case LyXRC::RC_SINGLE_INSTANCE:
 	case LyXRC::RC_SORT_LAYOUTS:
-	case LyXRC::RC_FULL_SCREEN_LIMIT:
+	case LyXRC::RC_SCREEN_LIMIT:
 	case LyXRC::RC_FULL_SCREEN_SCROLLBAR:
 	case LyXRC::RC_FULL_SCREEN_MENUBAR:
 	case LyXRC::RC_FULL_SCREEN_STATUSBAR:
 	case LyXRC::RC_FULL_SCREEN_TABBAR:
 	case LyXRC::RC_FULL_SCREEN_TOOLBARS:
-	case LyXRC::RC_FULL_SCREEN_WIDTH:
+	case LyXRC::RC_SCREEN_WIDTH:
 	case LyXRC::RC_VISUAL_CURSOR:
 	case LyXRC::RC_CLOSE_BUFFER_WITH_LAST_VIEW:
 	case LyXRC::RC_VIEWER:
diff --git a/src/LyXRC.h b/src/LyXRC.h
index 6e82a6def9..1119b181c3 100644
--- a/src/LyXRC.h
+++ b/src/LyXRC.h
@@ -90,13 +90,13 @@ public:
 		RC_FILEFORMAT,
 		RC_FORWARD_SEARCH_DVI,
 		RC_FORWARD_SEARCH_PDF,
-		RC_FULL_SCREEN_LIMIT,
+		RC_SCREEN_LIMIT,
 		RC_FULL_SCREEN_SCROLLBAR,
 		RC_FULL_SCREEN_STATUSBAR,
 		RC_FULL_SCREEN_TABBAR,
 		RC_FULL_SCREEN_MENUBAR,
 		RC_FULL_SCREEN_TOOLBARS,
-		RC_FULL_SCREEN_WIDTH,
+		RC_SCREEN_WIDTH,
 		RC_GEOMETRY_SESSION,
 		RC_GROUP_LAYOUTS,
 		RC_GUI_LANGUAGE,
@@ -511,9 +511,9 @@ public:
 	/// Toggle statusbar in fullscreen mode?
 	bool full_screen_statusbar = true;
 	/// Limit the text width?
-	bool full_screen_limit = false;
-	/// Width of limited screen (in pixels) in fullscreen mode
-	int full_screen_width = 700;
+	bool screen_limit = false;
+    /// Width of limited screen width 
+ 	Length screen_width = Length(7, Length::IN); 
 	///
 	bool completion_cursor_text = true;
 	///
diff --git a/src/frontends/qt/GuiPrefs.cpp b/src/frontends/qt/GuiPrefs.cpp
index 5fa3b940d4..3b2a1c2c35 100644
--- a/src/frontends/qt/GuiPrefs.cpp
+++ b/src/frontends/qt/GuiPrefs.cpp
@@ -33,6 +33,7 @@
 #include "FuncRequest.h"
 #include "KeySequence.h"
 #include "Language.h"
+#include "LengthCombo.h"
 #include "LyXAction.h"
 #include "LyX.h"
 #include "PanelStack.h"
@@ -2812,7 +2813,9 @@ PrefEdit::PrefEdit(GuiPreferences * form)
 		this, SIGNAL(changed()));
 	connect(citationSearchLE, SIGNAL(textChanged(QString)),
 		this, SIGNAL(changed()));
-	connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
+	connect(screenWidthLE, SIGNAL(textChanged(QString)),
+		this, SIGNAL(changed()));
+	connect(screenWidthUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)), 
 		this, SIGNAL(changed()));
 	connect(toggleTabbarCB, SIGNAL(toggled(bool)),
 		this, SIGNAL(changed()));
@@ -2827,10 +2830,11 @@ PrefEdit::PrefEdit(GuiPreferences * form)
 }
 
 
-void PrefEdit::on_fullscreenLimitCB_toggled(bool const state)
+void PrefEdit::on_screenLimitCB_toggled(bool const state)
 {
-	fullscreenWidthSB->setEnabled(state);
-	fullscreenWidthLA->setEnabled(state);
+	screenWidthLE->setEnabled(state);
+	screenWidthLA->setEnabled(state);
+	screenWidthUnitCO->setEnabled(state);
 	changed();
 }
 
@@ -2864,8 +2868,8 @@ void PrefEdit::applyRC(LyXRC & rc) const
 	rc.full_screen_statusbar = toggleStatusbarCB->isChecked();
 	rc.full_screen_tabbar = toggleTabbarCB->isChecked();
 	rc.full_screen_menubar = toggleMenubarCB->isChecked();
-	rc.full_screen_width = fullscreenWidthSB->value();
-	rc.full_screen_limit = fullscreenLimitCB->isChecked();
+    rc.screen_width = Length(widgetsToLength(screenWidthLE, screenWidthUnitCO)); 
+    rc.screen_limit = screenLimitCB->isChecked(); 
 }
 
 
@@ -2888,10 +2892,11 @@ void PrefEdit::updateRC(LyXRC const & rc)
 	toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
 	toggleTabbarCB->setChecked(rc.full_screen_tabbar);
 	toggleMenubarCB->setChecked(rc.full_screen_menubar);
-	fullscreenWidthSB->setValue(rc.full_screen_width);
-	fullscreenLimitCB->setChecked(rc.full_screen_limit);
-	fullscreenWidthSB->setEnabled(rc.full_screen_limit);
-	fullscreenWidthLA->setEnabled(rc.full_screen_limit);
+	lengthToWidgets(screenWidthLE, screenWidthUnitCO, rc.screen_width, Length::defaultUnit());
+	screenWidthUnitCO->setEnabled(rc.screen_limit);
+	screenLimitCB->setChecked(rc.screen_limit);
+	screenWidthLE->setEnabled(rc.screen_limit);
+	screenWidthLA->setEnabled(rc.screen_limit); 
 }
 
 
diff --git a/src/frontends/qt/GuiPrefs.h b/src/frontends/qt/GuiPrefs.h
index 5fac6bc5e9..d23759089e 100644
--- a/src/frontends/qt/GuiPrefs.h
+++ b/src/frontends/qt/GuiPrefs.h
@@ -451,7 +451,7 @@ public:
 	void updateRC(LyXRC const & rc) override;
 
 public Q_SLOTS:
-	void on_fullscreenLimitCB_toggled(bool);
+	void on_screenLimitCB_toggled(bool);
 	void on_citationSearchCB_toggled(bool);
 };
 
diff --git a/src/frontends/qt/ui/PrefEditUi.ui b/src/frontends/qt/ui/PrefEditUi.ui
index bcedaf8c51..7a7e30bae1 100644
--- a/src/frontends/qt/ui/PrefEditUi.ui
+++ b/src/frontends/qt/ui/PrefEditUi.ui
@@ -212,6 +212,59 @@
         </property>
        </widget>
       </item>
+      <item row="10" column="0" colspan="3">
+        <layout class="QHBoxLayout" name="horizontalLayout_4">
+         <item>
+          <widget class="QCheckBox" name="screenLimitCB">
+           <property name="text">
+            <string>&amp;Limit text width</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <spacer name="horizontalSpacer_9">
+           <property name="orientation">
+            <enum>Qt::Horizontal</enum>
+           </property>
+           <property name="sizeType">
+            <enum>QSizePolicy::Fixed</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>10</width>
+             <height>20</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+         <item>
+           <widget class="QLabel" name="screenWidthLA">
+             <property name="text">
+               <string>Screen used:</string>
+             </property>
+           </widget>
+         </item>
+         <item>
+           <widget class="lyx::frontend::LengthCombo" name="screenWidthUnitCO" />
+         </item>
+         <item>
+           <widget class="QLineEdit" name="screenWidthLE" />
+         </item>
+         <item>
+          <spacer name="horizontalSpacer_2">
+           <property name="orientation">
+            <enum>Qt::Horizontal</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>157</width>
+             <height>20</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+        </layout>
+       </item>
      </layout>
     </widget>
    </item>
@@ -300,72 +353,6 @@
         </property>
        </spacer>
       </item>
-      <item row="2" column="0" colspan="6">
-       <layout class="QHBoxLayout" name="horizontalLayout_4">
-        <item>
-         <widget class="QCheckBox" name="fullscreenLimitCB">
-          <property name="text">
-           <string>&amp;Limit text width</string>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <spacer name="horizontalSpacer_9">
-          <property name="orientation">
-           <enum>Qt::Horizontal</enum>
-          </property>
-          <property name="sizeType">
-           <enum>QSizePolicy::Fixed</enum>
-          </property>
-          <property name="sizeHint" stdset="0">
-           <size>
-            <width>10</width>
-            <height>20</height>
-           </size>
-          </property>
-         </spacer>
-        </item>
-        <item>
-         <widget class="QLabel" name="fullscreenWidthLA">
-          <property name="text">
-           <string>Screen used (pi&amp;xels):</string>
-          </property>
-          <property name="buddy">
-           <cstring>fullscreenWidthSB</cstring>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <widget class="QSpinBox" name="fullscreenWidthSB">
-          <property name="minimum">
-           <number>0</number>
-          </property>
-          <property name="maximum">
-           <number>10000</number>
-          </property>
-          <property name="singleStep">
-           <number>10</number>
-          </property>
-          <property name="value">
-           <number>700</number>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <spacer name="horizontalSpacer_2">
-          <property name="orientation">
-           <enum>Qt::Horizontal</enum>
-          </property>
-          <property name="sizeHint" stdset="0">
-           <size>
-            <width>157</width>
-            <height>20</height>
-           </size>
-          </property>
-         </spacer>
-        </item>
-       </layout>
-      </item>
       <item row="0" column="0">
        <widget class="QCheckBox" name="toggleToolbarsCB">
         <property name="sizePolicy">
@@ -414,6 +401,13 @@
   </layout>
  </widget>
  <layoutdefault spacing="4" margin="9"/>
+ <customwidgets> 
+  <customwidget> 
+    <class>lyx::frontend::LengthCombo</class> 
+    <extends>QComboBox</extends> 
+    <header>LengthCombo.h</header> 
+  </customwidget> 
+ </customwidgets> 
  <tabstops>
   <tabstop>cursorFollowsCB</tabstop>
   <tabstop>cursorWidthSB</tabstop>
-- 
2.38.1

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to