Skip to content

Commit

Permalink
Add functionality to update text and background colors when changing …
Browse files Browse the repository at this point in the history
…themes

JDimを起動した直後やフォントと色の詳細設定ダイアログで「OK」ボタンを
押した際に、ビューで使用する文字色と背景色を更新する処理を追加します。

修正前は、「色の設定を全てデフォルトに戻す」ボタンを操作しなければ
文字色と背景色が更新されませんでした。このため、GTKテーマや
ダークテーマの切り替え後に、板のプロパティのローカルルールなどが
周囲と異なる配色で表示される問題が発生していました。

今回の修正でテーマ変更時に文字色と背景色が自動的に更新されるようになり、
ユーザー体験を向上させます。

制限:
アプリケーション外でGTKテーマを変更した場合、色が自動的に更新されない
問題は残っています。この問題は、時間帯に応じてGTKテーマを切り替える
デスクトップ環境や、アプリケーション起動中にテーマを変更する状況で
発生します。この場合は、フォントと色の詳細設定ダイアログから
「色の設定を全てデフォルトに戻す」を選択し、手動で色を更新してください。

Add functionality to update the text and background colors used in
views upon JDim startup or after pressing the "OK" button in the Font
and Color Preferences dialog.

Previously, text and background colors were only updated by manually
using the "Reset all color settings to default" button. As a result,
issues arose where elements like local board rule properties were
displayed in color schemes inconsistent with the surrounding theme
after switching between GTK or dark themes.

With this update, text and background colors are now automatically
updated when themes are changed, improving the user experience.

Limitations:
Colors are not automatically updated when changing GTK themes outside
the application. This issue may occur in desktop environments that
switch GTK themes based on time or when themes are changed while the
application is running. In such cases, use the Font and Color
Preferences dialog to manually update colors by selecting
"Reset all color settings to default."
  • Loading branch information
ma8ma committed Jan 25, 2025
1 parent 235bd99 commit 962add6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/config/configitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,20 @@ void ConfigItems::reset_colors_dark_theme()
}
}

update_view_colors();
}


/** @brief ビューで使用する文字色と背景色を更新する
*
* @details ビューで使用する文字色と背景色はフォントと色の詳細設定ダイアログにある
* 「色の設定を全てデフォルトに戻す」ボタンで更新されますが、JDimを起動した直後や
* フォントと色の詳細設定ダイアログで「OK」ボタンを押した際も更新する必要があります。
* そのため、 `ConfigItems::reset_colors_dark_theme()` から処理を抽出して関数にまとめ、
* 更新が必要な箇所で呼び出しできるようにします。
*/
void ConfigItems::update_view_colors()
{
// Gtk::Entryのデフォルトの文字色
str_color[ COLOR_CHAR_ENTRY_DEFAULT ] = MISC::get_entry_color_text();

Expand Down
1 change: 1 addition & 0 deletions src/config/configitems.h
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ namespace CONFIG
// 色のリセット
void reset_colors();
void reset_colors_dark_theme();
void update_view_colors();

// プロクシ設定
void set_proxy_for2ch( const std::string& proxy );
Expand Down
1 change: 1 addition & 0 deletions src/config/globalconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ void CONFIG::set_color( const int id, const std::string& color )

void CONFIG::reset_colors(){ get_confitem()->reset_colors(); }
void CONFIG::reset_colors_dark_theme(){ get_confitem()->reset_colors_dark_theme(); }
void CONFIG::update_view_colors(){ get_confitem()->update_view_colors(); }

const std::string& CONFIG::get_gtk_theme_name() { return get_confitem()->gtk_theme_name; }
void CONFIG::set_gtk_theme_name( const std::string& name ) { get_confitem()->gtk_theme_name = name; }
Expand Down
1 change: 1 addition & 0 deletions src/config/globalconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace CONFIG
void set_color( const int id, const std::string& color );
void reset_colors();
void reset_colors_dark_theme();
void update_view_colors();

// GTKテーマの名前
const std::string& get_gtk_theme_name();
Expand Down
2 changes: 2 additions & 0 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ Core::Core( JDWinMain& win_main )
}
// property_gtk_application_prefer_dark_theme() に値を設定しても同期は維持される
Gtk::Settings::get_default()->property_gtk_application_prefer_dark_theme() = CONFIG::get_use_dark_theme();
// 色のセットアップが済んだのでビューで使う文字色と背景色を取得する
CONFIG::update_view_colors();

if( auto icon_theme = CONFIG::get_gtk_icon_theme_name(); ! icon_theme.empty() ) {
// GTKの仕様により property_gtk_icon_theme_name() に値を設定すると
Expand Down
2 changes: 2 additions & 0 deletions src/fontcolorpref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ void FontColorPref::slot_ok_clicked()
}
}
CONFIG::set_use_dark_theme( m_check_dark_theme.get_active() );
// GTKテーマを変更したときは、ビューで使用する文字色と背景色を更新する必要がある
CONFIG::update_view_colors();

if( m_check_system_icon.get_active() ) {
// システム設定のアイコンテーマを使うため、空文字列をセットする
Expand Down

0 comments on commit 962add6

Please sign in to comment.