Make position correction an option

This commit is contained in:
Ximi1970
2024-04-14 21:50:27 +02:00
parent 5ea763b948
commit 795be32773
9 changed files with 1414 additions and 1149 deletions

View File

@@ -49,6 +49,9 @@ Preferences::Preferences( QObject *parent ) : QObject( parent )
m_close_type = PREF_MINIMIZE_MAIN_TRAY_CLOSE_CHILDREN_WINDOWS;
m_minimize_icon_type = PREF_MINIMIZE_TRAY_ICON;
m_window_positions_correction = false;
m_window_positions_correction_type = PREF_NO_CORRECTION;
m_startup_type = PREF_START_DEFAULT;
m_restore_window_positions = false;
@@ -420,6 +423,58 @@ void Preferences::setMinimizeIconType( MinimizeIconType minimize_icon_type )
}
/*
* Get the window positions correction state
*/
bool Preferences::getWindowPositionsCorrection() const
{
return m_window_positions_correction;
}
/*
* Set the window positions correction state
*/
void Preferences::setWindowPositionsCorrection( bool state )
{
if( m_window_positions_correction != state )
{
m_window_positions_correction = state;
/*
* Tell the world the new preference
*/
emit signalWindowPositionsCorrectionChange();
}
}
/*
* Get the window positions correction type
*/
Preferences::WindowPositionsCorrectionType Preferences::getWindowPositionsCorrectionType() const
{
return m_window_positions_correction_type;
}
/*
* Set the minimize type.
*/
void Preferences::setWindowPositionsCorrectionType( WindowPositionsCorrectionType window_positions_correction_type )
{
if( m_window_positions_correction_type != window_positions_correction_type)
{
m_window_positions_correction_type = window_positions_correction_type;
/*
* Tell the world the new preference
*/
emit signalWindowPositionsCorrectionTypeChange();
}
}
/*
* Get the start minmized pref.
*/

View File

@@ -53,6 +53,15 @@ class Preferences : public QObject
PREF_MINIMIZE_TRAY_ICON
};
/*
* Position correction
*/
enum WindowPositionsCorrectionType {
PREF_NO_CORRECTION = 0,
PREF_ADD_CORRECTION,
PREF_SUBTRACT_CORRECTION
};
/*
* Startup types
*/
@@ -258,6 +267,34 @@ class Preferences : public QObject
*/
void setMinimizeIconType( MinimizeIconType minimize_icon_type );
/**
* @brief getWindowPositionsCorrection. Get the window positions correction state.
*
* @return The state.
*/
bool getWindowPositionsCorrection() const;
/**
* @brief setWindowPositionsCorrection. Set the window positions correction state.
*
* @param state The state.
*/
void setWindowPositionsCorrection( bool state );
/**
* @brief getWindowPositionsCorrectionType. Get the window positions correction type
*
* @return the window positions correction type.
*/
WindowPositionsCorrectionType getWindowPositionsCorrectionType() const;
/**
* @brief setWindowPositionsCorrectionType. Set the window positions correction type.
*
* @param window_positions_correction_type The window positions correction type.
*/
void setWindowPositionsCorrectionType( WindowPositionsCorrectionType window_positions_correction_type );
/**
* @brief getDefaultIconType. Get the default icon type.
*
@@ -684,6 +721,16 @@ class Preferences : public QObject
*/
void signalMinimizeIconTypeChange();
/**
* @brief signalWindowPositionsCorrectionChange. Signal a window positions correction change.
*/
void signalWindowPositionsCorrectionChange();
/**
* @brief signalWindowPositionsCorrectionTypeChange. Signal a window positions correction type change.
*/
void signalWindowPositionsCorrectionTypeChange();
/**
* @brief signalStartupTypeChange. Signal a startup type change.
*/
@@ -890,6 +937,16 @@ class Preferences : public QObject
*/
MinimizeIconType m_minimize_icon_type;
/**
* @brief m_window_positions_correction
*/
bool m_window_positions_correction;
/**
* @brief m_window_positions_correction_type
*/
WindowPositionsCorrectionType m_window_positions_correction_type;
/**
* @brief m_startup_type. Startup TB preference.
*/

File diff suppressed because it is too large Load Diff

View File

@@ -56,7 +56,7 @@ PreferencesDialog::PreferencesDialog( SysTrayXLink *link, Preferences *pref, QWi
m_ui->minimizeMethod2RadioButton->hide();
/*
* Set minimize type button Ids
* Set minimize icon type button Ids
*/
m_ui->minimizeIconTypeGroup->setId( m_ui->defaultMinimizeIconRadioButton, Preferences::PREF_DEFAULT_MINIMIZE_ICON);
m_ui->minimizeIconTypeGroup->setId( m_ui->minimizeTrayIconRadioButton, Preferences::PREF_MINIMIZE_TRAY_ICON );
@@ -68,9 +68,17 @@ PreferencesDialog::PreferencesDialog( SysTrayXLink *link, Preferences *pref, QWi
m_ui->startupTypeGroup->setId( m_ui->startMinimizedRadioButton, Preferences::PREF_START_MINIMIZED);
m_ui->startupTypeGroup->setId( m_ui->startDockedRadioButton, Preferences::PREF_START_DOCKED );
/*
* Set position button Ids
*/
m_ui->positionGroup->setId( m_ui->noTitlebarCorrectionRadioButton, Preferences::PREF_NO_CORRECTION);
m_ui->positionGroup->setId( m_ui->addTitlebarCorrectionRadioButton, Preferences::PREF_ADD_CORRECTION );
m_ui->positionGroup->setId( m_ui->subtractTitlebarCorrectionRadioButton, Preferences::PREF_SUBTRACT_CORRECTION );
#ifdef Q_OS_WIN
m_ui->hideDefaultIconCheckBox->hide();
m_ui->positionGroupBox->hide();
m_ui->restorePositionscheckBox->hide();
#endif
@@ -299,6 +307,24 @@ void PreferencesDialog::setMinimizeIconType( Preferences::MinimizeIconType mi
}
/*
* Set the positions correction state
*/
void PreferencesDialog::setWindowPositionsCorrection( bool state )
{
m_ui->correctWinPosCheckBox->setChecked( state );
}
/*
* Set the position correction
*/
void PreferencesDialog::setWindowPositionsCorrectionType( Preferences::WindowPositionsCorrectionType position_correction )
{
( m_ui->positionGroup->button( position_correction ) )->setChecked( true );
}
/*
* Set the startup type
*/
@@ -631,6 +657,10 @@ void PreferencesDialog::slotAccept()
m_pref->setMinimizeType( static_cast< Preferences::MinimizeType >( m_ui->minimizeTypeGroup->checkedId() ) );
m_pref->setMinimizeIconType( static_cast< Preferences::MinimizeIconType >( m_ui->minimizeIconTypeGroup->checkedId() ) );
m_pref->setWindowPositionsCorrection( m_ui->correctWinPosCheckBox->isChecked() );
m_pref->setWindowPositionsCorrectionType( static_cast< Preferences::WindowPositionsCorrectionType >( m_ui->positionGroup->checkedId() ) );
m_pref->setStartupType( static_cast< Preferences::StartupType >( m_ui->startupTypeGroup->checkedId() ) );
m_pref->setRestoreWindowPositions( m_ui->restorePositionscheckBox->isChecked() );
m_pref->setCloseType( static_cast< Preferences::CloseType >( m_ui->closeTypeGroup->checkedId() ) );
@@ -699,6 +729,8 @@ void PreferencesDialog::slotReject()
setMinimizeType( m_pref->getMinimizeType() );
setMinimizeIconType( m_pref->getMinimizeIconType() );
setWindowPositionsCorrection( m_pref->getWindowPositionsCorrection() );
setWindowPositionsCorrectionType( m_pref->getWindowPositionsCorrectionType() );
setStartupType( m_pref->getStartupType() );
setRestoreWindowPositions( m_pref->getRestoreWindowPositions() );
setCloseType( m_pref->getCloseType() );

View File

@@ -83,6 +83,20 @@ class PreferencesDialog : public QDialog
*/
void setMinimizeIconType( Preferences::MinimizeIconType minimize_icon_type );
/**
* @brief setWindowPositionsCorrection. Set the window postions correction state.
*
* @param state The state.
*/
void setWindowPositionsCorrection( bool state );
/**
* @brief setWindowPositionsCorrectionType. Set the window positions correction type.
*
* @param position_correction The correction type.
*/
void setWindowPositionsCorrectionType( Preferences::WindowPositionsCorrectionType position_correction );
/**
* @brief setStartupType. Set the startup type.
*

View File

@@ -403,11 +403,34 @@ void WindowCtrlUnix::updatePositions()
int y3;
GetWindowPosition( m_display, window, &x, &y, &x1, &y1, &x2, &y2, &x3, &y3 );
/*
* Apply the requested correction
*/
QPoint point;
switch( m_pref->getWindowPositionsCorrectionType() )
{
case Preferences::PREF_NO_CORRECTION:
{
point = QPoint( x, y );
break;
}
case Preferences::PREF_ADD_CORRECTION:
{
point = QPoint( x + left, y + top );
break;
}
case Preferences::PREF_SUBTRACT_CORRECTION:
{
point = QPoint( x - left, y - top );
break;
}
}
/*
* Update the list?
*/
QPoint point = QPoint( x - left, y - top );
if( m_tb_window_positions[ window ] != point )
{
m_tb_window_positions[ window ] = point;
@@ -640,13 +663,19 @@ void WindowCtrlUnix::normalizeWindow( quint64 window )
Sync( m_display );
/*
* Move the window to the last recorded position, seems to be needed for wayland
* Force the window to the last known position?
*/
QPoint pos = m_tb_window_positions[ window ];
MoveWindow( m_display, window, pos.x(), pos.y() );
Flush( m_display );
if( m_pref->getWindowPositionsCorrection() )
{
/*
* Move the window to the last recorded position
*/
QPoint pos = m_tb_window_positions[ window ];
MoveWindow( m_display, window, pos.x(), pos.y() );
Flush( m_display );
emit signalConsole( QString( "Set pos: %1, %2" ).arg( pos.x() ).arg( pos.y() ) );
emit signalConsole( QString( "Set pos: %1, %2" ).arg( pos.x() ).arg( pos.y() ) );
}
/*
* Let us wait a bit, maybe this helps...

View File

@@ -341,6 +341,13 @@ class WindowCtrlUnix : public QObject
*/
void signalPositions( QList< QPoint > positions );
protected:
/**
* @brief m_pref. Pointer to the preferences storage.
*/
Preferences* m_pref;
private:
/**

View File

@@ -272,6 +272,13 @@ class WindowCtrlWin : public QObject
*/
void signalConsole( QString message );
protected:
/**
* @brief m_pref. Pointer to the preferences storage.
*/
Preferences* m_pref;
private:
/**

View File

@@ -135,11 +135,6 @@ class WindowCtrl : public QObject
private:
/**
* @brief m_pref. Pointer to the preferences storage.
*/
Preferences* m_pref;
/**
* @brief m_show_hide_active
*/