Skip to content

Commit

Permalink
offline: Reduce plymouth messages flickering
Browse files Browse the repository at this point in the history
The fact that plymouth prints messages centered causes unpleasant
flickering during the offline transaction execution.
Reduce flickering by normalizing all the messages to the same size, so
the '[count/total]' part of the messages stays on the fixed position.
  • Loading branch information
m-blaha committed Feb 26, 2025
1 parent b58d219 commit c5fe158
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions dnf5/commands/offline/offline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const sdbus::ObjectPath SYSTEMD_OBJECT_PATH{"/org/freedesktop/systemd1"};
const SDBUS_INTERFACE_NAME_TYPE SYSTEMD_MANAGER_INTERFACE{"org.freedesktop.systemd1.Manager"};
const SDBUS_INTERFACE_NAME_TYPE SYSTEMD_UNIT_INTERFACE{"org.freedesktop.systemd1.Unit"};
const std::string SYSTEMD_SERVICE_NAME{"dnf5-offline-transaction.service"};
const std::size_t PLYMOUTH_LINE_LENGTH{75};

int call(const std::string & command, const std::vector<std::string> & args) {
std::vector<char *> c_args;
Expand Down Expand Up @@ -99,11 +100,12 @@ class PlymouthOutput {
bool ping() { return plymouth({"--ping"}); }
bool set_mode() { return plymouth({"change-mode", "--system-upgrade"}); }
bool message(const std::string & message) {
if (last_message.has_value() && message == last_message) {
auto msg = normalize_message(message);
if (last_message.has_value() && msg == last_message) {
plymouth({"hide-message", "--text", last_message.value()});
}
last_message = message;
return plymouth({"display-message", "--text", message});
last_message = msg;
return plymouth({"display-message", "--text", msg});
}
bool progress(const int percentage) {
return plymouth({"system-update", "--progress", std::to_string(percentage)});
Expand All @@ -124,6 +126,14 @@ class PlymouthOutput {
}
return alive;
}
std::string normalize_message(const std::string & original_message) {
std::string message{original_message};
const auto message_length = message.length();
if (message_length < PLYMOUTH_LINE_LENGTH) {
message.append(PLYMOUTH_LINE_LENGTH - message_length, ' ');
}
return message.substr(0, PLYMOUTH_LINE_LENGTH);
}
};

/// Extend RpmTransCB to also display messages with Plymouth
Expand Down

0 comments on commit c5fe158

Please sign in to comment.