feat(ags): add method to decide x pos of popup windows

This commit is contained in:
matt1432 2023-12-12 11:21:27 -05:00
parent 6805c0f521
commit 71d69c88ec
4 changed files with 36 additions and 4 deletions

View file

@ -12,7 +12,12 @@ const SPACING = 4;
export default () => EventBox({ export default () => EventBox({
className: 'toggle-off', className: 'toggle-off',
onPrimaryClickRelease: () => App.toggleWindow('notification-center'), onPrimaryClickRelease: (self) => {
App.getWindow('notification-center')
.setXPos(self.get_allocation(), 'right');
App.toggleWindow('notification-center');
},
connections: [[App, (self, windowName, visible) => { connections: [[App, (self, windowName, visible) => {
if (windowName === 'notification-center') { if (windowName === 'notification-center') {

View file

@ -19,7 +19,12 @@ export default () => EventBox({
onHoverLost: () => { /**/ }, onHoverLost: () => { /**/ },
onPrimaryClickRelease: () => App.toggleWindow('quick-settings'), onPrimaryClickRelease: (self) => {
App.getWindow('notification-center')
.setXPos(self.get_allocation(), 'right');
App.toggleWindow('quick-settings');
},
connections: [[App, (self, windowName, visible) => { connections: [[App, (self, windowName, visible) => {
if (windowName === 'quick-settings') { if (windowName === 'quick-settings') {

View file

@ -78,6 +78,29 @@ export default ({
}), }),
}); });
window.setXPos = (
alloc,
side = 'right',
) => {
const width = window.get_display()
.get_monitor_at_point(alloc.x, alloc.y)
.get_geometry().width;
window.margins = [
window.margins[0],
side === 'right' ?
(width - alloc.x - alloc.width) :
window.margins[1],
window.margins[2],
side === 'right' ?
window.margins[3] :
(alloc.x - alloc.width),
];
};
// Make getting the original child passed in this // Make getting the original child passed in this
// function easier when making more code for the widget // function easier when making more code for the widget
window.getChild = () => window.child.children[0].child; window.getChild = () => window.child.children[0].child;

View file

@ -15,12 +15,11 @@ export const NotifPopups = () => PopupWindow({
const TOP_MARGIN = 6; const TOP_MARGIN = 6;
const RIGHT_MARGIN = 60;
export const NotifCenter = () => PopupWindow({ export const NotifCenter = () => PopupWindow({
name: 'notification-center', name: 'notification-center',
anchor: ['top', 'right'], anchor: ['top', 'right'],
margins: [TOP_MARGIN, RIGHT_MARGIN, 0, 0], margins: [TOP_MARGIN, 0, 0, 0],
child: NotifCenterWidget(), child: NotifCenterWidget(),
}); });