Snap attraction between windows

Jens Guballa J.Guballa at t-online.de
Sun Mar 9 22:46:59 CET 2003


Hi Olivier,

On Sun, Mar 09, 2003 at 10:27:13PM +0100, Olivier Fourdan wrote:
> Jens,
> 
> Yes, please send your patch and I'll evaluate it. If it proves to be
> okay, I'll commit it in CVS.

OK, here it comes. As I am not very familar with the diff and the other
development tools, I will provide the code in "plain".

The changes I have done are in the fuction clientMove_event_filter,
my changes are limited to the "if (params.snap_to_border)"-clause only.

Best regards,
Jens


          :
          :
        if (params.snap_to_border)
        {
            int i;
            Client * c2;
            int frame_x2 = frame_x + frame_width;
            int frame_y2 = frame_y + frame_height;
            int c_frame_x1, c_frame_x2, c_frame_y1, c_frame_y2;
            int delta;
            int best_delta_x, best_delta_y, best_frame_x, best_frame_y;
            
            if (abs(disp_x + left - frame_x) < abs(disp_max_x - right - frame_x2))
            {
                best_delta_x = abs(disp_x + left - frame_x);
                best_frame_x = disp_x + left;
            }
            else
            {
                best_delta_x = abs(disp_max_x - right - frame_x2);
                best_frame_x = disp_max_x - right - frame_width;
            }
            
            if (abs(disp_y + top - frame_y) < abs(disp_max_y - bottom - frame_y2))
            {
                best_delta_y = abs(disp_y + top - frame_y);
                best_frame_y = disp_y + top;
            }
            else
            {
                best_delta_y = abs(disp_max_y - bottom - frame_y2);
                best_frame_y = disp_max_y - bottom - frame_height;
            }

            
            for(c2 = clients, i = 0; i < client_count; c2 = c2->next, i++)
            {
                if (CLIENT_FLAG_TEST(c2, CLIENT_FLAG_VISIBLE)) 
                {
                    c_frame_x1 = frameX(c2);
                    c_frame_x2 = c_frame_x1 + frameWidth(c2);
                    c_frame_y1 = frameY(c2);
                    c_frame_y2 = c_frame_y1 + frameHeight(c2);

                    if ((c_frame_y1 <= frame_y2) && (c_frame_y2 >= frame_y))
                    {
                        delta = abs(c_frame_x2 - frame_x);
                        if (delta < best_delta_x) 
                        {
                            best_delta_x = delta;
                            best_frame_x = c_frame_x2;
                        }

                        delta = abs(c_frame_x1 - frame_x2);
                        if (delta < best_delta_x) 
                        {
                            best_delta_x = delta;
                            best_frame_x = c_frame_x1 - frame_width;
                        }
                    }

                    if ((c_frame_x1 <= frame_x2) && (c_frame_x2 >= frame_x))
                    {
                        delta = abs(c_frame_y2 - frame_y);                    
                        if (delta < best_delta_y) 
                        {
                            best_delta_y = delta;
                            best_frame_y = c_frame_y2;
                        }
                        
                        delta = abs(c_frame_y1 - frame_y2); 
                        if (delta < best_delta_y)
                        {
                            best_delta_y = delta;
                            best_frame_y = c_frame_y1 - frame_height;
                        }
                    
                    }
                }
            }

            if (best_delta_x <= params.snap_width)
            {
                c->x = best_frame_x + frame_left;
            }
            
            if (best_delta_y <= params.snap_width)
            {
                c->y = ((best_frame_y < top) ? top : best_frame_y ) + frame_top;
            }
            else if ((frame_y + frame_top > 0) && (frame_y < top))
            {
                c->y = frame_top + top;
            }
            

/* old code           if(abs(frame_x - disp_max_x + frame_width + right) < params.snap_width)
            {
                c->x = disp_max_x - frame_right - c->width - right;
                frame_x = frameX(c);
            }
            if(abs(frame_x - disp_x) < params.snap_width + left)
            {
                c->x = disp_x + frame_left + left;
                frame_x = frameX(c);
           }
            if(abs(frame_y - disp_max_y + frame_height + bottom) < params.snap_width)
            {
                c->y = disp_max_y - frame_height + frame_top - bottom;
                frame_y = frameY(c);
            }
            if((frame_y + frame_top > disp_y) && (frame_y < disp_y + top + params.snap_width))
            {
                c->y = disp_y + frame_top + top;
                frame_y = frameY(c);
            }  
end old code */
        }
        else
        {
            if((frame_y + frame_top > 0) && (frame_y < top))
            {
                c->y = frame_top + top;
            }
        }

            :
            :
            



More information about the Xfce4-dev mailing list